1b4872c1de
- added support for tiktok (images won't work, they're only accessible through the app) - hopefully main input bar is now not rounded on ios, i fucking hate apple - if service is not supported, a correlating error will appear, not generic one - removed duplicates from config that are present in package json already - tiny bit of clean up
59 lines
No EOL
2.2 KiB
JavaScript
59 lines
No EOL
2.2 KiB
JavaScript
import { createStream } from "../stream/manage.js";
|
|
|
|
export function apiJSON(type, obj) {
|
|
try {
|
|
switch (type) {
|
|
case 0:
|
|
return { status: 400, body: { status: "error", text: obj.t } };
|
|
case 1:
|
|
return { status: 200, body: { status: "redirect", url: obj.u } };
|
|
case 2:
|
|
return { status: 200, body: { status: "stream", url: createStream(obj) } };
|
|
case 3:
|
|
return { status: 200, body: { status: "success", text: obj.t } };
|
|
case 4:
|
|
return { status: 429, body: { status: "rate-limit", text: obj.t } };
|
|
default:
|
|
return { status: 400, body: { status: "error", text: "Bad Request" } };
|
|
}
|
|
} catch (e) {
|
|
return { status: 500, body: { status: "error", text: "Internal Server Error" } };
|
|
}
|
|
}
|
|
export function msToTime(d) {
|
|
let milliseconds = parseInt((d % 1000) / 100),
|
|
seconds = parseInt((d / 1000) % 60),
|
|
minutes = parseInt((d / (1000 * 60)) % 60),
|
|
hours = parseInt((d / (1000 * 60 * 60)) % 24),
|
|
r;
|
|
|
|
hours = (hours < 10) ? "0" + hours : hours;
|
|
minutes = (minutes < 10) ? "0" + minutes : minutes;
|
|
seconds = (seconds < 10) ? "0" + seconds : seconds;
|
|
r = hours + ":" + minutes + ":" + seconds;
|
|
milliseconds ? r += "." + milliseconds : r += "";
|
|
return r;
|
|
}
|
|
export function cleanURL(url, host) {
|
|
url = url.replace('}', '').replace('{', '').replace(')', '').replace('(', '').replace(' ', '').replace('@', '');
|
|
if (url.includes('youtube.com/shorts/')) {
|
|
url = url.split('?')[0].replace('shorts/', 'watch?v=');
|
|
}
|
|
if (host == "youtube") {
|
|
url = url.split('&')[0];
|
|
} else {
|
|
url = url.split('?')[0];
|
|
if (url.substring(url.length - 1) == "/") {
|
|
url = url.substring(0, url.length - 1);
|
|
}
|
|
}
|
|
return url
|
|
}
|
|
export function languageCode(req) {
|
|
return req.header('Accept-Language') ? req.header('Accept-Language').slice(0, 2) : "en"
|
|
}
|
|
export function unicodeDecode(str) {
|
|
return str.replace(/\\u[\dA-F]{4}/gi, (unicode) => {
|
|
return String.fromCharCode(parseInt(unicode.replace(/\\u/g, ""), 16));
|
|
});
|
|
} |