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

feat(frontend): アップロードするファイルの名前をランダム文字列にできるように #13688

Merged
merged 7 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Fix: Play作成時に設定した公開範囲が機能していない問題を修正

### Client
- Feat: アップロードするファイルの名前をランダム文字列にできるように
- Enhance: 自分のノートの添付ファイルから直接ファイルの詳細ページに飛べるように
- Enhance: 広告がMisskeyと同一ドメインの場合はRouterで遷移するように
- Enhance: リアクション・いいねの総数を表示するように
Expand Down
8 changes: 8 additions & 0 deletions locales/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4936,6 +4936,14 @@ export interface Locale extends ILocale {
* 動画・音声の再生にブラウザのUIを使用する
*/
"useNativeUIForVideoAudioPlayer": string;
/**
* オリジナルのファイル名を保持
*/
"keepOriginalFilename": string;
/**
* この設定をオフにすると、アップロード時にファイル名が自動でランダム文字列に置き換えられます。
*/
"keepOriginalFilenameDescription": string;
"_bubbleGame": {
/**
* 遊び方
Expand Down
2 changes: 2 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,8 @@ useTotp: "ワンタイムパスワードを使う"
useBackupCode: "バックアップコードを使う"
launchApp: "アプリを起動"
useNativeUIForVideoAudioPlayer: "動画・音声の再生にブラウザのUIを使用する"
keepOriginalFilename: "オリジナルのファイル名を保持"
keepOriginalFilenameDescription: "この設定をオフにすると、アップロード時にファイル名が自動でランダム文字列に置き換えられます。"

_bubbleGame:
howToPlay: "遊び方"
Expand Down
5 changes: 5 additions & 0 deletions packages/frontend/src/pages/settings/drive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #label>{{ i18n.ts.keepOriginalUploading }}</template>
<template #caption>{{ i18n.ts.keepOriginalUploadingDescription }}</template>
</MkSwitch>
<MkSwitch v-model="keepOriginalFilename">
<template #label>{{ i18n.ts.keepOriginalFilename }}</template>
<template #caption>{{ i18n.ts.keepOriginalFilenameDescription }}</template>
</MkSwitch>
<MkSwitch v-model="alwaysMarkNsfw" @update:modelValue="saveProfile()">
<template #label>{{ i18n.ts.alwaysMarkSensitive }}</template>
</MkSwitch>
Expand Down Expand Up @@ -96,6 +100,7 @@ const meterStyle = computed(() => {
});

const keepOriginalUploading = computed(defaultStore.makeGetterSetter('keepOriginalUploading'));
const keepOriginalFilename = computed(defaultStore.makeGetterSetter('keepOriginalFilename'));

misskeyApi('drive').then(info => {
capacity.value = info.capacity;
Expand Down
10 changes: 7 additions & 3 deletions packages/frontend/src/scripts/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { reactive, ref } from 'vue';
import * as Misskey from 'misskey-js';
import { v4 as uuid } from 'uuid';
import { readAndCompressImage } from '@misskey-dev/browser-image-resizer';
import { getCompressionConfig } from './upload/compress-config.js';
import { defaultStore } from '@/store.js';
Expand Down Expand Up @@ -39,13 +40,16 @@ export function uploadFile(
if (folder && typeof folder === 'object') folder = folder.id;

return new Promise((resolve, reject) => {
const id = Math.random().toString();
const id = uuid();

const reader = new FileReader();
reader.onload = async (): Promise<void> => {
const filename = name ?? file.name ?? 'untitled';
const extension = filename.split('.').length > 1 ? '.' + filename.split('.').pop() : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename.tar.gzのようなケースで.gzしか付与されないことになりそうですが、大丈夫なのでしょうか…?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

それはそれで判別が難しそう(tar.gzだけ特別対応でも良いかもしれない)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考までに、tarを圧縮するシリーズで著名なものとして以下があります

  • tar.gz
  • tar.bz2
  • tar.xz

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#13699

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非アーカイブ系の圧縮ファイル(.gz .zstd等)については2つのドットまでとするとかのほうが良さそう

.cpio.gzとか組み合わせ爆発するので

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうした


const ctx = reactive<Uploading>({
id: id,
name: name ?? file.name ?? 'untitled',
id,
name: defaultStore.state.keepOriginalFilename ? filename : id + extension,
progressMax: undefined,
progressValue: undefined,
img: window.URL.createObjectURL(file),
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,10 @@ export const defaultStore = markRaw(new Storage('base', {
where: 'device',
default: false,
},
keepOriginalFilename: {
where: 'device',
default: true,
},

sound_masterVolume: {
where: 'device',
Expand Down
Loading