This commit is contained in:
syuilo 2018-12-15 00:09:04 +09:00
parent 3ae42d9b85
commit ebceffba1e
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
3 changed files with 71 additions and 37 deletions

View file

@ -19,6 +19,7 @@
</ui-select>
</ui-horizon-group>
<div class="kidvdlkg" v-for="file in files">
<div @click="file._open = !file._open">
<div>
<div class="thumbnail" :style="thumbnail(file)"></div>
</div>
@ -36,6 +37,10 @@
</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>
</ui-card>
@ -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,11 +141,14 @@ export default Vue.extend({
padding 16px
.kidvdlkg
display flex
padding 16px 0
border-top solid 1px var(--faceDivider)
> div:first-child
display flex
cursor pointer
> div:nth-child(1)
> .thumbnail
display block
width 64px
@ -127,7 +156,7 @@ export default Vue.extend({
background-size cover
background-position center center
> div:last-child
> div:nth-child(2)
flex 1
padding-left 16px

View file

@ -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, {

View file

@ -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);