mirror of
https://github.com/imputnet/cobalt.git
synced 2025-07-18 19:28:29 +00:00
error checking for parsing things
This commit is contained in:
parent
5723239f10
commit
b219c3e9aa
@ -16,7 +16,10 @@ export default async function(obj) {
|
|||||||
|
|
||||||
if (!req) return { error: 'ErrorEmptyDownload' };
|
if (!req) return { error: 'ErrorEmptyDownload' };
|
||||||
|
|
||||||
const json = JSON.parse(req);
|
let json;
|
||||||
|
try {
|
||||||
|
json = JSON.parse(req);
|
||||||
|
} catch { return { error: 'ErrorEmptyDownload' }; }
|
||||||
const highestQuality = Object.keys(json.sources)[0];
|
const highestQuality = Object.keys(json.sources)[0];
|
||||||
const video = json.sources[highestQuality][0].src
|
const video = json.sources[highestQuality][0].src
|
||||||
|
|
||||||
@ -37,9 +40,17 @@ export default async function(obj) {
|
|||||||
|
|
||||||
if (!req) return { error: 'ErrorEmptyDownload' };
|
if (!req) return { error: 'ErrorEmptyDownload' };
|
||||||
|
|
||||||
const title = req.match(/"name"\s*:\s*"([^"]+)"/)?.[1];
|
const titleMatch = req.match(/"name"\s*:\s*"([^"]+)"/);
|
||||||
const artist = req.match(/"artist"\s*:\s*"([^"]+)"/)?.[1];
|
const artistMatch = req.match(/"artist"\s*:\s*"([^"]+)"/);
|
||||||
const url = req.match(/"filename"\s*:\s*"([^"]+)"/)?.[1]?.replace(/\\\//g, '/');
|
const urlMatch = req.match(/"filename"\s*:\s*"([^"]+)"/);
|
||||||
|
|
||||||
|
if (!titleMatch || !artistMatch || !urlMatch) {
|
||||||
|
return { error: 'ErrorEmptyDownload' };
|
||||||
|
}
|
||||||
|
|
||||||
|
const title = titleMatch[1];
|
||||||
|
const artist = artistMatch[1];
|
||||||
|
const url = urlMatch[1].replace(/\\\//g, '/');
|
||||||
let fileMetadata = {
|
let fileMetadata = {
|
||||||
title: cleanString(decodeURIComponent(title.trim())),
|
title: cleanString(decodeURIComponent(title.trim())),
|
||||||
artist: cleanString(decodeURIComponent(artist.trim())),
|
artist: cleanString(decodeURIComponent(artist.trim())),
|
||||||
@ -51,7 +62,8 @@ export default async function(obj) {
|
|||||||
service: "newgrounds",
|
service: "newgrounds",
|
||||||
id: obj.id,
|
id: obj.id,
|
||||||
title: fileMetadata.title,
|
title: fileMetadata.title,
|
||||||
author: fileMetadata.artist
|
author: fileMetadata.artist,
|
||||||
|
fileMetadata
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user