Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ランダム文字列でアップロードする際に拡張子内にドットが含まれるものを正常にアップロードできるように #199

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
### General
- Fix: パブリック投稿をホーム投稿に変更するモデレーション操作がリプライに正しく適用されていなかった問題を修正

### Client
- Fix: ランダム文字列でアップロードする際に拡張子内にドットが含まれるものを正常にアップロードできるように

## 2024.5.0 (merged to 2024.5.0-kinel.1)

### Note
Expand Down
28 changes: 27 additions & 1 deletion packages/frontend/src/scripts/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,32 @@ const mimeTypeMap = {
'image/png': 'png',
} as const;

// tar.gzなど、拡張子内にドットを2つまで許容するものはここに追加
const specialExtensions = [
'gz',
'bz2',
'xz',
'zst',
'lz',
'lz4',
'sz',
'z',
'zstd',
] as const;

function getExtension(filename: string): string {
const parts = filename.split('.');

if (parts.length <= 1) return '';

for (const ext of specialExtensions) {
if (parts[parts.length - 1] === ext && parts.length > 2) {
return '.' + parts[parts.length - 2] + '.' + parts[parts.length - 1];
}
}
return '.' + parts.pop();
}

export function uploadFile(
file: File,
folder?: any,
Expand All @@ -45,7 +71,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
Loading