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:
karlmanait 2022-11-23 12:36:49 +08:00 committed by GitHub
parent fd9908833a
commit 8e1541ea56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 2 deletions

View file

@ -34,6 +34,7 @@ DATASOURCE_SWIFT_PASSWORD=password
DATASOURCE_SWIFT_PROJECT_ID=project_id DATASOURCE_SWIFT_PROJECT_ID=project_id
DATASOURCE_SWIFT_DOMAIN_ID=domain_id DATASOURCE_SWIFT_DOMAIN_ID=domain_id
UPLOADER_DEFAULT_FORMAT=RANDOM
UPLOADER_ROUTE=/u UPLOADER_ROUTE=/u
UPLOADER_LENGTH=6 UPLOADER_LENGTH=6
UPLOADER_ADMIN_LIMIT=104900000 UPLOADER_ADMIN_LIMIT=104900000

View file

@ -43,6 +43,7 @@ export interface ConfigSwiftDatasource {
} }
export interface ConfigUploader { export interface ConfigUploader {
default_format: string;
route: string; route: string;
length: number; length: number;
admin_limit: number; admin_limit: number;

View file

@ -85,6 +85,7 @@ export default function readConfig() {
map('DATASOURCE_SWIFT_DOMAIN_ID', 'string', 'datasource.swift.domain_id'), map('DATASOURCE_SWIFT_DOMAIN_ID', 'string', 'datasource.swift.domain_id'),
map('DATASOURCE_SWIFT_REGION_ID', 'string', 'datasource.swift.region_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_ROUTE', 'string', 'uploader.route'),
map('UPLOADER_LENGTH', 'number', 'uploader.length'), map('UPLOADER_LENGTH', 'number', 'uploader.length'),
map('UPLOADER_ADMIN_LIMIT', 'human-to-byte', 'uploader.admin_limit'), map('UPLOADER_ADMIN_LIMIT', 'human-to-byte', 'uploader.admin_limit'),

View file

@ -77,6 +77,7 @@ const validator = s.object({
}), }),
uploader: s uploader: s
.object({ .object({
default_format: s.string.default('RANDOM'),
route: s.string.default('/u'), route: s.string.default('/u'),
embed_route: s.string.default('/a'), embed_route: s.string.default('/a'),
length: s.number.default(6), length: s.number.default(6),
@ -86,6 +87,7 @@ const validator = s.object({
format_date: s.string.default('YYYY-MM-DD_HH:mm:ss'), format_date: s.string.default('YYYY-MM-DD_HH:mm:ss'),
}) })
.default({ .default({
default_format: 'RANDOM',
route: '/u', route: '/u',
embed_route: '/a', embed_route: '/a',
length: 6, length: 6,

View file

@ -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 format: ImageFormat = Object.keys(ImageFormat).includes(rawFormat) && ImageFormat[rawFormat];
const imageCompressionPercent = req.headers['image-compression-percent'] const imageCompressionPercent = req.headers['image-compression-percent']