2018-12-14 11:09:11 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../../define';
|
2019-02-17 13:40:53 +01:00
|
|
|
import { fallback } from '../../../../../prelude/symbol';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { DriveFiles } from '../../../../../models';
|
2018-12-14 11:09:11 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 03:20:58 +01:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2020-02-15 13:33:32 +01:00
|
|
|
requireCredential: false as const,
|
2018-12-14 11:09:11 +01:00
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
limit: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.num.range(1, 100),
|
2018-12-14 11:09:11 +01:00
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
offset: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.num.min(0),
|
2018-12-14 11:09:11 +01:00
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
|
|
|
|
sort: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.str.or([
|
2018-12-14 11:09:11 +01:00
|
|
|
'+createdAt',
|
|
|
|
'-createdAt',
|
|
|
|
'+size',
|
|
|
|
'-size',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
|
|
|
|
origin: {
|
2019-02-13 08:33:07 +01:00
|
|
|
validator: $.optional.str.or([
|
2018-12-14 11:09:11 +01:00
|
|
|
'combined',
|
|
|
|
'local',
|
|
|
|
'remote',
|
|
|
|
]),
|
|
|
|
default: 'local'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-17 13:40:53 +01:00
|
|
|
const sort: any = { // < https://github.com/Microsoft/TypeScript/issues/1863
|
2019-04-07 14:50:36 +02:00
|
|
|
'+createdAt': { createdAt: -1 },
|
|
|
|
'-createdAt': { createdAt: 1 },
|
|
|
|
'+size': { size: -1 },
|
|
|
|
'-size': { size: 1 },
|
|
|
|
[fallback]: { id: -1 }
|
2019-02-17 13:40:53 +01:00
|
|
|
};
|
2018-12-14 11:09:11 +01:00
|
|
|
|
2019-02-22 03:46:58 +01:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-04-07 14:50:36 +02:00
|
|
|
const q = {} as any;
|
2018-12-14 16:09:04 +01:00
|
|
|
|
2020-04-04 01:46:54 +02:00
|
|
|
if (ps.origin === 'local') q['userHost'] = null;
|
|
|
|
if (ps.origin === 'remote') q['userHost'] = { $ne: null };
|
2018-12-14 11:09:11 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
const files = await DriveFiles.find({
|
|
|
|
where: q,
|
2019-04-12 18:43:22 +02:00
|
|
|
take: ps.limit!,
|
|
|
|
order: sort[ps.sort!] || sort[fallback],
|
2019-04-07 14:50:36 +02:00
|
|
|
skip: ps.offset
|
|
|
|
});
|
2018-12-14 11:09:11 +01:00
|
|
|
|
2019-04-07 14:50:36 +02:00
|
|
|
return await DriveFiles.packMany(files, { detail: true, withUser: true, self: true });
|
2019-02-22 03:46:58 +01:00
|
|
|
});
|