Improved some log outputs

pull/29/head
tycrek 3 years ago
parent 3405508080
commit 41c0a0ae42
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -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 : '<none>'}`);
log(`Frontend: ${ASS_PREMIUM.enabled ? ASS_PREMIUM.brand : '<none>'}${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`));

@ -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 || {};

@ -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 : '<token-only>'})`);
// Build the URLs

Loading…
Cancel
Save