From 41c0a0ae428fa013bf70b29d92868861d9d96830 Mon Sep 17 00:00:00 2001 From: tycrek Date: Thu, 8 Jul 2021 11:04:40 -0600 Subject: [PATCH] Improved some log outputs --- ass.js | 10 +++++++--- auth.js | 4 ++-- routers/upload.js | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/ass.js b/ass.js index f649aba..c017a76 100755 --- a/ass.js +++ b/ass.js @@ -16,14 +16,18 @@ const helmet = require('helmet'); const marked = require('marked'); const uploadRouter = require('./routers/upload'); const resourceRouter = require('./routers/resource'); -const { path, log } = require('./utils'); +const { path, log, getTrueHttp, getTrueDomain } = require('./utils'); const { CODE_NO_CONTENT, CODE_INTERNAL_SERVER_ERROR } = require('./MagicNumbers.json'); +const { name: ASS_NAME, version: ASS_VERSION } = require('./package.json'); //#endregion +// Welcome :D +log(`\n * ${ASS_NAME} v${ASS_VERSION} * \n`); + // Set up premium frontend const FRONTEND_NAME = 'ass-x'; // <-- Change this to use a custom frontend const ASS_PREMIUM = fs.existsSync(`./${FRONTEND_NAME}/package.json`) ? (require('submodule'), require(`./${FRONTEND_NAME}`)) : { enabled: false }; -log(`Frontend: ${ASS_PREMIUM.enabled ? ASS_PREMIUM.brand : ''}`); +log(`Frontend: ${ASS_PREMIUM.enabled ? ASS_PREMIUM.brand : ''}${ASS_PREMIUM.enabled && ASS_PREMIUM.index ? ' (with index)' : ''}`); //#region Variables, module setup const app = express(); @@ -86,4 +90,4 @@ app.use(([err, , res,]) => { }); // Host the server -app.listen(port, host, () => log(`Server started on [${host}:${port}]\nAuthorized users: ${Object.keys(users).length}\nAvailable files: ${data.size}`)); +app.listen(port, host, () => log(`Users: ${Object.keys(users).length}\nFiles: ${data.size}\n\nListening on: ${host}:${port}${ASS_PREMIUM.enabled ? ` (frontend: ${getTrueHttp()}${getTrueDomain()}${ASS_PREMIUM.endpoint})` : ''}\n`)); diff --git a/auth.js b/auth.js index 892f57b..6680dbc 100644 --- a/auth.js +++ b/auth.js @@ -10,8 +10,8 @@ if (!fs.existsSync(path('auth.json'))) { let users = {}; users[generateToken()] = { username: 'ass', count: 0 }; fs.writeJsonSync(path('auth.json'), { users }, { spaces: 4 }); - log(`File [auth.json] created\n\n!! Important: save this token in a secure spot: ${Object.keys(users)[0]}\n`); -} else log('File [auth.json] exists'); + log(`File created: auth.json\n\n!! Important: save this token in a secure spot: ${Object.keys(users)[0]}`); +} const users = require('./auth.json').users || {}; diff --git a/routers/upload.js b/routers/upload.js index 9b230c4..7fe2d94 100644 --- a/routers/upload.js +++ b/routers/upload.js @@ -60,7 +60,7 @@ router.post('/', (req, res, next) => { const resourceId = generateId(generator, resourceIdSize, req.headers['x-ass-gfycat'] || gfyIdSize, req.file.originalname); data.put(resourceId.split('.')[0], req.file).then(() => { // Log the upload - const logInfo = `${req.file.originalname} (${req.file.mimetype})`; + const logInfo = `${req.file.originalname} (${req.file.mimetype}, ${formatBytes(req.file.size)})`; log(`Uploaded: ${logInfo} (user: ${users[req.token] ? users[req.token].username : ''})`); // Build the URLs