Skip to content

Commit

Permalink
Tune admin/drive
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Feb 23, 2022
1 parent 166e69e commit 8e02e80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
17 changes: 1 addition & 16 deletions src/client/app/admin/views/drive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
<template #title><fa :icon="faCloud"/> {{ $t('@.drive') }}</template>
<section class="fit-top">
<ui-horizon-group inputs>
<ui-select v-model="sort">
<template #label>{{ $t('sort.title') }}</template>
<option value="-createdAt">{{ $t('sort.createdAtAsc') }}</option>
<option value="+createdAt">{{ $t('sort.createdAtDesc') }}</option>
<option value="-size">{{ $t('sort.sizeAsc') }}</option>
<option value="+size">{{ $t('sort.sizeDesc') }}</option>
</ui-select>
<ui-select v-model="origin">
<template #label>{{ $t('origin.title') }}</template>
<option value="combined">{{ $t('origin.combined') }}</option>
Expand Down Expand Up @@ -88,8 +81,7 @@ export default Vue.extend({
return {
file: null,
target: null,
sort: '+createdAt',
origin: 'combined',
origin: 'local',
limit: 10,
offset: 0,
files: [],
Expand All @@ -99,12 +91,6 @@ export default Vue.extend({
},
watch: {
sort() {
this.files = [];
this.offset = 0;
this.fetch();
},
origin() {
this.files = [];
this.offset = 0;
Expand All @@ -131,7 +117,6 @@ export default Vue.extend({
fetch() {
this.$root.api('admin/drive/files', {
origin: this.origin,
sort: this.sort,
offset: this.offset,
limit: this.limit + 1
}).then(files => {
Expand Down
34 changes: 12 additions & 22 deletions src/server/api/endpoints/admin/drive/files.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import $ from 'cafy';
import File, { packMany } from '../../../../../models/drive-file';
import define from '../../../define';
import { fallback } from '../../../../../prelude/symbol';

export const meta = {
tags: ['admin'],
Expand All @@ -20,46 +19,37 @@ export const meta = {
default: 0
},

sort: {
validator: $.optional.str.or([
'+createdAt',
'-createdAt',
'+size',
'-size',
]),
},

origin: {
validator: $.optional.str.or([
'combined',
'local',
'remote',
]),
default: 'local'
}
}
};
},

const sort: any = { // < https://github.com/Microsoft/TypeScript/issues/1863
'+createdAt': { uploadDate: -1 },
'-createdAt': { uploadDate: 1 },
'+size': { length: -1 },
'-size': { length: 1 },
[fallback]: { _id: -1 }
hostname: {
validator: $.optional.nullable.str,
default: null,
},
}
};

export default define(meta, async (ps, me) => {
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 };
if (ps.hostname != null) {
q['metadata._user.host'] = ps.hostname; // TODO:normalize
} else {
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, {
limit: ps.limit,
sort: sort[ps.sort] || sort[fallback],
skip: ps.offset
});

Expand Down

0 comments on commit 8e02e80

Please sign in to comment.