Skip to content

Commit

Permalink
ランダム文字列でアップロードする際に拡張子内にドットが含まれるものを正常にアップロードできるように (#199)
Browse files Browse the repository at this point in the history
* fix(frontend): 拡張子内にドットが含まれるものを正常にアップロードできるように

(cherry picked from commit f3a7b48)

* 拡張子内にドットを2つまで許容するものを追加する仕様に変更

(cherry picked from commit 754bb92)

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

---------

Co-authored-by: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com>
  • Loading branch information
anatawa12 and kakkokari-gtyih committed Jun 3, 2024
1 parent 7b5cb59 commit b55dd9e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Client
- Enhance: Unicode絵文字をslugから入力する際に`:ok:`のように最後の`:`を入力したあとにUnicode絵文字に変換できるように
- Fix: フォロー中のユーザーに関する"TLに他の人への返信を含める"の設定が分かりづらい問題を修正
- Fix: ランダム文字列でアップロードする際に拡張子内にドットが含まれるものを正常にアップロードできるように

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

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

0 comments on commit b55dd9e

Please sign in to comment.