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_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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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'),
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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']
|
||||||
|
|
Loading…
Reference in a new issue