summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-12-15 00:09:04 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-12-15 00:09:04 +0900
commitebceffba1eb3d762fe164a10ee58fc78547a0a27 (patch)
tree8000bbb47469f637578ad59677a6d19b037fb846 /src
parent:art: (diff)
downloadsharkey-ebceffba1eb3d762fe164a10ee58fc78547a0a27.tar.gz
sharkey-ebceffba1eb3d762fe164a10ee58fc78547a0a27.tar.bz2
sharkey-ebceffba1eb3d762fe164a10ee58fc78547a0a27.zip
Resolve #2165
Diffstat (limited to 'src')
-rw-r--r--src/client/app/admin/views/drive.vue87
-rw-r--r--src/server/api/endpoints/admin/drive/files.ts10
-rw-r--r--src/server/api/endpoints/drive/files/delete.ts7
3 files changed, 69 insertions, 35 deletions
diff --git a/src/client/app/admin/views/drive.vue b/src/client/app/admin/views/drive.vue
index 2888b0be9f..2872155b60 100644
--- a/src/client/app/admin/views/drive.vue
+++ b/src/client/app/admin/views/drive.vue
@@ -19,22 +19,27 @@
</ui-select>
</ui-horizon-group>
<div class="kidvdlkg" v-for="file in files">
- <div>
- <div class="thumbnail" :style="thumbnail(file)"></div>
- </div>
- <div>
- <header>
- <b>{{ file.name }}</b>
- <span class="username">@{{ file.user | acct }}</span>
- </header>
+ <div @click="file._open = !file._open">
+ <div>
+ <div class="thumbnail" :style="thumbnail(file)"></div>
+ </div>
<div>
+ <header>
+ <b>{{ file.name }}</b>
+ <span class="username">@{{ file.user | acct }}</span>
+ </header>
<div>
- <span style="margin-right:16px;">{{ file.type }}</span>
- <span>{{ file.datasize | bytes }}</span>
+ <div>
+ <span style="margin-right:16px;">{{ file.type }}</span>
+ <span>{{ file.datasize | bytes }}</span>
+ </div>
+ <div><mk-time :time="file.createdAt" mode="detail"/></div>
</div>
- <div><mk-time :time="file.createdAt" mode="detail"/></div>
</div>
</div>
+ <div v-show="file._open">
+ <ui-button @click="del(file)"><fa :icon="faTrashAlt"/> {{ $t('delete') }}</ui-button>
+ </div>
</div>
<ui-button v-if="existMore" @click="fetch">{{ $t('@.load-more') }}</ui-button>
</section>
@@ -46,6 +51,7 @@
import Vue from 'vue';
import i18n from '../../i18n';
import { faCloud } from '@fortawesome/free-solid-svg-icons';
+import { faTrashAlt } from '@fortawesome/free-regular-svg-icons';
export default Vue.extend({
i18n: i18n('admin/views/drive.vue'),
@@ -58,7 +64,7 @@ export default Vue.extend({
offset: 0,
files: [],
existMore: false,
- faCloud
+ faCloud, faTrashAlt
};
},
@@ -94,6 +100,9 @@ export default Vue.extend({
} else {
this.existMore = false;
}
+ for (const x of files) {
+ x._open = false;
+ }
this.files = this.files.concat(files);
this.offset += this.limit;
});
@@ -104,6 +113,23 @@ export default Vue.extend({
'background-color': file.properties.avgColor && file.properties.avgColor.length == 3 ? `rgb(${file.properties.avgColor.join(',')})` : 'transparent',
'background-image': `url(${file.thumbnailUrl})`
};
+ },
+
+ async del(file: any) {
+ const process = async () => {
+ await this.$root.api('drive/files/delete', { fileId: file.id });
+ this.$root.dialog({
+ type: 'success',
+ text: this.$t('deleted')
+ });
+ };
+
+ await process().catch(e => {
+ this.$root.dialog({
+ type: 'error',
+ text: e.toString()
+ });
+ });
}
}
});
@@ -115,30 +141,33 @@ export default Vue.extend({
padding 16px
.kidvdlkg
- display flex
padding 16px 0
border-top solid 1px var(--faceDivider)
> div:first-child
- > .thumbnail
- display block
- width 64px
- height 64px
- background-size cover
- background-position center center
+ display flex
+ cursor pointer
+
+ > div:nth-child(1)
+ > .thumbnail
+ display block
+ width 64px
+ height 64px
+ background-size cover
+ background-position center center
- > div:last-child
- flex 1
- padding-left 16px
+ > div:nth-child(2)
+ flex 1
+ padding-left 16px
- @media (max-width 500px)
- font-size 14px
+ @media (max-width 500px)
+ font-size 14px
- > header
- word-break break-word
+ > header
+ word-break break-word
- > .username
- margin-left 8px
- opacity 0.7
+ > .username
+ margin-left 8px
+ opacity 0.7
</style>
diff --git a/src/server/api/endpoints/admin/drive/files.ts b/src/server/api/endpoints/admin/drive/files.ts
index 2e54270a0f..6fc83f8191 100644
--- a/src/server/api/endpoints/admin/drive/files.ts
+++ b/src/server/api/endpoints/admin/drive/files.ts
@@ -63,10 +63,12 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => {
};
}
- const q =
- ps.origin == 'local' ? { host: null } :
- ps.origin == 'remote' ? { host: { $ne: null } } :
- {};
+ const q = {
+ 'metadata.deletedAt': { $exists: false },
+ } as any;
+
+ if (ps.origin == 'local') q['metadata._user.host'] = null;
+ if (ps.origin == 'remote') q['metadata._user.host'] = { $ne: null };
const files = await File
.find(q, {
diff --git a/src/server/api/endpoints/drive/files/delete.ts b/src/server/api/endpoints/drive/files/delete.ts
index 7367c8fbb6..0c2799c708 100644
--- a/src/server/api/endpoints/drive/files/delete.ts
+++ b/src/server/api/endpoints/drive/files/delete.ts
@@ -32,14 +32,17 @@ export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// Fetch file
const file = await DriveFile
.findOne({
- _id: ps.fileId,
- 'metadata.userId': user._id
+ _id: ps.fileId
});
if (file === null) {
return rej('file-not-found');
}
+ if (!user.isAdmin && !user.isModerator && !file.metadata.userId.equals(user._id)) {
+ return rej('access denied');
+ }
+
// Delete
await del(file);