diff options
| author | Acid Chicken (硫酸鶏) <root@acid-chicken.com> | 2019-02-17 21:40:53 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-02-17 21:40:53 +0900 |
| commit | 357528d1399f4f7046c4cd8ed1a9884ffbba905f (patch) | |
| tree | 10fa35890bd78c47c224684e3e0fd2dccda893f0 /src/server/api/endpoints/admin/drive | |
| parent | Fix #4292 (#4294) (diff) | |
| download | sharkey-357528d1399f4f7046c4cd8ed1a9884ffbba905f.tar.gz sharkey-357528d1399f4f7046c4cd8ed1a9884ffbba905f.tar.bz2 sharkey-357528d1399f4f7046c4cd8ed1a9884ffbba905f.zip | |
Use object instead of if chain (#4212)
Diffstat (limited to 'src/server/api/endpoints/admin/drive')
| -rw-r--r-- | src/server/api/endpoints/admin/drive/files.ts | 36 |
1 files changed, 10 insertions, 26 deletions
diff --git a/src/server/api/endpoints/admin/drive/files.ts b/src/server/api/endpoints/admin/drive/files.ts index 12b2bac376..3a837e4189 100644 --- a/src/server/api/endpoints/admin/drive/files.ts +++ b/src/server/api/endpoints/admin/drive/files.ts @@ -1,6 +1,7 @@ import $ from 'cafy'; import File, { packMany } from '../../../../../models/drive-file'; import define from '../../../define'; +import { fallback } from '../../../../../prelude/symbol'; export const meta = { requireCredential: false, @@ -37,32 +38,15 @@ export const meta = { } }; -export default define(meta, (ps, me) => new Promise(async (res, rej) => { - let _sort; - if (ps.sort) { - if (ps.sort == '+createdAt') { - _sort = { - uploadDate: -1 - }; - } else if (ps.sort == '-createdAt') { - _sort = { - uploadDate: 1 - }; - } else if (ps.sort == '+size') { - _sort = { - length: -1 - }; - } else if (ps.sort == '-size') { - _sort = { - length: 1 - }; - } - } else { - _sort = { - _id: -1 - }; - } +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 } +}; +export default define(meta, (ps, me) => new Promise(async (res, rej) => { const q = { 'metadata.deletedAt': { $exists: false }, } as any; @@ -73,7 +57,7 @@ export default define(meta, (ps, me) => new Promise(async (res, rej) => { const files = await File .find(q, { limit: ps.limit, - sort: _sort, + sort: sort[ps.sort] || sort[fallback], skip: ps.offset }); |