feat: added `savePerDay` (closes #140)

pull/190/head
tycrek 1 year ago
parent d44f26091d
commit d3f49158da
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

@ -17,6 +17,7 @@ const config = {
dataEngine: '@tycrek/papito',
frontendName: 'ass-x',
useSia: false,
savePerDay: false,
adminWebhookEnabled: false,
s3enabled: false,
};
@ -200,6 +201,12 @@ function doSetup() {
default: config.useSia,
required: false
},
savePerDay: {
description: 'Save uploads in folders by day (YYYY-MM-DD) instead of by month (YYYY-MM)',
type: 'boolean',
default: config.savePerDay,
required: false
},
adminWebhookEnabled: {
description: 'Enable admin Discord webhook (This will let you audit ALL uploads, from ALL users)',
type: 'boolean',

@ -12,7 +12,7 @@ import { path, generateId, log } from './utils';
import { SkynetUpload } from './skynet';
import { Request, Response } from 'express';
import { removeGPS } from './nightmare';
const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, diskFilePath, saveAsOriginal, saveWithDate, mediaStrict, maxUploadSize, useSia }: Config = fs.readJsonSync(path('config.json'));
const { s3enabled, s3endpoint, s3bucket, s3usePathStyle, s3accessKey, s3secretKey, diskFilePath, saveAsOriginal, saveWithDate, savePerDay, mediaStrict, maxUploadSize, useSia }: Config = fs.readJsonSync(path('config.json'));
const { CODE_UNSUPPORTED_MEDIA_TYPE }: MagicNumbers = fs.readJsonSync(path('MagicNumbers.json'));
const ID_GEN_LENGTH = 32;
@ -34,8 +34,22 @@ function getDatedDirname() {
return `${diskFilePath}${diskFilePath.endsWith('/') ? '' : '/'}${year}-${`0${month}`.slice(-2)}`; // skipcq: JS-0074
}
/**
* A bit hacky but it works
* @since 0.14.1
*/
function getDatedDirnameWithDay() {
if (!savePerDay) return getDatedDirname();
// Get current day
const [, day] = new Date().toLocaleDateString('en-US').split('/');
// Add 0 before single digit days (6 turns into 06)
return `${getDatedDirname()}-${`0${day}`.slice(-2)}`; // skipcq: JS-0074
}
function getLocalFilename(req: Request) {
let name = `${getDatedDirname()}/${saveAsOriginal ? req.file.originalname : req.file.sha1}`;
let name = `${getDatedDirnameWithDay()}/${saveAsOriginal ? req.file.originalname : req.file.sha1}`;
// Append a number if this file has already been uploaded before
let count = 0;

@ -18,6 +18,7 @@ declare module 'ass-json' {
frontendName: string
indexFile: string
useSia: boolean
savePerDay: boolean
adminWebhookEnabled: boolean
adminWebhookUrl: string
adminWebhookUsername: string

Loading…
Cancel
Save