cleanup: move processing into different functions

This commit is contained in:
hyperdefined 2024-07-26 18:06:33 -04:00
parent 3e83e1ec36
commit 2de4cd6a30
No known key found for this signature in database
GPG Key ID: EB0B55B31E88AB03

View File

@ -1,9 +1,7 @@
import { genericUserAgent } from "../../config.js";
import { cleanString } from "../../sub/utils.js";
export default async function(obj) {
// handle video downloads
if (obj.type == 'portal') {
async function video(obj) {
let req = await fetch(`https://www.newgrounds.com/portal/video/${obj.id}`, {
headers: {
'User-Agent': genericUserAgent,
@ -41,10 +39,9 @@ export default async function(obj) {
},
fileMetadata,
}
}
}
// handle audio downloads
if (obj.type == 'audio') {
async function music(obj) {
let req = await fetch(`https://www.newgrounds.com/audio/listen/${obj.id}`, {
headers: {
'User-Agent': genericUserAgent,
@ -82,5 +79,17 @@ export default async function(obj) {
fileMetadata,
isAudioOnly: true
}
}
}
export default async function(obj) {
// handle video downloads
if (obj.type == 'portal') {
return video(obj);
}
// handle audio downloads
if (obj.type == 'audio') {
return music(obj);
}
return { error: 'ErrorUnsupported' };
}