2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-08-31 00:24:33 +09:00
|
|
|
<div
|
|
|
|
class="ncvczrfv"
|
2020-10-17 20:12:00 +09:00
|
|
|
:class="{ isSelected }"
|
2021-11-19 19:36:12 +09:00
|
|
|
draggable="true"
|
|
|
|
:title="title"
|
2020-01-30 04:37:25 +09:00
|
|
|
@click="onClick"
|
2020-10-17 20:12:00 +09:00
|
|
|
@contextmenu.stop="onContextmenu"
|
2020-01-30 04:37:25 +09:00
|
|
|
@dragstart="onDragstart"
|
|
|
|
@dragend="onDragend"
|
|
|
|
>
|
2022-01-18 23:06:16 +09:00
|
|
|
<div v-if="$i?.avatarId == file.id" class="label">
|
2021-11-12 02:02:25 +09:00
|
|
|
<img src="/client-assets/label.svg"/>
|
2022-01-28 11:39:49 +09:00
|
|
|
<p>{{ i18n.ts.avatar }}</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2022-01-18 23:06:16 +09:00
|
|
|
<div v-if="$i?.bannerId == file.id" class="label">
|
2021-11-12 02:02:25 +09:00
|
|
|
<img src="/client-assets/label.svg"/>
|
2022-01-28 11:39:49 +09:00
|
|
|
<p>{{ i18n.ts.banner }}</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
2021-11-19 19:36:12 +09:00
|
|
|
<div v-if="file.isSensitive" class="label red">
|
2021-11-12 02:02:25 +09:00
|
|
|
<img src="/client-assets/label-red.svg"/>
|
2022-01-28 11:39:49 +09:00
|
|
|
<p>{{ i18n.ts.nsfw }}</p>
|
2020-01-30 04:37:25 +09:00
|
|
|
</div>
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
<MkDriveFileThumbnail class="thumbnail" :file="file" fit="contain"/>
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
<p class="name">
|
|
|
|
<span>{{ file.name.lastIndexOf('.') != -1 ? file.name.substr(0, file.name.lastIndexOf('.')) : file.name }}</span>
|
2021-11-19 19:36:12 +09:00
|
|
|
<span v-if="file.name.lastIndexOf('.') != -1" class="ext">{{ file.name.substr(file.name.lastIndexOf('.')) }}</span>
|
2020-01-30 04:37:25 +09:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
<script lang="ts" setup>
|
2022-05-01 22:51:07 +09:00
|
|
|
import { computed, defineAsyncComponent, ref } from 'vue';
|
2022-01-18 23:06:16 +09:00
|
|
|
import * as Misskey from 'misskey-js';
|
2021-11-12 02:02:25 +09:00
|
|
|
import copyToClipboard from '@/scripts/copy-to-clipboard';
|
2022-08-31 00:24:33 +09:00
|
|
|
import MkDriveFileThumbnail from '@/components/MkDriveFileThumbnail.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import bytes from '@/filters/bytes';
|
|
|
|
import * as os from '@/os';
|
2022-01-18 23:06:16 +09:00
|
|
|
import { i18n } from '@/i18n';
|
|
|
|
import { $i } from '@/account';
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
file: Misskey.entities.DriveFile;
|
|
|
|
isSelected?: boolean;
|
|
|
|
selectMode?: boolean;
|
|
|
|
}>(), {
|
|
|
|
isSelected: false,
|
|
|
|
selectMode: false,
|
|
|
|
});
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-01-18 23:06:16 +09:00
|
|
|
const emit = defineEmits<{
|
2022-05-05 20:45:50 +09:00
|
|
|
(ev: 'chosen', r: Misskey.entities.DriveFile): void;
|
|
|
|
(ev: 'dragstart'): void;
|
|
|
|
(ev: 'dragend'): void;
|
2022-01-18 23:06:16 +09:00
|
|
|
}>();
|
|
|
|
|
|
|
|
const isDragging = ref(false);
|
|
|
|
|
|
|
|
const title = computed(() => `${props.file.name}\n${props.file.type} ${bytes(props.file.size)}`);
|
|
|
|
|
|
|
|
function getMenu() {
|
|
|
|
return [{
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.rename,
|
2022-01-18 23:06:16 +09:00
|
|
|
icon: 'fas fa-i-cursor',
|
2022-08-31 00:24:33 +09:00
|
|
|
action: rename,
|
2022-01-18 23:06:16 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: props.file.isSensitive ? i18n.ts.unmarkAsSensitive : i18n.ts.markAsSensitive,
|
2022-01-18 23:06:16 +09:00
|
|
|
icon: props.file.isSensitive ? 'fas fa-eye' : 'fas fa-eye-slash',
|
2022-08-31 00:24:33 +09:00
|
|
|
action: toggleSensitive,
|
2022-01-18 23:06:16 +09:00
|
|
|
}, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.describeFile,
|
2022-01-18 23:06:16 +09:00
|
|
|
icon: 'fas fa-i-cursor',
|
2022-08-31 00:24:33 +09:00
|
|
|
action: describe,
|
2022-01-18 23:06:16 +09:00
|
|
|
}, null, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.copyUrl,
|
2022-01-18 23:06:16 +09:00
|
|
|
icon: 'fas fa-link',
|
2022-08-31 00:24:33 +09:00
|
|
|
action: copyUrl,
|
2022-01-18 23:06:16 +09:00
|
|
|
}, {
|
|
|
|
type: 'a',
|
|
|
|
href: props.file.url,
|
|
|
|
target: '_blank',
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.download,
|
2022-01-18 23:06:16 +09:00
|
|
|
icon: 'fas fa-download',
|
2022-08-31 00:24:33 +09:00
|
|
|
download: props.file.name,
|
2022-01-18 23:06:16 +09:00
|
|
|
}, null, {
|
2022-01-28 11:39:49 +09:00
|
|
|
text: i18n.ts.delete,
|
2022-01-18 23:06:16 +09:00
|
|
|
icon: 'fas fa-trash-alt',
|
|
|
|
danger: true,
|
2022-08-31 00:24:33 +09:00
|
|
|
action: deleteFile,
|
2022-01-18 23:06:16 +09:00
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
function onClick(ev: MouseEvent) {
|
|
|
|
if (props.selectMode) {
|
|
|
|
emit('chosen', props.file);
|
|
|
|
} else {
|
2022-01-28 12:20:42 +09:00
|
|
|
os.popupMenu(getMenu(), (ev.currentTarget ?? ev.target ?? undefined) as HTMLElement | undefined);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-05-05 20:45:50 +09:00
|
|
|
function onContextmenu(ev: MouseEvent) {
|
|
|
|
os.contextMenu(getMenu(), ev);
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2022-05-05 20:45:50 +09:00
|
|
|
function onDragstart(ev: DragEvent) {
|
|
|
|
if (ev.dataTransfer) {
|
|
|
|
ev.dataTransfer.effectAllowed = 'move';
|
|
|
|
ev.dataTransfer.setData(_DATA_TRANSFER_DRIVE_FILE_, JSON.stringify(props.file));
|
2022-01-18 23:06:16 +09:00
|
|
|
}
|
|
|
|
isDragging.value = true;
|
|
|
|
|
|
|
|
emit('dragstart');
|
|
|
|
}
|
|
|
|
|
|
|
|
function onDragend() {
|
|
|
|
isDragging.value = false;
|
|
|
|
emit('dragend');
|
|
|
|
}
|
|
|
|
|
|
|
|
function rename() {
|
|
|
|
os.inputText({
|
2022-01-28 11:39:49 +09:00
|
|
|
title: i18n.ts.renameFile,
|
|
|
|
placeholder: i18n.ts.inputNewFileName,
|
2022-01-18 23:06:16 +09:00
|
|
|
default: props.file.name,
|
|
|
|
}).then(({ canceled, result: name }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: props.file.id,
|
2022-08-31 00:24:33 +09:00
|
|
|
name: name,
|
2022-01-18 23:06:16 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function describe() {
|
2022-08-31 00:24:33 +09:00
|
|
|
os.popup(defineAsyncComponent(() => import('@/components/MkMediaCaption.vue')), {
|
2022-01-28 11:39:49 +09:00
|
|
|
title: i18n.ts.describeFile,
|
2022-01-18 23:06:16 +09:00
|
|
|
input: {
|
2022-01-28 11:39:49 +09:00
|
|
|
placeholder: i18n.ts.inputNewDescription,
|
2022-05-05 20:45:50 +09:00
|
|
|
default: props.file.comment != null ? props.file.comment : '',
|
2021-05-28 09:38:09 +09:00
|
|
|
},
|
2022-08-31 00:24:33 +09:00
|
|
|
image: props.file,
|
2022-01-18 23:06:16 +09:00
|
|
|
}, {
|
|
|
|
done: result => {
|
|
|
|
if (!result || result.canceled) return;
|
|
|
|
let comment = result.result;
|
2020-10-17 20:12:00 +09:00
|
|
|
os.api('drive/files/update', {
|
2022-01-18 23:06:16 +09:00
|
|
|
fileId: props.file.id,
|
2022-08-31 00:24:33 +09:00
|
|
|
comment: comment.length === 0 ? null : comment,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2022-08-31 00:24:33 +09:00
|
|
|
},
|
2022-01-18 23:06:16 +09:00
|
|
|
}, 'closed');
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSensitive() {
|
|
|
|
os.api('drive/files/update', {
|
|
|
|
fileId: props.file.id,
|
2022-08-31 00:24:33 +09:00
|
|
|
isSensitive: !props.file.isSensitive,
|
2022-01-18 23:06:16 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function copyUrl() {
|
|
|
|
copyToClipboard(props.file.url);
|
|
|
|
os.success();
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
function addApp() {
|
|
|
|
alert('not implemented yet');
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
async function deleteFile() {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('driveFileDeleteConfirm', { name: props.file.name }),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (canceled) return;
|
|
|
|
os.api('drive/files/delete', {
|
2022-08-31 00:24:33 +09:00
|
|
|
fileId: props.file.id,
|
2022-01-18 23:06:16 +09:00
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.ncvczrfv {
|
|
|
|
position: relative;
|
|
|
|
padding: 8px 0 0 0;
|
|
|
|
min-height: 180px;
|
2021-12-10 10:46:29 +09:00
|
|
|
border-radius: 8px;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
&, * {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
> * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
|
|
|
|
2020-01-30 04:37:25 +09:00
|
|
|
&:hover {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b65a5;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: rgba(#000, 0.1);
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #0b588c;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #ce2212;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 20:12:00 +09:00
|
|
|
&.isSelected {
|
2020-01-30 04:37:25 +09:00
|
|
|
background: var(--accent);
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--accentLighten);
|
|
|
|
}
|
|
|
|
|
|
|
|
&:active {
|
|
|
|
background: var(--accentDarken);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .label {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
pointer-events: none;
|
|
|
|
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
content: "";
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 1;
|
|
|
|
background: #0c7ac9;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:before {
|
|
|
|
top: 0;
|
|
|
|
left: 57px;
|
|
|
|
width: 28px;
|
|
|
|
height: 8px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&:after {
|
|
|
|
top: 57px;
|
|
|
|
left: 0;
|
|
|
|
width: 8px;
|
|
|
|
height: 28px;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
&:before,
|
|
|
|
&:after {
|
|
|
|
background: #c12113;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> img {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 2;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
> p {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 3;
|
|
|
|
top: 19px;
|
|
|
|
left: -28px;
|
|
|
|
width: 120px;
|
|
|
|
margin: 0;
|
|
|
|
text-align: center;
|
|
|
|
line-height: 28px;
|
|
|
|
color: #fff;
|
|
|
|
transform: rotate(-45deg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .thumbnail {
|
2021-04-10 12:40:50 +09:00
|
|
|
width: 110px;
|
|
|
|
height: 110px;
|
2020-01-30 04:37:25 +09:00
|
|
|
margin: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
margin: 4px 0 0 0;
|
|
|
|
font-size: 0.8em;
|
|
|
|
text-align: center;
|
|
|
|
word-break: break-all;
|
|
|
|
color: var(--fg);
|
2021-03-02 22:57:16 +09:00
|
|
|
overflow: hidden;
|
2020-01-30 04:37:25 +09:00
|
|
|
|
|
|
|
> .ext {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|