2018-12-14 12:09:11 +02:00
|
|
|
import $ from 'cafy';
|
|
|
|
import File, { packMany } from '../../../../../models/drive-file';
|
|
|
|
import define from '../../../define';
|
2019-02-17 14:40:53 +02:00
|
|
|
import { fallback } from '../../../../../prelude/symbol';
|
2018-12-14 12:09:11 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2018-12-14 12:09:11 +02:00
|
|
|
requireCredential: false,
|
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
limit: {
|
2019-02-13 09:33:07 +02:00
|
|
|
validator: $.optional.num.range(1, 100),
|
2018-12-14 12:09:11 +02:00
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
offset: {
|
2019-02-13 09:33:07 +02:00
|
|
|
validator: $.optional.num.min(0),
|
2018-12-14 12:09:11 +02:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
|
|
|
|
sort: {
|
2019-02-13 09:33:07 +02:00
|
|
|
validator: $.optional.str.or([
|
2018-12-14 12:09:11 +02:00
|
|
|
'+createdAt',
|
|
|
|
'-createdAt',
|
|
|
|
'+size',
|
|
|
|
'-size',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
|
|
|
|
origin: {
|
2019-02-13 09:33:07 +02:00
|
|
|
validator: $.optional.str.or([
|
2018-12-14 12:09:11 +02:00
|
|
|
'combined',
|
|
|
|
'local',
|
|
|
|
'remote',
|
|
|
|
]),
|
|
|
|
default: 'local'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-17 14:40:53 +02:00
|
|
|
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 }
|
|
|
|
};
|
2018-12-14 12:09:11 +02:00
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
export default define(meta, async (ps, me) => {
|
2018-12-14 17:09:04 +02:00
|
|
|
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 };
|
2018-12-14 12:09:11 +02:00
|
|
|
|
|
|
|
const files = await File
|
|
|
|
.find(q, {
|
|
|
|
limit: ps.limit,
|
2019-02-17 14:40:53 +02:00
|
|
|
sort: sort[ps.sort] || sort[fallback],
|
2018-12-14 12:09:11 +02:00
|
|
|
skip: ps.offset
|
|
|
|
});
|
|
|
|
|
2019-02-22 04:46:58 +02:00
|
|
|
return await packMany(files, { detail: true, withUser: true, self: true });
|
|
|
|
});
|