mirror of
https://github.com/diced/zipline.git
synced 2025-04-11 23:31:17 -05:00
feat: common double-extensions like .tar.gz supported
This commit is contained in:
parent
86b4e5fdcb
commit
171790613d
2 changed files with 31 additions and 7 deletions
|
@ -1,8 +1,3 @@
|
|||
import { ApiUploadResponse, MultipartFileBuffer } from '@/server/routes/api/upload';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { extname, join } from 'path';
|
||||
import { Worker } from 'worker_threads';
|
||||
import { config } from '@/lib/config';
|
||||
import { hashPassword } from '@/lib/crypto';
|
||||
import { prisma } from '@/lib/db';
|
||||
|
@ -10,6 +5,12 @@ import { log } from '@/lib/logger';
|
|||
import { guess } from '@/lib/mimes';
|
||||
import { formatFileName } from '@/lib/uploader/formatFileName';
|
||||
import { UploadHeaders, UploadOptions } from '@/lib/uploader/parseHeaders';
|
||||
import { ApiUploadResponse, MultipartFileBuffer } from '@/server/routes/api/upload';
|
||||
import { FastifyRequest } from 'fastify';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { Worker } from 'worker_threads';
|
||||
import { getExtension } from './upload';
|
||||
|
||||
const logger = log('api').c('upload');
|
||||
export async function handlePartialUpload({
|
||||
|
@ -31,7 +32,8 @@ export async function handlePartialUpload({
|
|||
if (!options.partial.identifier || !options.partial.range || options.partial.range.length !== 3)
|
||||
throw 'Invalid partial upload';
|
||||
|
||||
const extension = options.overrides?.extension ?? extname(options.partial.filename);
|
||||
const extension = getExtension(options.partial.filename, options.overrides?.extension);
|
||||
|
||||
if (config.files.disabledExtensions.includes(extension)) throw `File extension ${extension} is not allowed`;
|
||||
|
||||
const format = options.format || config.files.defaultFormat;
|
||||
|
|
|
@ -17,6 +17,27 @@ import { UploadHeaders, UploadOptions } from '@/lib/uploader/parseHeaders';
|
|||
|
||||
const logger = log('api').c('upload');
|
||||
|
||||
const commonDoubleExts = [
|
||||
'.tar.gz',
|
||||
'.tar.xz',
|
||||
'.tar.bz2',
|
||||
'.tar.lz',
|
||||
'.tar.lzma',
|
||||
'.tar.Z',
|
||||
'.tar.7z',
|
||||
'.zip.gz',
|
||||
'.zip.xz',
|
||||
'.rar.gz',
|
||||
'.log.gz',
|
||||
'.csv.gz',
|
||||
'.pdf.gz',
|
||||
// feel free to PR more
|
||||
];
|
||||
|
||||
export const getExtension = (filename: string, override?: string): string => {
|
||||
return override ?? commonDoubleExts.find((ext) => filename.endsWith(ext)) ?? extname(filename);
|
||||
};
|
||||
|
||||
export async function handleFile({
|
||||
file,
|
||||
i,
|
||||
|
@ -32,7 +53,8 @@ export async function handleFile({
|
|||
response: ApiUploadResponse;
|
||||
req: FastifyRequest<{ Headers: UploadHeaders }>;
|
||||
}) {
|
||||
const extension = options.overrides?.extension ?? extname(file.filename);
|
||||
const extension = getExtension(file.filename, options.overrides?.extension);
|
||||
|
||||
if (config.files.disabledExtensions.includes(extension)) throw `File extension ${extension} is not allowed`;
|
||||
|
||||
if (file.file.bytesRead > bytes(config.files.maxFileSize))
|
||||
|
|
Loading…
Add table
Reference in a new issue