2023-07-27 07:31:52 +02:00
|
|
|
/*
|
2024-02-12 03:37:45 +01:00
|
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 07:31:52 +02:00
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
import { defineAsyncComponent } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard.js';
|
|
|
|
import * as os from '@/os.js';
|
2024-01-04 10:32:46 +01:00
|
|
|
import { misskeyApi } from '@/scripts/misskey-api.js';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { MenuItem } from '@/types/menu.js';
|
|
|
|
import { defaultStore } from '@/store.js';
|
2023-03-20 05:20:21 +01:00
|
|
|
|
|
|
|
function rename(file: Misskey.entities.DriveFile) {
|
|
|
|
os.inputText({
|
|
|
|
title: i18n.ts.renameFile,
|
|
|
|
placeholder: i18n.ts.inputNewFileName,
|
|
|
|
default: file.name,
|
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/files/update', {
|
2023-03-20 05:20:21 +01:00
|
|
|
fileId: file.id,
|
|
|
|
name: name,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function describe(file: Misskey.entities.DriveFile) {
|
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkFileCaptionEditWindow.vue')), {
|
2023-10-10 03:43:43 +02:00
|
|
|
default: file.comment ?? '',
|
2023-03-20 05:20:21 +01:00
|
|
|
file: file,
|
|
|
|
}, {
|
|
|
|
done: caption => {
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/files/update', {
|
2023-03-20 05:20:21 +01:00
|
|
|
fileId: file.id,
|
|
|
|
comment: caption.length === 0 ? null : caption,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, 'closed');
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSensitive(file: Misskey.entities.DriveFile) {
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/files/update', {
|
2023-03-20 05:20:21 +01:00
|
|
|
fileId: file.id,
|
|
|
|
isSensitive: !file.isSensitive,
|
2023-05-05 07:18:06 +02:00
|
|
|
}).catch(err => {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.error,
|
|
|
|
text: err.message,
|
|
|
|
});
|
2023-03-20 05:20:21 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyUrl(file: Misskey.entities.DriveFile) {
|
|
|
|
copyToClipboard(file.url);
|
|
|
|
os.success();
|
|
|
|
}
|
2023-10-29 08:09:20 +01:00
|
|
|
|
2023-03-20 05:20:21 +01:00
|
|
|
/*
|
|
|
|
function addApp() {
|
|
|
|
alert('not implemented yet');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
async function deleteFile(file: Misskey.entities.DriveFile) {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2024-01-20 00:11:59 +01:00
|
|
|
text: i18n.tsx.driveFileDeleteConfirm({ name: file.name }),
|
2023-03-20 05:20:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
if (canceled) return;
|
2024-01-04 10:32:46 +01:00
|
|
|
misskeyApi('drive/files/delete', {
|
2023-03-20 05:20:21 +01:00
|
|
|
fileId: file.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-05 06:54:40 +02:00
|
|
|
export function getDriveFileMenu(file: Misskey.entities.DriveFile, folder?: Misskey.entities.DriveFolder | null): MenuItem[] {
|
|
|
|
const isImage = file.type.startsWith('image/');
|
2023-07-08 11:45:41 +02:00
|
|
|
let menu;
|
|
|
|
menu = [{
|
2023-11-03 00:01:22 +01:00
|
|
|
type: 'link',
|
|
|
|
to: `/my/drive/file/${file.id}`,
|
|
|
|
text: i18n.ts._fileViewer.title,
|
|
|
|
icon: 'ti ti-info-circle',
|
2023-12-12 02:26:37 +01:00
|
|
|
}, { type: 'divider' }, {
|
2023-03-20 05:20:21 +01:00
|
|
|
text: i18n.ts.rename,
|
|
|
|
icon: 'ti ti-forms',
|
2023-03-22 10:29:17 +01:00
|
|
|
action: () => rename(file),
|
2023-03-20 05:20:21 +01:00
|
|
|
}, {
|
|
|
|
text: file.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive,
|
2023-05-30 07:34:55 +02:00
|
|
|
icon: file.isSensitive ? 'ti ti-eye' : 'ti ti-eye-exclamation',
|
2023-03-22 10:29:17 +01:00
|
|
|
action: () => toggleSensitive(file),
|
2023-03-20 05:20:21 +01:00
|
|
|
}, {
|
|
|
|
text: i18n.ts.describeFile,
|
|
|
|
icon: 'ti ti-text-caption',
|
2023-03-22 10:29:17 +01:00
|
|
|
action: () => describe(file),
|
2023-07-05 06:54:40 +02:00
|
|
|
}, ...isImage ? [{
|
|
|
|
text: i18n.ts.cropImage,
|
|
|
|
icon: 'ti ti-crop',
|
|
|
|
action: () => os.cropImage(file, {
|
|
|
|
aspectRatio: NaN,
|
2023-07-27 07:31:52 +02:00
|
|
|
uploadFolder: folder ? folder.id : folder,
|
2023-07-05 06:54:40 +02:00
|
|
|
}),
|
2023-12-12 02:26:37 +01:00
|
|
|
}] : [], { type: 'divider' }, {
|
2023-05-04 12:58:17 +02:00
|
|
|
text: i18n.ts.createNoteFromTheFile,
|
|
|
|
icon: 'ti ti-pencil',
|
|
|
|
action: () => os.post({
|
|
|
|
initialFiles: [file],
|
|
|
|
}),
|
|
|
|
}, {
|
2023-03-20 05:20:21 +01:00
|
|
|
text: i18n.ts.copyUrl,
|
|
|
|
icon: 'ti ti-link',
|
2023-03-22 10:29:17 +01:00
|
|
|
action: () => copyUrl(file),
|
2023-03-20 05:20:21 +01:00
|
|
|
}, {
|
|
|
|
type: 'a',
|
|
|
|
href: file.url,
|
|
|
|
target: '_blank',
|
|
|
|
text: i18n.ts.download,
|
|
|
|
icon: 'ti ti-download',
|
|
|
|
download: file.name,
|
2023-12-12 02:26:37 +01:00
|
|
|
}, { type: 'divider' }, {
|
2023-03-20 05:20:21 +01:00
|
|
|
text: i18n.ts.delete,
|
|
|
|
icon: 'ti ti-trash',
|
|
|
|
danger: true,
|
2023-03-22 10:29:17 +01:00
|
|
|
action: () => deleteFile(file),
|
2023-03-20 05:20:21 +01:00
|
|
|
}];
|
2023-07-08 11:45:41 +02:00
|
|
|
|
|
|
|
if (defaultStore.state.devMode) {
|
2023-12-12 02:26:37 +01:00
|
|
|
menu = menu.concat([{ type: 'divider' }, {
|
2023-07-08 11:45:41 +02:00
|
|
|
icon: 'ti ti-id',
|
|
|
|
text: i18n.ts.copyFileId,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(file.id);
|
|
|
|
},
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
2023-03-20 05:20:21 +01:00
|
|
|
}
|