feat: add configuration for default upload format (#232)
* feat: add configuration for default upload format * fix: change default back to original
This commit is contained in:
parent
fd9908833a
commit
8e1541ea56
5 changed files with 7 additions and 2 deletions
|
@ -34,6 +34,7 @@ DATASOURCE_SWIFT_PASSWORD=password
|
|||
DATASOURCE_SWIFT_PROJECT_ID=project_id
|
||||
DATASOURCE_SWIFT_DOMAIN_ID=domain_id
|
||||
|
||||
UPLOADER_DEFAULT_FORMAT=RANDOM
|
||||
UPLOADER_ROUTE=/u
|
||||
UPLOADER_LENGTH=6
|
||||
UPLOADER_ADMIN_LIMIT=104900000
|
||||
|
@ -44,4 +45,4 @@ URLS_ROUTE=/go
|
|||
URLS_LENGTH=6
|
||||
|
||||
RATELIMIT_USER = 5
|
||||
RATELIMIT_ADMIN = 3
|
||||
RATELIMIT_ADMIN = 3
|
||||
|
|
|
@ -43,6 +43,7 @@ export interface ConfigSwiftDatasource {
|
|||
}
|
||||
|
||||
export interface ConfigUploader {
|
||||
default_format: string;
|
||||
route: string;
|
||||
length: number;
|
||||
admin_limit: number;
|
||||
|
|
|
@ -85,6 +85,7 @@ export default function readConfig() {
|
|||
map('DATASOURCE_SWIFT_DOMAIN_ID', 'string', 'datasource.swift.domain_id'),
|
||||
map('DATASOURCE_SWIFT_REGION_ID', 'string', 'datasource.swift.region_id'),
|
||||
|
||||
map('UPLOADER_DEFAULT_FORMAT', 'string', 'uploader.default_format'),
|
||||
map('UPLOADER_ROUTE', 'string', 'uploader.route'),
|
||||
map('UPLOADER_LENGTH', 'number', 'uploader.length'),
|
||||
map('UPLOADER_ADMIN_LIMIT', 'human-to-byte', 'uploader.admin_limit'),
|
||||
|
|
|
@ -77,6 +77,7 @@ const validator = s.object({
|
|||
}),
|
||||
uploader: s
|
||||
.object({
|
||||
default_format: s.string.default('RANDOM'),
|
||||
route: s.string.default('/u'),
|
||||
embed_route: s.string.default('/a'),
|
||||
length: s.number.default(6),
|
||||
|
@ -86,6 +87,7 @@ const validator = s.object({
|
|||
format_date: s.string.default('YYYY-MM-DD_HH:mm:ss'),
|
||||
})
|
||||
.default({
|
||||
default_format: 'RANDOM',
|
||||
route: '/u',
|
||||
embed_route: '/a',
|
||||
length: 6,
|
||||
|
|
|
@ -49,7 +49,7 @@ async function handler(req: NextApiReq, res: NextApiRes) {
|
|||
}
|
||||
}
|
||||
|
||||
const rawFormat = ((req.headers.format || '') as string).toUpperCase() || 'RANDOM';
|
||||
const rawFormat = ((req.headers.format || '') as string).toUpperCase() || zconfig.uploader.default_format;
|
||||
const format: ImageFormat = Object.keys(ImageFormat).includes(rawFormat) && ImageFormat[rawFormat];
|
||||
|
||||
const imageCompressionPercent = req.headers['image-compression-percent']
|
||||
|
|
Loading…
Reference in a new issue