fix small issues

This commit is contained in:
wukko 2022-09-01 19:51:18 +06:00
parent e61122d5b0
commit f70128f4fc
11 changed files with 40 additions and 49 deletions

View file

@ -96,10 +96,10 @@ if (fs.existsSync('./.env')) {
res.status(500).json({ 'status': 'error', 'text': 'something went wrong.' }) res.status(500).json({ 'status': 'error', 'text': 'something went wrong.' })
} }
}); });
app.get("/api", async (req, res) => { app.get("/api", (req, res) => {
res.redirect('/api/json') res.redirect('/api/json')
}); });
app.get("/", async (req, res) => { app.get("/", (req, res) => {
// redirect masochists to a page where they can install a proper browser // redirect masochists to a page where they can install a proper browser
if (req.header("user-agent") && req.header("user-agent").includes("Trident")) { if (req.header("user-agent") && req.header("user-agent").includes("Trident")) {
if (internetExplorerRedirect.newNT.includes(req.header("user-agent").split('NT ')[1].split(';')[0])) { if (internetExplorerRedirect.newNT.includes(req.header("user-agent").split('NT ')[1].split(';')[0])) {
@ -118,10 +118,10 @@ if (fs.existsSync('./.env')) {
})) }))
} }
}); });
app.get("/favicon.ico", async (req, res) => { app.get("/favicon.ico", (req, res) => {
res.redirect('/icons/favicon.ico'); res.redirect('/icons/favicon.ico');
}); });
app.get("/*", async (req, res) => { app.get("/*", (req, res) => {
res.redirect('/') res.redirect('/')
}); });
app.listen(process.env.port, () => { app.listen(process.env.port, () => {

View file

@ -185,15 +185,6 @@ function loadSettings() {
changeSwitcher(i, sGet(i)) changeSwitcher(i, sGet(i))
} }
} }
function checkbox(action) {
if (eid(action).checked) {
sSet(action, "true");
if (action == "alwaysVisibleButton") button();
} else {
sSet(action, "false");
if (action == "alwaysVisibleButton") button();
}
}
function toggle(toggle) { function toggle(toggle) {
let state = sGet(toggle); let state = sGet(toggle);
if (state) { if (state) {

View file

@ -6,7 +6,7 @@ const locPath = './src/localization/languages'
let loc = {} let loc = {}
export async function loadLoc() { export function loadLoc() {
fs.readdir(locPath, (err, files) => { fs.readdir(locPath, (err, files) => {
files.forEach(file => { files.forEach(file => {
loc[file.split('.')[0]] = loadJson(`${locPath}/${file}`) loc[file.split('.')[0]] = loadJson(`${locPath}/${file}`)

View file

@ -32,7 +32,7 @@ export function popup(obj) {
if (Array.isArray(obj.body)) { if (Array.isArray(obj.body)) {
body = `` body = ``
for (let i = 0; i < obj.body.length; i++) { for (let i = 0; i < obj.body.length; i++) {
let classes = obj.body[i]["classes"] ? obj.body[i]["classes"] : [] classes = obj.body[i]["classes"] ? obj.body[i]["classes"] : []
if (i != obj.body.length - 1 && !obj.body[i]["nopadding"]) { if (i != obj.body.length - 1 && !obj.body[i]["nopadding"]) {
classes.push("desc-padding") classes.push("desc-padding")
} }

View file

@ -16,9 +16,9 @@ export default async function(obj) {
let best = all[0] let best = all[0]
try { try {
if (obj.quality != "max") { if (obj.quality != "max") {
let pref = parseInt(quality[obj.quality]) let pref = parseInt(quality[obj.quality], 10)
for (let i in all) { for (let i in all) {
let currQuality = parseInt(all[i]["quality"].replace('p', '')) let currQuality = parseInt(all[i]["quality"].replace('p', ''), 10)
if (currQuality < pref) { if (currQuality < pref) {
break; break;
} else if (currQuality == pref) { } else if (currQuality == pref) {

View file

@ -1,4 +1,4 @@
export let testers = { export const testers = {
"twitter": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length < 20), "twitter": (patternMatch) => (patternMatch["id"] && patternMatch["id"].length < 20),
"vk": (patternMatch) => (patternMatch["userId"] && patternMatch["videoId"] && "vk": (patternMatch) => (patternMatch["userId"] && patternMatch["videoId"] &&

View file

@ -9,6 +9,22 @@ let q = `${Cyan('?')} \x1b[1m`;
let ob = { streamSalt: randomBytes(64).toString('hex') } let ob = { streamSalt: randomBytes(64).toString('hex') }
let rl = createInterface({ input: process.stdin, output: process.stdout }); let rl = createInterface({ input: process.stdin, output: process.stdout });
let final = () => {
if (existsSync(envPath)) {
unlinkSync(envPath)
}
for (let i in ob) {
appendFileSync(envPath, `${i}=${ob[i]}\n`)
}
console.log(Bright("\nI've created a .env file with selfURL, port, and stream salt."))
console.log(`${Bright("Now I'll run")} ${Cyan("npm install")} ${Bright("to install all dependencies. It shouldn't take long.\n\n")}`)
execSync('npm install', { stdio: [0, 1, 2] });
console.log(`\n\n${Green("All done!\n")}`)
console.log("You can re-run this script any time to update the configuration.")
console.log("\nYou're now ready to start the main project.\nHave fun!")
rl.close()
}
console.log( console.log(
`${Cyan("Welcome to cobalt!")}\n${Bright("We'll get you up and running in no time.\nLet's start by creating a ")}${Cyan(".env")}${Bright(" file. You can always change it later.")}` `${Cyan("Welcome to cobalt!")}\n${Bright("We'll get you up and running in no time.\nLet's start by creating a ")}${Cyan(".env")}${Bright(" file. You can always change it later.")}`
) )
@ -36,19 +52,3 @@ rl.question(q, r1 => {
final() final()
}); });
}) })
let final = () => {
if (existsSync(envPath)) {
unlinkSync(envPath)
}
for (let i in ob) {
appendFileSync(envPath, `${i}=${ob[i]}\n`)
}
console.log(Bright("\nI've created a .env file with selfURL, port, and stream salt."))
console.log(`${Bright("Now I'll run")} ${Cyan("npm install")} ${Bright("to install all dependencies. It shouldn't take long.\n\n")}`)
execSync('npm install', { stdio: [0, 1, 2] });
console.log(`\n\n${Green("All done!\n")}`)
console.log("You can re-run this script any time to update the configuration.")
console.log("\nYou're now ready to start the main project.\nHave fun!")
rl.close()
}

View file

@ -9,8 +9,8 @@ function closest(goal, array) {
export default function(service, quality, maxQuality) { export default function(service, quality, maxQuality) {
if (quality == "max") return maxQuality; if (quality == "max") return maxQuality;
quality = parseInt(mq[quality]) quality = parseInt(mq[quality], 10)
maxQuality = parseInt(maxQuality) maxQuality = parseInt(maxQuality, 10)
if (quality >= maxQuality || quality == maxQuality) return maxQuality; if (quality >= maxQuality || quality == maxQuality) return maxQuality;

View file

@ -22,6 +22,6 @@ export default function(res, ip, id, hmac, exp) {
res.status(streamInfo.status).json(apiJSON(0, { t: streamInfo.error }).body); res.status(streamInfo.status).json(apiJSON(0, { t: streamInfo.error }).body);
} }
} catch (e) { } catch (e) {
internalError(res) res.status(500).json({ status: "error", text: "Internal Server Error" });
} }
} }

View file

@ -4,7 +4,7 @@ import got from "got";
import { ffmpegArgs, genericUserAgent } from "../config.js"; import { ffmpegArgs, genericUserAgent } from "../config.js";
import { msToTime } from "../sub/utils.js"; import { msToTime } from "../sub/utils.js";
export async function streamDefault(streamInfo, res) { export function streamDefault(streamInfo, res) {
try { try {
res.setHeader('Content-disposition', `attachment; filename="${streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : streamInfo.filename}"`); res.setHeader('Content-disposition', `attachment; filename="${streamInfo.isAudioOnly ? `${streamInfo.filename}.${streamInfo.audioFormat}` : streamInfo.filename}"`);
const stream = got.get(streamInfo.urls, { const stream = got.get(streamInfo.urls, {
@ -23,7 +23,7 @@ export async function streamDefault(streamInfo, res) {
res.end(); res.end();
} }
} }
export async function streamLiveRender(streamInfo, res) { export function streamLiveRender(streamInfo, res) {
try { try {
if (streamInfo.urls.length == 2) { if (streamInfo.urls.length == 2) {
let headers = {}; let headers = {};
@ -79,7 +79,7 @@ export async function streamLiveRender(streamInfo, res) {
res.end(); res.end();
} }
} }
export async function streamAudioOnly(streamInfo, res) { export function streamAudioOnly(streamInfo, res) {
try { try {
let headers = {}; let headers = {};
if (streamInfo.service == "bilibili") { if (streamInfo.service == "bilibili") {

View file

@ -21,17 +21,17 @@ export function apiJSON(type, obj) {
} }
} }
export function msToTime(d) { export function msToTime(d) {
let milliseconds = parseInt((d % 1000) / 100), let milliseconds = parseInt((d % 1000) / 100, 10),
seconds = parseInt((d / 1000) % 60), seconds = parseInt((d / 1000) % 60, 10),
minutes = parseInt((d / (1000 * 60)) % 60), minutes = parseInt((d / (1000 * 60)) % 60, 10),
hours = parseInt((d / (1000 * 60 * 60)) % 24), hours = parseInt((d / (1000 * 60 * 60)) % 24, 10),
r; r;
hours = (hours < 10) ? "0" + hours : hours; hours = (hours < 10) ? `0${hours}` : hours;
minutes = (minutes < 10) ? "0" + minutes : minutes; minutes = (minutes < 10) ? `0${minutes}` : minutes;
seconds = (seconds < 10) ? "0" + seconds : seconds; seconds = (seconds < 10) ? `0${seconds}` : seconds;
r = hours + ":" + minutes + ":" + seconds; r = `${hours}:${minutes}:${seconds}`;
milliseconds ? r += "." + milliseconds : r += ""; if (milliseconds) r += `.${milliseconds}`;
return r; return r;
} }
export function cleanURL(url, host) { export function cleanURL(url, host) {