From 16e92e6447559934c4129186c7a3ca7e60e2ed10 Mon Sep 17 00:00:00 2001 From: kakkokari-gtyih <67428053+kakkokari-gtyih@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:39:35 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=BB=E3=83=B3=E3=82=B7=E3=83=86=E3=82=A3?= =?UTF-8?q?=E3=83=96=E3=81=AA=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E9=81=B8=E6=8A=9E=E3=81=A7=E3=81=8D=E3=81=AA=E3=81=84=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/index.d.ts | 9 +++++ locales/ja-JP.yml | 2 ++ .../frontend/src/components/MkDrive.file.vue | 14 +++++++- packages/frontend/src/components/MkDrive.vue | 3 ++ .../src/components/MkDriveSelectDialog.vue | 3 +- packages/frontend/src/os.ts | 3 +- .../frontend/src/pages/settings/profile.vue | 4 +-- packages/frontend/src/scripts/select-file.ts | 33 +++++++++++++------ 8 files changed, 56 insertions(+), 15 deletions(-) diff --git a/locales/index.d.ts b/locales/index.d.ts index 01bec41d9e..690cf33b70 100644 --- a/locales/index.d.ts +++ b/locales/index.d.ts @@ -4936,6 +4936,15 @@ export interface Locale extends ILocale { * 動画・音声の再生にブラウザのUIを使用する */ "useNativeUIForVideoAudioPlayer": string; + /** + * センシティブなメディアは選択できません + */ + "cannotSelectSensitiveMedia": string; + /** + * 自分でセンシティブ設定を行っていないのにこのエラーが出ている場合、自動判定によりセンシティブなメディアとされている可能性があります。 + * サーバーの規則に照らして不要な場合は、ファイルのセンシティブ設定を解除してもう一度お試しください。 + */ + "cannotSelectSensitiveMediaDescription": string; "_bubbleGame": { /** * 遊び方 diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 4ba9ea0221..9bd813a856 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1230,6 +1230,8 @@ useTotp: "ワンタイムパスワードを使う" useBackupCode: "バックアップコードを使う" launchApp: "アプリを起動" useNativeUIForVideoAudioPlayer: "動画・音声の再生にブラウザのUIを使用する" +cannotSelectSensitiveMedia: "センシティブなメディアは選択できません" +cannotSelectSensitiveMediaDescription: "自分でセンシティブ設定を行っていないのにこのエラーが出ている場合、自動判定によりセンシティブなメディアとされている可能性があります。\nサーバーの規則に照らして不要な場合は、ファイルのセンシティブ設定を解除してもう一度お試しください。" _bubbleGame: howToPlay: "遊び方" diff --git a/packages/frontend/src/components/MkDrive.file.vue b/packages/frontend/src/components/MkDrive.file.vue index 4106b0a436..4380b4605e 100644 --- a/packages/frontend/src/components/MkDrive.file.vue +++ b/packages/frontend/src/components/MkDrive.file.vue @@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only - + @@ -34,6 +34,7 @@ import { i18n } from '@/i18n.js'; withDefaults(defineProps<{ type?: 'file' | 'folder'; multiple: boolean; + excludeSensitive: boolean; }>(), { type: 'file', }); diff --git a/packages/frontend/src/os.ts b/packages/frontend/src/os.ts index c561e84a23..7c60d38543 100644 --- a/packages/frontend/src/os.ts +++ b/packages/frontend/src/os.ts @@ -541,11 +541,12 @@ export async function selectUser(opts: { includeSelf?: boolean; localOnly?: bool }); } -export async function selectDriveFile(multiple: boolean): Promise { +export async function selectDriveFile(multiple: boolean, excludeSensitive: boolean): Promise { return new Promise(resolve => { popup(defineAsyncComponent(() => import('@/components/MkDriveSelectDialog.vue')), { type: 'file', multiple, + excludeSensitive, }, { done: files => { if (files) { diff --git a/packages/frontend/src/pages/settings/profile.vue b/packages/frontend/src/pages/settings/profile.vue index 60bf9b4d3d..4b0363ef33 100644 --- a/packages/frontend/src/pages/settings/profile.vue +++ b/packages/frontend/src/pages/settings/profile.vue @@ -204,7 +204,7 @@ function save() { } function changeAvatar(ev) { - selectFile(ev.currentTarget ?? ev.target, i18n.ts.avatar).then(async (file) => { + selectFile(ev.currentTarget ?? ev.target, i18n.ts.avatar, true).then(async (file) => { let originalOrCropped = file; const { canceled } = await os.confirm({ @@ -231,7 +231,7 @@ function changeAvatar(ev) { } function changeBanner(ev) { - selectFile(ev.currentTarget ?? ev.target, i18n.ts.banner).then(async (file) => { + selectFile(ev.currentTarget ?? ev.target, i18n.ts.banner, true).then(async (file) => { let originalOrCropped = file; const { canceled } = await os.confirm({ diff --git a/packages/frontend/src/scripts/select-file.ts b/packages/frontend/src/scripts/select-file.ts index 9aa38178b2..c2fc3ef7a4 100644 --- a/packages/frontend/src/scripts/select-file.ts +++ b/packages/frontend/src/scripts/select-file.ts @@ -39,9 +39,9 @@ export function chooseFileFromPc(multiple: boolean, keepOriginal = false): Promi }); } -export function chooseFileFromDrive(multiple: boolean): Promise { +export function chooseFileFromDrive(multiple: boolean, excludeSensitive: boolean): Promise { return new Promise((res, rej) => { - os.selectDriveFile(multiple).then(files => { + os.selectDriveFile(multiple, excludeSensitive).then(files => { res(files); }); }); @@ -80,10 +80,23 @@ export function chooseFileFromUrl(): Promise { }); } -function select(src: any, label: string | null, multiple: boolean): Promise { +function select(src: any, label: string | null, multiple: boolean, excludeSensitive: boolean): Promise { return new Promise((res, rej) => { const keepOriginal = ref(defaultStore.state.keepOriginalUploading); + function _resolve(files: Misskey.entities.DriveFile[]) { + if (excludeSensitive && files.some(file => file.isSensitive)) { + os.alert({ + title: i18n.ts.cannotSelectSensitiveMedia, + text: i18n.ts.cannotSelectSensitiveMediaDescription, + }); + rej(); + return; + } + + res(files); + } + os.popupMenu([label ? { text: label, type: 'label', @@ -94,23 +107,23 @@ function select(src: any, label: string | null, multiple: boolean): Promise chooseFileFromPc(multiple, keepOriginal.value).then(files => res(files)), + action: () => chooseFileFromPc(multiple, keepOriginal.value).then(files => _resolve(files)), }, { text: i18n.ts.fromDrive, icon: 'ti ti-cloud', - action: () => chooseFileFromDrive(multiple).then(files => res(files)), + action: () => chooseFileFromDrive(multiple, excludeSensitive).then(files => _resolve(files)), }, { text: i18n.ts.fromUrl, icon: 'ti ti-link', - action: () => chooseFileFromUrl().then(file => res([file])), + action: () => chooseFileFromUrl().then(file => _resolve([file])), }], src); }); } -export function selectFile(src: any, label: string | null = null): Promise { - return select(src, label, false).then(files => files[0]); +export function selectFile(src: any, label: string | null = null, excludeSensitive = false): Promise { + return select(src, label, false, excludeSensitive).then(files => files[0]); } -export function selectFiles(src: any, label: string | null = null): Promise { - return select(src, label, true); +export function selectFiles(src: any, label: string | null = null, excludeSensitive = false): Promise { + return select(src, label, true, excludeSensitive); }