api: flatten code directories, better filenames, remove old files
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Innertube } from 'youtubei.js';
|
||||
import { Red } from '../modules/sub/consoleText.js'
|
||||
import { Red } from '../misc/console-text.js'
|
||||
|
||||
const bail = (...msg) => {
|
||||
console.error(...msg);
|
||||
|
||||
105
api/src/util/setup.js
Normal file
105
api/src/util/setup.js
Normal file
@@ -0,0 +1,105 @@
|
||||
import { existsSync, unlinkSync, appendFileSync } from "fs";
|
||||
import { createInterface } from "readline";
|
||||
import { Cyan, Bright } from "./misc/console-text.js";
|
||||
import { loadJSON } from "./misc/load-from-fs.js";
|
||||
import { execSync } from "child_process";
|
||||
|
||||
const { version } = loadJSON("./package.json");
|
||||
|
||||
let envPath = './.env';
|
||||
let q = `${Cyan('?')} \x1b[1m`;
|
||||
let ob = {};
|
||||
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("\nAwesome! I've created a fresh .env file for you."));
|
||||
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${Cyan("All done!\n")}`);
|
||||
console.log(Bright("You can re-run this script at any time to update the configuration."));
|
||||
console.log(Bright("\nYou're now ready to start cobalt. Simply run ") + Cyan("npm start") + Bright('!\nHave fun :)'));
|
||||
rl.close()
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${Cyan(`Hey, this is cobalt v.${version}!`)}\n${Bright("Let's start by creating a new ")}${Cyan(".env")}${Bright(" file. You can always change it later.")}`
|
||||
)
|
||||
|
||||
function setup() {
|
||||
console.log(Bright("\nWhat kind of server will this instance be?\nOptions: api, web."));
|
||||
|
||||
rl.question(q, r1 => {
|
||||
switch (r1.toLowerCase()) {
|
||||
case 'api':
|
||||
console.log(Bright("\nCool! What's the domain this API instance will be running on? (localhost)\nExample: api.cobalt.tools"));
|
||||
|
||||
rl.question(q, apiURL => {
|
||||
ob.API_URL = `http://localhost:9000/`;
|
||||
ob.API_PORT = 9000;
|
||||
if (apiURL && apiURL !== "localhost") ob.API_URL = `https://${apiURL.toLowerCase()}/`;
|
||||
|
||||
console.log(Bright("\nGreat! Now, what port will it be running on? (9000)"));
|
||||
|
||||
rl.question(q, apiPort => {
|
||||
if (apiPort) ob.API_PORT = apiPort;
|
||||
if (apiPort && (apiURL === "localhost" || !apiURL)) ob.API_URL = `http://localhost:${apiPort}/`;
|
||||
|
||||
console.log(Bright("\nWhat will your instance's name be? Usually it's something like eu-nl aka region-country. (local)"));
|
||||
|
||||
rl.question(q, apiName => {
|
||||
ob.API_NAME = apiName.toLowerCase();
|
||||
if (!apiName || apiName === "local") ob.API_NAME = "local";
|
||||
|
||||
console.log(Bright("\nOne last thing: would you like to enable CORS? It allows other websites and extensions to use your instance's API.\ny/n (n)"));
|
||||
|
||||
rl.question(q, apiCors => {
|
||||
let answCors = apiCors.toLowerCase().trim();
|
||||
if (answCors !== "y" && answCors !== "yes") ob.CORS_WILDCARD = '0'
|
||||
final()
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
})
|
||||
break;
|
||||
case 'web':
|
||||
console.log(Bright("\nAwesome! What's the domain this web app instance will be running on? (localhost)\nExample: cobalt.tools"));
|
||||
|
||||
rl.question(q, webURL => {
|
||||
ob.WEB_URL = `http://localhost:9001/`;
|
||||
ob.WEB_PORT = 9001;
|
||||
if (webURL && webURL !== "localhost") ob.WEB_URL = `https://${webURL.toLowerCase()}/`;
|
||||
|
||||
console.log(
|
||||
Bright("\nGreat! Now, what port will it be running on? (9001)")
|
||||
)
|
||||
rl.question(q, webPort => {
|
||||
if (webPort) ob.WEB_PORT = webPort;
|
||||
if (webPort && (webURL === "localhost" || !webURL)) ob.WEB_URL = `http://localhost:${webPort}/`;
|
||||
|
||||
console.log(
|
||||
Bright("\nOne last thing: what default API domain should be used? (api.cobalt.tools)\nIf it's hosted locally, make sure to include the port:") + Cyan(" localhost:9000")
|
||||
);
|
||||
|
||||
rl.question(q, apiURL => {
|
||||
ob.API_URL = `https://${apiURL.toLowerCase()}/`;
|
||||
if (apiURL.includes(':')) ob.API_URL = `http://${apiURL.toLowerCase()}/`;
|
||||
if (!apiURL) ob.API_URL = "https://api.cobalt.tools/";
|
||||
final()
|
||||
})
|
||||
});
|
||||
|
||||
});
|
||||
break;
|
||||
default:
|
||||
console.log(Bright("\nThis is not an option. Try again."));
|
||||
setup()
|
||||
}
|
||||
})
|
||||
}
|
||||
setup()
|
||||
@@ -1,11 +1,10 @@
|
||||
import { env } from "../modules/config.js";
|
||||
import { runTest } from "../modules/test.js";
|
||||
import { loadLoc } from "../localization/manager.js";
|
||||
import { loadJSON } from "../modules/sub/loadFromFs.js";
|
||||
import { Red, Bright } from "../modules/sub/consoleText.js";
|
||||
import { env } from "../config.js";
|
||||
import { runTest } from "../misc/run-test.js";
|
||||
import { loadJSON } from "../misc/load-from-fs.js";
|
||||
import { Red, Bright } from "../misc/console-text.js";
|
||||
|
||||
const tests = loadJSON('./src/util/tests.json');
|
||||
const services = loadJSON('./src/modules/processing/servicesConfig.json');
|
||||
const services = loadJSON('./src/processing/service-config.json');
|
||||
|
||||
// services that are known to frequently fail due to external
|
||||
// factors (e.g. rate limiting)
|
||||
@@ -38,7 +37,6 @@ switch (action) {
|
||||
console.error('no such service:', service);
|
||||
}
|
||||
|
||||
await loadLoc();
|
||||
env.streamLifespan = 10000;
|
||||
env.apiURL = 'http://x';
|
||||
|
||||
@@ -78,4 +76,4 @@ switch (action) {
|
||||
default:
|
||||
console.error('invalid action:', action);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import "dotenv/config";
|
||||
import "../modules/sub/alias-envs.js";
|
||||
import "../misc/alias-envs.js";
|
||||
|
||||
import { services } from "../modules/config.js";
|
||||
import { extract } from "../modules/processing/url.js";
|
||||
import match from "../modules/processing/match.js";
|
||||
import { loadJSON } from "../modules/sub/loadFromFs.js";
|
||||
import { normalizeRequest } from "../modules/processing/request.js";
|
||||
import { env } from "../modules/config.js";
|
||||
import { services } from "../config.js";
|
||||
import { extract } from "../processing/url.js";
|
||||
import match from "../processing/match.js";
|
||||
import { loadJSON } from "../misc/load-from-fs.js";
|
||||
import { normalizeRequest } from "../processing/request.js";
|
||||
import { env } from "../config.js";
|
||||
|
||||
env.apiURL = 'http://localhost:9000'
|
||||
let tests = loadJSON('./src/util/tests.json');
|
||||
@@ -29,7 +29,7 @@ for (let i in services) {
|
||||
console.log(`\nRunning tests for ${i}...\n`)
|
||||
for (let k = 0; k < tests[i].length; k++) {
|
||||
let test = tests[i][k];
|
||||
|
||||
|
||||
console.log(`Running test ${k+1}: ${test.name}`);
|
||||
console.log('params:');
|
||||
let params = {...{url: test.url}, ...test.params};
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
import createFilename from "../modules/processing/createFilename.js";
|
||||
|
||||
let tests = [
|
||||
{
|
||||
f: {
|
||||
service: 'youtube',
|
||||
id: 'MMK3L4W70g4',
|
||||
title: "Loossemble (루셈블) - 'Sensitive' MV",
|
||||
author: 'Loossemble',
|
||||
youtubeDubName: false,
|
||||
qualityLabel: '2160p',
|
||||
resolution: '3840x2160',
|
||||
extension: 'webm',
|
||||
youtubeFormat: 'vp9'
|
||||
},
|
||||
isAudioOnly: false,
|
||||
isAudioMuted: false
|
||||
},
|
||||
{
|
||||
f: {
|
||||
service: 'youtube',
|
||||
id: 'MMK3L4W70g4',
|
||||
title: "Loossemble (루셈블) - 'Sensitive' MV",
|
||||
author: 'Loossemble',
|
||||
youtubeDubName: false,
|
||||
qualityLabel: '2160p',
|
||||
resolution: '3840x2160',
|
||||
extension: 'webm',
|
||||
youtubeFormat: 'vp9'
|
||||
},
|
||||
isAudioOnly: true,
|
||||
isAudioMuted: false
|
||||
},
|
||||
{
|
||||
f: {
|
||||
service: 'youtube',
|
||||
id: 'MMK3L4W70g4',
|
||||
title: "Loossemble (루셈블) - 'Sensitive' MV",
|
||||
author: 'Loossemble',
|
||||
youtubeDubName: false,
|
||||
qualityLabel: '2160p',
|
||||
resolution: '3840x2160',
|
||||
extension: 'webm',
|
||||
youtubeFormat: 'vp9'
|
||||
},
|
||||
isAudioOnly: false,
|
||||
isAudioMuted: true
|
||||
},
|
||||
{
|
||||
f: {
|
||||
service: 'vimeo',
|
||||
id: 'MMK3L4W70g4',
|
||||
title: "Loossemble (루셈블) - 'Sensitive' MV",
|
||||
author: 'Loossemble',
|
||||
qualityLabel: '2160p',
|
||||
resolution: '3840x2160',
|
||||
extension: 'mp4'
|
||||
},
|
||||
isAudioOnly: false,
|
||||
isAudioMuted: true
|
||||
}
|
||||
]
|
||||
|
||||
for (let i = 0; i < tests.length; i++) {
|
||||
console.log(`---${i}---`)
|
||||
console.log(createFilename(tests[i].f, "classic", tests[i].isAudioOnly, tests[i].isAudioMuted))
|
||||
console.log(createFilename(tests[i].f, "basic", tests[i].isAudioOnly, tests[i].isAudioMuted))
|
||||
console.log(createFilename(tests[i].f, "pretty", tests[i].isAudioOnly, tests[i].isAudioMuted))
|
||||
console.log(createFilename(tests[i].f, "nerdy", tests[i].isAudioOnly, tests[i].isAudioMuted))
|
||||
}
|
||||
Reference in New Issue
Block a user