ドライブで複数選択できるようにした

This commit is contained in:
mattyatea 2023-10-06 08:01:42 +09:00
parent a328a03c51
commit c345383374
6 changed files with 370 additions and 123 deletions

4
locales/index.d.ts vendored
View File

@ -79,6 +79,10 @@ export interface Locale {
"files": string; "files": string;
"download": string; "download": string;
"driveFileDeleteConfirm": string; "driveFileDeleteConfirm": string;
"driveFilesDeleteConfirm": string;
"driveFilesSensitiveonConfirm": string;
"driveFilesSensitiveoffConfirm": string;
"driveFolderDeleteConfirm": string;
"unfollowConfirm": string; "unfollowConfirm": string;
"exportRequested": string; "exportRequested": string;
"importRequested": string; "importRequested": string;

View File

@ -76,6 +76,10 @@ export: "エクスポート"
files: "ファイル" files: "ファイル"
download: "ダウンロード" download: "ダウンロード"
driveFileDeleteConfirm: "ファイル「{name}」を削除しますか?このファイルを使用した一部のコンテンツも削除されます。" driveFileDeleteConfirm: "ファイル「{name}」を削除しますか?このファイルを使用した一部のコンテンツも削除されます。"
driveFilesDeleteConfirm: "{name}つのファイルを削除しますか?このファイルを使用した一部のコンテンツも削除されます。"
driveFilesSensitiveonConfirm: "{name}つのファイルをセンシティブにしますか?"
driveFilesSensitiveoffConfirm: "{name}つのファイルのセンシティブを解除しますか?"
driveFolderDeleteConfirm: "フォルダ「{name}」を削除しますか?このフォルダの中に存在するファイルを使用した一部のコンテンツも削除されます。"
unfollowConfirm: "{name}のフォローを解除しますか?" unfollowConfirm: "{name}のフォローを解除しますか?"
exportRequested: "エクスポートをリクエストしました。これには時間がかかる場合があります。エクスポートが終わると、「ドライブ」に追加されます。" exportRequested: "エクスポートをリクエストしました。これには時間がかかる場合があります。エクスポートが終わると、「ドライブ」に追加されます。"
importRequested: "インポートをリクエストしました。これには時間がかかる場合があります。" importRequested: "インポートをリクエストしました。これには時間がかかる場合があります。"

View File

@ -1,6 +1,6 @@
{ {
"name": "misskey", "name": "misskey",
"version": "2023.9.3-prismisskey.2", "version": "2023.9.3-prismisskey.3",
"codename": "nasubi", "codename": "nasubi",
"repository": { "repository": {
"type": "git", "type": "git",
@ -18,6 +18,7 @@
"build-assets": "node ./scripts/build-assets.mjs", "build-assets": "node ./scripts/build-assets.mjs",
"build": "pnpm build-pre && pnpm -r build && pnpm build-assets", "build": "pnpm build-pre && pnpm -r build && pnpm build-assets",
"build-storybook": "pnpm --filter frontend build-storybook", "build-storybook": "pnpm --filter frontend build-storybook",
"build-and-start": "pnpm build && pnpm start",
"start": "pnpm check:connect && cd packages/backend && node ./built/boot/entry.js", "start": "pnpm check:connect && cd packages/backend && node ./built/boot/entry.js",
"start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js", "start:test": "cd packages/backend && cross-env NODE_ENV=test node ./built/boot/entry.js",
"init": "pnpm migrate", "init": "pnpm migrate",

View File

@ -44,6 +44,7 @@ const props = withDefaults(defineProps<{
folder: Misskey.entities.DriveFolder; folder: Misskey.entities.DriveFolder;
isSelected?: boolean; isSelected?: boolean;
selectMode?: boolean; selectMode?: boolean;
selectedFiles?: string[];
}>(), { }>(), {
isSelected: false, isSelected: false,
selectMode: false, selectMode: false,
@ -143,10 +144,19 @@ function onDrop(ev: DragEvent) {
if (driveFile != null && driveFile !== '') { if (driveFile != null && driveFile !== '') {
const file = JSON.parse(driveFile); const file = JSON.parse(driveFile);
emit('removeFile', file.id); emit('removeFile', file.id);
if (props.selectedFiles.length > 0) {
props.selectedFiles.forEach((e)=>{
os.api('drive/files/update', {
fileId: e.id,
folderId: props.folder.id,
});
})
}else{
os.api('drive/files/update', { os.api('drive/files/update', {
fileId: file.id, fileId: file.id,
folderId: props.folder.id, folderId: props.folder.id,
}); });
}
} }
//#endregion //#endregion
@ -221,6 +231,57 @@ function rename() {
} }
function deleteFolder() { function deleteFolder() {
os.api('drive/folders/show', {
folderId: props.folder.id,
}).then(async (r) => {
if (r.foldersCount > 0) {
await os.alert({
type: 'error',
title: i18n.ts.unableToDelete,
text: 'フォルダ内にフォルダが存在するため、削除できません。 \n フォルダ内のフォルダを削除してから試してみてください。',
});
}
if (r.filesCount > 0) {
const {canceled} = await os.confirm({
type: 'warning',
text: i18n.t('driveFolderDeleteConfirm', {name: props.folder.name}),
});
if (canceled) return;
let allResults = [];
let Result = await os.api('drive/files', {folderId: props.folder.id, limit: 31});
allResults = allResults.concat(Result)
while (Result.length >= 31) {
const untilId = Result[Result.length - 1].id;
Result = await os.api('drive/files', { folderId: props.folder.id, limit: 31, untilId });
allResults = allResults.concat(Result); // pushconcat
}
allResults.forEach((r,i)=>{
os.api('drive/files/delete',{fileId: r.id})
})
os.api('drive/folders/show', {
folderId: props.folder.id,
}).then(async (r) =>{
if (r.filesCount > 0) {
let allResults = [];
let Result = await os.api('drive/files', {folderId: props.folder.id, limit: 31});
allResults = allResults.concat(Result)
while (Result.length >= 31) {
const untilId = Result[Result.length - 1].id;
Result = await os.api('drive/files', { folderId: props.folder.id, limit: 31, untilId });
allResults = allResults.concat(Result);
}
allResults.forEach((r,i)=>{
os.api('drive/files/delete',{fileId: r.id})
})
os.api('drive/folders/delete', { os.api('drive/folders/delete', {
folderId: props.folder.id, folderId: props.folder.id,
}).then(() => { }).then(() => {
@ -243,7 +304,46 @@ function deleteFolder() {
}); });
} }
}); });
os.api('drive/folders/delete', {
folderId: props.folder.id,
})
}else{
os.api('drive/folders/delete', {
folderId: props.folder.id,
})
} }
})
} else {
await os.api('drive/folders/delete', {
folderId: props.folder.id,
}).then(() => {
if (defaultStore.state.uploadFolder === props.folder.id) {
defaultStore.set('uploadFolder', null);
}
}).catch(err => {
switch (err.id) {
case 'b0fc8a17-963c-405d-bfbc-859a487295e1':
os.alert({
type: 'error',
title: i18n.ts.unableToDelete,
text: i18n.ts.hasChildFilesOrFolders,
});
break;
default:
os.alert({
type: 'error',
text: i18n.ts.unableToDelete,
});
}
});
}
})
}
function setAsUploadFolder() { function setAsUploadFolder() {
defaultStore.set('uploadFolder', props.folder.id); defaultStore.set('uploadFolder', props.folder.id);

View File

@ -26,6 +26,7 @@ import { i18n } from '@/i18n.js';
const props = defineProps<{ const props = defineProps<{
folder?: Misskey.entities.DriveFolder; folder?: Misskey.entities.DriveFolder;
parentFolder: Misskey.entities.DriveFolder | null; parentFolder: Misskey.entities.DriveFolder | null;
selectedFiles: string[];
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
@ -112,11 +113,20 @@ function onDrop(ev: DragEvent) {
if (driveFile != null && driveFile !== '') { if (driveFile != null && driveFile !== '') {
const file = JSON.parse(driveFile); const file = JSON.parse(driveFile);
emit('removeFile', file.id); emit('removeFile', file.id);
if (props.selectedFiles.length > 0) {
props.selectedFiles.forEach((e) => {
os.api('drive/files/update', {
fileId: e.id,
folderId: props.folder ? props.folder.id : null,
});
});
} else {
os.api('drive/files/update', { os.api('drive/files/update', {
fileId: file.id, fileId: file.id,
folderId: props.folder ? props.folder.id : null, folderId: props.folder ? props.folder.id : null,
}); });
} }
}
//#endregion //#endregion
//#region //#region

View File

@ -10,6 +10,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<XNavFolder <XNavFolder
:class="[$style.navPathItem, { [$style.navCurrent]: folder == null }]" :class="[$style.navPathItem, { [$style.navCurrent]: folder == null }]"
:parentFolder="folder" :parentFolder="folder"
:selectedFiles="selectedFiles"
@move="move" @move="move"
@upload="upload" @upload="upload"
@removeFile="removeFile" @removeFile="removeFile"
@ -27,10 +28,23 @@ SPDX-License-Identifier: AGPL-3.0-only
@removeFolder="removeFolder" @removeFolder="removeFolder"
/> />
</template> </template>
<span v-if="folder != null" :class="[$style.navPathItem, $style.navSeparator]"><i class="ti ti-chevron-right"></i></span> <span v-if="folder != null" :class="[$style.navPathItem, $style.navSeparator]"><i
class="ti ti-chevron-right"
></i></span>
<span v-if="folder != null" :class="[$style.navPathItem, $style.navCurrent]">{{ folder.name }}</span> <span v-if="folder != null" :class="[$style.navPathItem, $style.navCurrent]">{{ folder.name }}</span>
</div> </div>
<button class="_button" :class="$style.navMenu" @click="showMenu"><i class="ti ti-dots"></i></button> <button v-if="!multiple" class="_button" :class="$style.navMenu" @click="filesSelect">複数選択モード</button>
<span v-if="multiple && selectedFiles.length > 0" style="padding-right: 12px; margin-top: auto; margin-bottom: auto;opacity: 0.5;">
({{ number(selectedFiles.length) }})
</span>
<button v-if="multiple" class="_button" :class="$style.navMenu" @click="filesSelect">複数選択モード解除</button>
<button v-if="multiple && selectedFiles.length === 0" style="padding-right: 12px;" class="_button" @click="filesAllSelect">
全選択
</button>
<button v-if="multiple && selectedFiles.length !== 0" style="padding-right: 12px;" class="_button" @click="filesAllSelect">
全選択解除
</button>
<button class="_button" @click="showMenu"><i class="ti ti-dots"></i></button>
</nav> </nav>
<div <div
ref="main" ref="main"
@ -51,6 +65,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:folder="f" :folder="f"
:selectMode="select === 'folder'" :selectMode="select === 'folder'"
:isSelected="selectedFolders.some(x => x.id === f.id)" :isSelected="selectedFolders.some(x => x.id === f.id)"
:selectedFiles="selectedFiles"
@chosen="chooseFolder" @chosen="chooseFolder"
@move="move" @move="move"
@upload="upload" @upload="upload"
@ -73,6 +88,7 @@ SPDX-License-Identifier: AGPL-3.0-only
:folder="folder" :folder="folder"
:selectMode="select === 'file'" :selectMode="select === 'file'"
:isSelected="selectedFiles.some(x => x.id === file.id)" :isSelected="selectedFiles.some(x => x.id === file.id)"
@click.shift.left.exact="filesSelect"
@chosen="chooseFile" @chosen="chooseFile"
@dragstart="isDragSource = true" @dragstart="isDragSource = true"
@dragend="isDragSource = false" @dragend="isDragSource = false"
@ -83,14 +99,21 @@ SPDX-License-Identifier: AGPL-3.0-only
</div> </div>
<div v-if="files.length == 0 && folders.length == 0 && !fetching" :class="$style.empty"> <div v-if="files.length == 0 && folders.length == 0 && !fetching" :class="$style.empty">
<div v-if="draghover">{{ i18n.t('empty-draghover') }}</div> <div v-if="draghover">{{ i18n.t('empty-draghover') }}</div>
<div v-if="!draghover && folder == null"><strong>{{ i18n.ts.emptyDrive }}</strong><br/>{{ i18n.t('empty-drive-description') }}</div> <div v-if="!draghover && folder == null">
<strong>{{
i18n.ts.emptyDrive
}}</strong><br/>{{ i18n.t('empty-drive-description') }}
</div>
<div v-if="!draghover && folder != null">{{ i18n.ts.emptyFolder }}</div> <div v-if="!draghover && folder != null">{{ i18n.ts.emptyFolder }}</div>
</div> </div>
</div> </div>
<MkLoading v-if="fetching"/> <MkLoading v-if="fetching"/>
</div> </div>
<div v-if="draghover" :class="$style.dropzone"></div> <div v-if="draghover" :class="$style.dropzone"></div>
<input ref="fileInput" style="display: none;" type="file" accept="*/*" multiple tabindex="-1" @change="onChangeFileInput"/> <input
ref="fileInput" style="display: none;" type="file" accept="*/*" multiple tabindex="-1"
@change="onChangeFileInput"
/>
</div> </div>
</template> </template>
@ -107,6 +130,7 @@ import { defaultStore } from '@/store.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { uploadFile, uploads } from '@/scripts/upload.js'; import { uploadFile, uploads } from '@/scripts/upload.js';
import { claimAchievement } from '@/scripts/achievements.js'; import { claimAchievement } from '@/scripts/achievements.js';
import number from "@/filters/number.js";
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
initialFolder?: Misskey.entities.DriveFolder; initialFolder?: Misskey.entities.DriveFolder;
@ -140,6 +164,8 @@ const selectedFolders = ref<Misskey.entities.DriveFolder[]>([]);
const uploadings = uploads; const uploadings = uploads;
const connection = useStream().useChannel('drive'); const connection = useStream().useChannel('drive');
const keepOriginal = ref<boolean>(defaultStore.state.keepOriginalUploading); // $ref使 const keepOriginal = ref<boolean>(defaultStore.state.keepOriginalUploading); // $ref使
const multiple = ref(props.multiple || false);
const select = ref(props.select || null);
// //
const draghover = ref(false); const draghover = ref(false);
@ -390,7 +416,7 @@ function upload(file: File, folderToUpload?: Misskey.entities.DriveFolder | null
function chooseFile(file: Misskey.entities.DriveFile) { function chooseFile(file: Misskey.entities.DriveFile) {
const isAlreadySelected = selectedFiles.value.some(f => f.id === file.id); const isAlreadySelected = selectedFiles.value.some(f => f.id === file.id);
if (props.multiple) { if (multiple.value) {
if (isAlreadySelected) { if (isAlreadySelected) {
selectedFiles.value = selectedFiles.value.filter(f => f.id !== file.id); selectedFiles.value = selectedFiles.value.filter(f => f.id !== file.id);
} else { } else {
@ -409,7 +435,7 @@ function chooseFile(file: Misskey.entities.DriveFile) {
function chooseFolder(folderToChoose: Misskey.entities.DriveFolder) { function chooseFolder(folderToChoose: Misskey.entities.DriveFolder) {
const isAlreadySelected = selectedFolders.value.some(f => f.id === folderToChoose.id); const isAlreadySelected = selectedFolders.value.some(f => f.id === folderToChoose.id);
if (props.multiple) { if (multiple.value) {
if (isAlreadySelected) { if (isAlreadySelected) {
selectedFolders.value = selectedFolders.value.filter(f => f.id !== folderToChoose.id); selectedFolders.value = selectedFolders.value.filter(f => f.id !== folderToChoose.id);
} else { } else {
@ -496,6 +522,7 @@ function removeFolder(folderToRemove: Misskey.entities.DriveFolder | string) {
function removeFile(file: Misskey.entities.DriveFile | string) { function removeFile(file: Misskey.entities.DriveFile | string) {
const fileId = typeof file === 'object' ? file.id : file; const fileId = typeof file === 'object' ? file.id : file;
files.value = files.value.filter(f => f.id !== fileId); files.value = files.value.filter(f => f.id !== fileId);
selectedFiles.value = selectedFiles.value.filter(f => f.id !== fileId);
} }
function appendFile(file: Misskey.entities.DriveFile) { function appendFile(file: Misskey.entities.DriveFile) {
@ -505,6 +532,7 @@ function appendFile(file: Misskey.entities.DriveFile) {
function appendFolder(folderToAppend: Misskey.entities.DriveFolder) { function appendFolder(folderToAppend: Misskey.entities.DriveFolder) {
addFolder(folderToAppend); addFolder(folderToAppend);
} }
/* /*
function prependFile(file: Misskey.entities.DriveFile) { function prependFile(file: Misskey.entities.DriveFile) {
addFile(file, true); addFile(file, true);
@ -621,31 +649,128 @@ function getMenu() {
}, { }, {
text: i18n.ts.upload, text: i18n.ts.upload,
icon: 'ti ti-upload', icon: 'ti ti-upload',
action: () => { selectLocalFile(); }, action: () => {
selectLocalFile();
},
}, { }, {
text: i18n.ts.fromUrl, text: i18n.ts.fromUrl,
icon: 'ti ti-link', icon: 'ti ti-link',
action: () => { urlUpload(); }, action: () => {
urlUpload();
},
}, null, { }, null, {
text: folder.value ? folder.value.name : i18n.ts.drive, text: folder.value ? folder.value.name : i18n.ts.drive,
type: 'label', type: 'label',
}, folder.value ? { }, folder.value ? {
text: i18n.ts.renameFolder, text: i18n.ts.renameFolder,
icon: 'ti ti-forms', icon: 'ti ti-forms',
action: () => { renameFolder(folder.value); }, action: () => {
renameFolder(folder.value);
},
} : undefined, folder.value ? { } : undefined, folder.value ? {
text: i18n.ts.deleteFolder, text: i18n.ts.deleteFolder,
icon: 'ti ti-trash', icon: 'ti ti-trash',
action: () => { deleteFolder(folder.value as Misskey.entities.DriveFolder); }, action: () => {
deleteFolder(folder.value as Misskey.entities.DriveFolder);
},
} : undefined, { } : undefined, {
text: i18n.ts.createFolder, text: i18n.ts.createFolder,
icon: 'ti ti-folder-plus', icon: 'ti ti-folder-plus',
action: () => { createFolder(); }, action: () => {
createFolder();
},
}]; }];
} }
async function isSensitive(Files, isSensitive: boolean) {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t(isSensitive ? 'driveFilesSensitiveonConfirm' : 'driveFilesSensitiveoffConfirm', { name: Files.length }),
});
if (canceled) return;
Files.forEach((file) => {
os.api('drive/files/update', {
fileId: file.id,
isSensitive,
});
});
}
async function fileDelete(Files) {
const { canceled } = await os.confirm({
type: 'warning',
text: i18n.t('driveFilesDeleteConfirm', { name: Files.length }),
});
if (canceled) return;
Files.forEach((file) => {
os.api('drive/files/delete', {
fileId: file.id,
});
});
}
function getFilesMenu(Files) {
return [{
text: i18n.ts.createNoteFromTheFile,
icon: 'ti ti-pencil',
action: () => {
if (Files.length >= 16) {
os.confirm({
type: 'warning',
text: '16ファイル以上添付しようとしています',
});
return;
} else {
os.post({
initialFiles: [...Files],
});
}
},
}, {
text: i18n.ts.unmarkAsSensitive,
icon: 'ti ti-eye',
action: () => {
isSensitive(Files, false);
},
}, {
text: i18n.ts.markAsSensitive,
icon: 'ti ti-eye-exclamation',
action: () => {
isSensitive(Files, true);
},
}, {
text: i18n.ts.delete,
icon: 'ti ti-trash',
danger: true,
action: () => {
fileDelete(Files);
},
}];
}
function filesSelect() {
multiple.value = !multiple.value;
select.value = (select.value === null) ? 'file' : null;
selectedFiles.value = [];
}
function filesAllSelect() {
if (selectedFiles.value.length === 0) {
selectedFiles.value = files.value;
} else {
selectedFiles.value = [];
}
}
function showMenu(ev: MouseEvent) { function showMenu(ev: MouseEvent) {
console.log(selectedFiles.value.length);
if (selectedFiles.value.length === 0) {
os.popupMenu(getMenu(), (ev.currentTarget ?? ev.target ?? undefined) as HTMLElement | undefined); os.popupMenu(getMenu(), (ev.currentTarget ?? ev.target ?? undefined) as HTMLElement | undefined);
} else {
os.popupMenu(getFilesMenu(selectedFiles.value), (ev.currentTarget ?? ev.target ?? undefined) as HTMLElement | undefined);
}
} }
function onContextmenu(ev: MouseEvent) { function onContextmenu(ev: MouseEvent) {
@ -696,7 +821,10 @@ onBeforeUnmount(() => {
.nav { .nav {
display: flex; display: flex;
z-index: 2; top: 0;
position: sticky;
z-index: 1000;
background-color: var(--bg);
width: 100%; width: 100%;
padding: 0 8px; padding: 0 8px;
box-sizing: border-box; box-sizing: border-box;