Skip to content

Commit

Permalink
fix(frontend): 拡張子内にドットが含まれるものを正常にアップロードできるように
Browse files Browse the repository at this point in the history
  • Loading branch information
kakkokari-gtyih committed Apr 13, 2024
1 parent f5100cc commit f3a7b48
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/frontend/src/scripts/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ const mimeTypeMap = {
'image/png': 'png',
} as const;

// tar.gzなど、拡張子内にドットが含まれるものはここに追加
const specialExtensions = [
'tar.gz',
'tar.bz2',
'tar.xz',
'tar.zst',
'tar.lz',
'tar.lz4',
'tar.sz',
'tar.z',
] as const;

function getExtension(filename: string): string {
for (const ext of specialExtensions) {
if (filename.endsWith('.' + ext)) return '.' + ext;
}
const parts = filename.split('.');
return parts.length > 1 ? '.' + parts.pop()! : '';
}

export function uploadFile(
file: File,
folder?: any,
Expand All @@ -45,7 +65,7 @@ export function uploadFile(
const reader = new FileReader();
reader.onload = async (): Promise<void> => {
const filename = name ?? file.name ?? 'untitled';
const extension = filename.split('.').length > 1 ? '.' + filename.split('.').pop() : '';
const extension = getExtension(filename);

const ctx = reactive<Uploading>({
id,
Expand Down

0 comments on commit f3a7b48

Please sign in to comment.