moved all `.js` files into `src/` & removed TLog socket plugin

pull/62/head
tycrek 3 years ago
parent 9c07e84b34
commit 2aadafe37b
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -1 +1 @@
Subproject commit ac4fbe6d850919a4c347cf3bb69c8d2cb60cd87d Subproject commit 7c7eb2a5b3b8e644f2a6b8caf7e8041cf7b5e42e

@ -8,15 +8,14 @@
"npm": ">=7.x.x" "npm": ">=7.x.x"
}, },
"scripts": { "scripts": {
"start": "node ass.js", "start": "node src/ass.js",
"setup": "node setup.js", "setup": "node src/setup.js",
"metrics": "node metrics.js", "metrics": "node src/metrics.js",
"new-token": "node generators/token.js", "new-token": "node src/generators/token.js",
"restart": "systemctl restart ass.service", "restart": "systemctl restart ass.service",
"engine-check": "node checkEngine.js", "engine-check": "node src/checkEngine.js",
"prestart": "npm run engine-check", "prestart": "npm run engine-check",
"presetup": "npm run engine-check", "presetup": "npm run engine-check",
"logs": "node ./node_modules/@tycrek/log/socketClient.js",
"docker-logs": "docker-compose logs -f --tail=50 --no-log-prefix ass", "docker-logs": "docker-compose logs -f --tail=50 --no-log-prefix ass",
"docker-update": "git pull && docker-compose up --force-recreate --build -d && docker image prune -f", "docker-update": "git pull && docker-compose up --force-recreate --build -d && docker image prune -f",
"docker-resetup": "docker-compose exec ass npm run setup && docker-compose restart" "docker-resetup": "docker-compose exec ass npm run setup && docker-compose restart"

@ -1,7 +1,7 @@
let doSetup = null; let doSetup = null;
try { try {
// Check if config.json exists // Check if config.json exists
require('./config.json'); require('../config.json');
} catch (err) { } catch (err) {
doSetup = require('./setup').doSetup; doSetup = require('./setup').doSetup;
} }
@ -13,7 +13,7 @@ if (doSetup) {
} }
// Load the config // Load the config
const { host, port, useSsl, isProxied, s3enabled, frontendName, indexFile } = require('./config.json'); const { host, port, useSsl, isProxied, s3enabled, frontendName, indexFile } = require('../config.json');
//#region Imports //#region Imports
const fs = require('fs-extra'); const fs = require('fs-extra');
@ -24,8 +24,8 @@ const marked = require('marked');
const uploadRouter = require('./routers/upload'); const uploadRouter = require('./routers/upload');
const resourceRouter = require('./routers/resource'); const resourceRouter = require('./routers/resource');
const { path, log, getTrueHttp, getTrueDomain } = require('./utils'); const { path, log, getTrueHttp, getTrueDomain } = require('./utils');
const { CODE_INTERNAL_SERVER_ERROR } = require('./MagicNumbers.json'); const { CODE_INTERNAL_SERVER_ERROR } = require('../MagicNumbers.json');
const { name: ASS_NAME, version: ASS_VERSION } = require('./package.json'); const { name: ASS_NAME, version: ASS_VERSION } = require('../package.json');
//#endregion //#endregion
// Welcome :D // Welcome :D
@ -66,7 +66,7 @@ useSsl && app.use(helmet.hsts({ preload: true })); // skipcq: JS-0093
app.use(nofavicon); app.use(nofavicon);
// Use custom index, otherwise render README.md // Use custom index, otherwise render README.md
const ASS_INDEX = indexFile !== '' && fs.existsSync(`./${indexFile}`) && require(`./${indexFile}`); const ASS_INDEX = indexFile !== '' && fs.existsSync(`../${indexFile}`) && require(`../${indexFile}`);
app.get('/', (req, res, next) => ASS_INDEX // skipcq: JS-0229 app.get('/', (req, res, next) => ASS_INDEX // skipcq: JS-0229
? ASS_INDEX(req, res, next) ? ASS_INDEX(req, res, next)
: fs.readFile(path('README.md')) : fs.readFile(path('README.md'))
@ -79,7 +79,7 @@ app.get('/', (req, res, next) => ASS_INDEX // skipcq: JS-0229
app.use('/', ROUTERS.upload); app.use('/', ROUTERS.upload);
// Set up custom frontend // Set up custom frontend
const ASS_FRONTEND = fs.existsSync(`./${frontendName}/package.json`) ? (require('submodule'), require(`./${frontendName}`)) : { enabled: false }; const ASS_FRONTEND = fs.existsSync(path(`./${frontendName}/package.json`)) ? (require('submodule'), require(`../${frontendName}`)) : { enabled: false }; // todo: update with src/
ASS_FRONTEND.enabled && app.use(ASS_FRONTEND.endpoint, ASS_FRONTEND.router); // skipcq: JS-0093 ASS_FRONTEND.enabled && app.use(ASS_FRONTEND.endpoint, ASS_FRONTEND.router); // skipcq: JS-0093
// '/:resouceId' always needs to be LAST since it's a catch-all route // '/:resouceId' always needs to be LAST since it's a catch-all route

@ -5,7 +5,7 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const { log, path, arrayEquals } = require('./utils'); const { log, path, arrayEquals } = require('./utils');
const users = require('./auth.json').users || {}; const users = require('../auth.json').users || {};
// Monitor auth.json for changes (triggered by running 'npm run new-token') // Monitor auth.json for changes (triggered by running 'npm run new-token')
fs.watch(path('auth.json'), { persistent: false }, fs.watch(path('auth.json'), { persistent: false },

@ -1,5 +1,5 @@
const check = require("check-node-version"); const check = require("check-node-version");
const ENGINES = require('./package.json').engines; const ENGINES = require('../package.json').engines;
const TLog = require('@tycrek/log'); const TLog = require('@tycrek/log');
const logger = new TLog(); const logger = new TLog();

@ -1,6 +1,4 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const adjectives = fs.readFileSync('./generators/gfycat/adjectives.txt').toString().split('\n');
const animals = fs.readFileSync('./generators/gfycat/animals.txt').toString().split('\n');
// Don't trigger circular dependency during setup // Don't trigger circular dependency during setup
if (!require.main.filename.includes('setup.js')) if (!require.main.filename.includes('setup.js'))
@ -11,6 +9,11 @@ function getWord(list, delim = '') {
} }
function genString(count = MIN_LENGTH) { function genString(count = MIN_LENGTH) {
// For some reason these 3 lines MUST be inside the function
const { path } = require('../utils');
const adjectives = fs.readFileSync(path('./gfycat/adjectives.txt')).toString().split('\n');
const animals = fs.readFileSync(path('./gfycat/animals.txt')).toString().split('\n');
let gfycat = ''; let gfycat = '';
for (let i = 0; i < (count < MIN_LENGTH ? MIN_LENGTH : count); i++) for (let i = 0; i < (count < MIN_LENGTH ? MIN_LENGTH : count); i++)
gfycat += getWord(adjectives, '-'); gfycat += getWord(adjectives, '-');

@ -12,7 +12,7 @@ module.exports = () => uuid().replace(/-/g, '');
// If directly called on the command line, generate a new token // If directly called on the command line, generate a new token
if (require.main === module) { if (require.main === module) {
const token = module.exports(); const token = module.exports();
const authPath = path.join(__dirname, '..', 'auth.json'); const authPath = path.join(process.cwd(), 'auth.json');
let name = ''; let name = '';
fs.readJson(authPath) fs.readJson(authPath)

@ -1,6 +1,6 @@
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const { s3enabled } = require('./config.json'); const { s3enabled } = require('../config.json');
const { formatBytes } = require('./utils'); const { formatBytes } = require('./utils');
const { bucketSize } = require('./storage'); const { bucketSize } = require('./storage');
@ -9,7 +9,7 @@ const log = new TLog({ level: 'debug', timestamp: { enabled: false } });
module.exports = () => { module.exports = () => {
const data = require('./data'); const data = require('./data');
const { users } = fs.readJsonSync(path.join(__dirname, 'auth.json')); const { users } = fs.readJsonSync(path.join(process.cwd(), 'auth.json'));
Object.keys(users).forEach((token) => users[token].count = 0); Object.keys(users).forEach((token) => users[token].count = 0);
let totalSize = 0; let totalSize = 0;

@ -2,9 +2,9 @@ const fs = require('fs-extra');
const escape = require('escape-html'); const escape = require('escape-html');
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const { deleteS3 } = require('../storage'); const { deleteS3 } = require('../storage');
const { diskFilePath, s3enabled, viewDirect } = require('../config.json'); const { diskFilePath, s3enabled, viewDirect } = require('../../config.json');
const { path, log, getTrueHttp, getTrueDomain, formatBytes, formatTimestamp, getS3url, getDirectUrl, getResourceColor, replaceholder } = require('../utils'); const { path, log, getTrueHttp, getTrueDomain, formatBytes, formatTimestamp, getS3url, getDirectUrl, getResourceColor, replaceholder } = require('../utils');
const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, } = require('../MagicNumbers.json'); const { CODE_UNAUTHORIZED, CODE_NOT_FOUND, } = require('../../MagicNumbers.json');
const data = require('../data'); const data = require('../data');
const users = require('../auth'); const users = require('../auth');

@ -3,9 +3,9 @@ const fs = require('fs-extra');
const { DateTime } = require('luxon'); const { DateTime } = require('luxon');
const { WebhookClient, MessageEmbed } = require('discord.js'); const { WebhookClient, MessageEmbed } = require('discord.js');
const { doUpload, processUploaded } = require('../storage'); const { doUpload, processUploaded } = require('../storage');
const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType } = require('../config.json'); const { maxUploadSize, resourceIdSize, gfyIdSize, resourceIdType } = require('../../config.json');
const { path, log, verify, getTrueHttp, getTrueDomain, generateId, formatBytes } = require('../utils'); const { path, log, verify, getTrueHttp, getTrueDomain, generateId, formatBytes } = require('../utils');
const { CODE_UNAUTHORIZED, CODE_PAYLOAD_TOO_LARGE } = require('../MagicNumbers.json'); const { CODE_UNAUTHORIZED, CODE_PAYLOAD_TOO_LARGE } = require('../../MagicNumbers.json');
const data = require('../data'); const data = require('../data');
const users = require('../auth'); const users = require('../auth');

@ -53,7 +53,7 @@ function getConfirmSchema(description) {
// If directly called on the command line, run setup script // If directly called on the command line, run setup script
function doSetup() { function doSetup() {
const path = (...paths) => require('path').join(__dirname, ...paths); const path = (...paths) => require('path').join(process.cwd(), ...paths);
const TLog = require('@tycrek/log'); const TLog = require('@tycrek/log');
const fs = require('fs-extra'); const fs = require('fs-extra');
const prompt = require('prompt'); const prompt = require('prompt');
@ -64,7 +64,7 @@ function doSetup() {
// Override default configs with existing configs to allow migrating configs // Override default configs with existing configs to allow migrating configs
// Now that's a lot of configs! // Now that's a lot of configs!
try { try {
const existingConfig = require('./config.json'); const existingConfig = require('../config.json');
Object.entries(existingConfig).forEach(([key, value]) => { Object.entries(existingConfig).forEach(([key, value]) => {
Object.prototype.hasOwnProperty.call(config, key) && (config[key] = value); // skipcq: JS-0093 Object.prototype.hasOwnProperty.call(config, key) && (config[key] = value); // skipcq: JS-0093
Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = value); // skipcq: JS-0093 Object.prototype.hasOwnProperty.call(s3config, key) && (s3config[key] = value); // skipcq: JS-0093

@ -8,8 +8,8 @@ const Thumbnail = require('./thumbnails');
const Vibrant = require('./vibrant'); const Vibrant = require('./vibrant');
const Hash = require('./hash'); const Hash = require('./hash');
const { getDatedDirname, sanitize, generateId, formatBytes, log } = require('./utils'); const { getDatedDirname, sanitize, generateId, formatBytes, log } = require('./utils');
const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, saveAsOriginal, maxUploadSize, mediaStrict } = require('./config.json'); const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, saveAsOriginal, maxUploadSize, mediaStrict } = require('../config.json');
const { CODE_UNSUPPORTED_MEDIA_TYPE } = require('./MagicNumbers.json'); const { CODE_UNSUPPORTED_MEDIA_TYPE } = require('../MagicNumbers.json');
const ID_GEN_LENGTH = 32; const ID_GEN_LENGTH = 32;
const ALLOWED_MIMETYPES = /(image)|(video)|(audio)\//; const ALLOWED_MIMETYPES = /(image)|(video)|(audio)\//;

@ -3,7 +3,7 @@ const Jimp = require('jimp');
const shell = require('any-shell-escape'); const shell = require('any-shell-escape');
const { exec } = require('child_process'); const { exec } = require('child_process');
const { isProd, path } = require('./utils'); const { isProd, path } = require('./utils');
const { diskFilePath } = require('./config.json'); const { diskFilePath } = require('../config.json');
// Thumbnail parameters // Thumbnail parameters
const THUMBNAIL = { const THUMBNAIL = {

@ -8,11 +8,11 @@ const token = require('./generators/token');
const zwsGen = require('./generators/zws'); const zwsGen = require('./generators/zws');
const randomGen = require('./generators/random'); const randomGen = require('./generators/random');
const gfyGen = require('./generators/gfycat'); const gfyGen = require('./generators/gfycat');
const { HTTP, HTTPS, KILOBYTES } = require('./MagicNumbers.json'); const { HTTP, HTTPS, KILOBYTES } = require('../MagicNumbers.json');
// Catch config.json not existing when running setup script // Catch config.json not existing when running setup script
try { try {
var { useSsl, port, domain, isProxied, diskFilePath, saveWithDate, s3bucket, s3endpoint, s3usePathStyle } = require('./config.json'); // skipcq: JS-0239, JS-0102 var { useSsl, port, domain, isProxied, diskFilePath, saveWithDate, s3bucket, s3endpoint, s3usePathStyle } = require('../config.json'); // skipcq: JS-0239, JS-0102
} catch (ex) { } catch (ex) {
if (ex.code !== 'MODULE_NOT_FOUND') console.error(ex); if (ex.code !== 'MODULE_NOT_FOUND') console.error(ex);
} }
@ -74,7 +74,7 @@ function getDatedDirname() {
} }
// Set up pathing & the logger // Set up pathing & the logger
const path = (...paths) => Path.join(process.cwd(), ...paths); const path = (...paths) => Path.join(process.cwd(), ...paths); // '..' was added to make it easier to run files after moving the project to src/
const logger = new TLog({ const logger = new TLog({
level: process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'info' : 'debug'), level: process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'info' : 'debug'),
timestamp: { timestamp: {
@ -85,11 +85,7 @@ const logger = new TLog({
}); });
// Enable the Express logger // Enable the Express logger
logger logger.enable.express({ handle500: false }).debug('Plugin enabled', 'Express');
.env('ASS_ENV')
//.enable.process({ uncaughtException: false }).debug('Plugin enabled', 'Process')
.enable.express({ handle500: false }).debug('Plugin enabled', 'Express')
.enable.socket().debug('Plugin enabled', 'Socket');
const idModes = { const idModes = {
zws: 'zws', // Zero-width spaces (see: https://zws.im/) zws: 'zws', // Zero-width spaces (see: https://zws.im/)
Loading…
Cancel
Save