feat: default expiration/ttl (#237)
This commit is contained in:
parent
cb123cb575
commit
78e884e97e
4 changed files with 10 additions and 0 deletions
|
@ -46,6 +46,7 @@ export interface ConfigUploader {
|
|||
user_limit: number;
|
||||
disabled_extensions: string[];
|
||||
format_date: string;
|
||||
default_expiration: string;
|
||||
}
|
||||
|
||||
export interface ConfigUrls {
|
||||
|
|
|
@ -3,6 +3,7 @@ import { expand } from 'dotenv-expand';
|
|||
import { existsSync, readFileSync } from 'fs';
|
||||
import Logger from '../logger';
|
||||
import { humanToBytes } from '../utils/bytes';
|
||||
import { parseExpiry } from '../utils/client';
|
||||
|
||||
export type ValueType = 'string' | 'number' | 'boolean' | 'array' | 'json-array' | 'human-to-byte';
|
||||
|
||||
|
@ -88,6 +89,7 @@ export default function readConfig() {
|
|||
map('UPLOADER_USER_LIMIT', 'human-to-byte', 'uploader.user_limit'),
|
||||
map('UPLOADER_DISABLED_EXTENSIONS', 'array', 'uploader.disabled_extensions'),
|
||||
map('UPLOADER_FORMAT_DATE', 'string', 'uploader.format_date'),
|
||||
map('UPLOADER_DEFAULT_EXPIRATION', 'string', 'uploader.default_expiration'),
|
||||
|
||||
map('URLS_ROUTE', 'string', 'urls.route'),
|
||||
map('URLS_LENGTH', 'number', 'urls.length'),
|
||||
|
|
|
@ -78,6 +78,7 @@ const validator = s.object({
|
|||
user_limit: s.number.default(humanToBytes('100MB')),
|
||||
disabled_extensions: s.string.array.default([]),
|
||||
format_date: s.string.default('YYYY-MM-DD_HH:mm:ss'),
|
||||
default_expiration: s.string.optional.default(null),
|
||||
})
|
||||
.default({
|
||||
default_format: 'RANDOM',
|
||||
|
@ -88,6 +89,7 @@ const validator = s.object({
|
|||
user_limit: humanToBytes('100MB'),
|
||||
disabled_extensions: [],
|
||||
format_date: 'YYYY-MM-DD_HH:mm:ss',
|
||||
default_expiration: null,
|
||||
}),
|
||||
urls: s
|
||||
.object({
|
||||
|
|
|
@ -49,6 +49,11 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
}
|
||||
}
|
||||
|
||||
if (zconfig.uploader.default_expiration) {
|
||||
expiry = parseExpiry(zconfig.uploader.default_expiration);
|
||||
if (!expiry) return res.badRequest('invalid date (UPLOADER_DEFAULT_EXPIRATION)');
|
||||
}
|
||||
|
||||
const rawFormat = ((req.headers.format || '') as string).toUpperCase() || zconfig.uploader.default_format;
|
||||
const format: ImageFormat = Object.keys(ImageFormat).includes(rawFormat) && ImageFormat[rawFormat];
|
||||
|
||||
|
|
Loading…
Reference in a new issue