2023-03-20 13:20:21 +09:00
|
|
|
import * as Misskey from 'misskey-js';
|
|
|
|
import { defineAsyncComponent } from 'vue';
|
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
|
|
|
import * as os from '@/os';
|
2023-07-05 13:54:40 +09:00
|
|
|
import { MenuItem } from '@/types/menu';
|
2023-07-08 18:45:41 +09:00
|
|
|
import { defaultStore } from '@/store';
|
2023-03-20 13:20:21 +09: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;
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: file.id,
|
|
|
|
name: name,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function describe(file: Misskey.entities.DriveFile) {
|
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkFileCaptionEditWindow.vue')), {
|
|
|
|
default: file.comment != null ? file.comment : '',
|
|
|
|
file: file,
|
|
|
|
}, {
|
|
|
|
done: caption => {
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: file.id,
|
|
|
|
comment: caption.length === 0 ? null : caption,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, 'closed');
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSensitive(file: Misskey.entities.DriveFile) {
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: file.id,
|
|
|
|
isSensitive: !file.isSensitive,
|
2023-05-05 14:18:06 +09:00
|
|
|
}).catch(err => {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
|
|
|
title: i18n.ts.error,
|
|
|
|
text: err.message,
|
|
|
|
});
|
2023-03-20 13:20:21 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyUrl(file: Misskey.entities.DriveFile) {
|
|
|
|
copyToClipboard(file.url);
|
|
|
|
os.success();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
function addApp() {
|
|
|
|
alert('not implemented yet');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
async function deleteFile(file: Misskey.entities.DriveFile) {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('driveFileDeleteConfirm', { name: file.name }),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (canceled) return;
|
|
|
|
os.api('drive/files/delete', {
|
|
|
|
fileId: file.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-05 13:54:40 +09:00
|
|
|
export function getDriveFileMenu(file: Misskey.entities.DriveFile, folder?: Misskey.entities.DriveFolder | null): MenuItem[] {
|
|
|
|
const isImage = file.type.startsWith('image/');
|
2023-07-08 18:45:41 +09:00
|
|
|
let menu;
|
|
|
|
menu = [{
|
2023-03-20 13:20:21 +09:00
|
|
|
text: i18n.ts.rename,
|
|
|
|
icon: 'ti ti-forms',
|
2023-03-22 18:29:17 +09:00
|
|
|
action: () => rename(file),
|
2023-03-20 13:20:21 +09:00
|
|
|
}, {
|
|
|
|
text: file.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive,
|
2023-05-30 14:34:55 +09:00
|
|
|
icon: file.isSensitive ? 'ti ti-eye' : 'ti ti-eye-exclamation',
|
2023-03-22 18:29:17 +09:00
|
|
|
action: () => toggleSensitive(file),
|
2023-03-20 13:20:21 +09:00
|
|
|
}, {
|
|
|
|
text: i18n.ts.describeFile,
|
|
|
|
icon: 'ti ti-text-caption',
|
2023-03-22 18:29:17 +09:00
|
|
|
action: () => describe(file),
|
2023-07-05 13:54:40 +09:00
|
|
|
}, ...isImage ? [{
|
|
|
|
text: i18n.ts.cropImage,
|
|
|
|
icon: 'ti ti-crop',
|
|
|
|
action: () => os.cropImage(file, {
|
|
|
|
aspectRatio: NaN,
|
|
|
|
uploadFolder: folder ? folder.id : folder
|
|
|
|
}),
|
|
|
|
}] : [], null, {
|
2023-05-04 19:58:17 +09:00
|
|
|
text: i18n.ts.createNoteFromTheFile,
|
|
|
|
icon: 'ti ti-pencil',
|
|
|
|
action: () => os.post({
|
|
|
|
initialFiles: [file],
|
|
|
|
}),
|
|
|
|
}, {
|
2023-03-20 13:20:21 +09:00
|
|
|
text: i18n.ts.copyUrl,
|
|
|
|
icon: 'ti ti-link',
|
2023-03-22 18:29:17 +09:00
|
|
|
action: () => copyUrl(file),
|
2023-03-20 13:20:21 +09:00
|
|
|
}, {
|
|
|
|
type: 'a',
|
|
|
|
href: file.url,
|
|
|
|
target: '_blank',
|
|
|
|
text: i18n.ts.download,
|
|
|
|
icon: 'ti ti-download',
|
|
|
|
download: file.name,
|
|
|
|
}, null, {
|
|
|
|
text: i18n.ts.delete,
|
|
|
|
icon: 'ti ti-trash',
|
|
|
|
danger: true,
|
2023-03-22 18:29:17 +09:00
|
|
|
action: () => deleteFile(file),
|
2023-03-20 13:20:21 +09:00
|
|
|
}];
|
2023-07-08 18:45:41 +09:00
|
|
|
|
|
|
|
if (defaultStore.state.devMode) {
|
|
|
|
menu = menu.concat([null, {
|
|
|
|
icon: 'ti ti-id',
|
|
|
|
text: i18n.ts.copyFileId,
|
|
|
|
action: () => {
|
|
|
|
copyToClipboard(file.id);
|
|
|
|
},
|
|
|
|
}]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return menu;
|
2023-03-20 13:20:21 +09:00
|
|
|
}
|