2018-12-14 10:09:11 +00:00
|
|
|
import $ from 'cafy';
|
|
|
|
import File, { packMany } from '../../../../../models/drive-file';
|
|
|
|
import define from '../../../define';
|
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
requireCredential: false,
|
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
limit: {
|
|
|
|
validator: $.num.optional.range(1, 100),
|
|
|
|
default: 10
|
|
|
|
},
|
|
|
|
|
|
|
|
offset: {
|
|
|
|
validator: $.num.optional.min(0),
|
|
|
|
default: 0
|
|
|
|
},
|
|
|
|
|
|
|
|
sort: {
|
|
|
|
validator: $.str.optional.or([
|
|
|
|
'+createdAt',
|
|
|
|
'-createdAt',
|
|
|
|
'+size',
|
|
|
|
'-size',
|
|
|
|
]),
|
|
|
|
},
|
|
|
|
|
|
|
|
origin: {
|
|
|
|
validator: $.str.optional.or([
|
|
|
|
'combined',
|
|
|
|
'local',
|
|
|
|
'remote',
|
|
|
|
]),
|
|
|
|
default: 'local'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
2018-12-23 20:31:20 +00:00
|
|
|
} else if (ps.sort == '-size') {
|
2018-12-14 10:09:11 +00:00
|
|
|
_sort = {
|
2018-12-23 20:31:20 +00:00
|
|
|
length: 1
|
2018-12-14 10:09:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_sort = {
|
|
|
|
_id: -1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-12-14 15:09:04 +00: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 10:09:11 +00:00
|
|
|
|
|
|
|
const files = await File
|
|
|
|
.find(q, {
|
|
|
|
limit: ps.limit,
|
|
|
|
sort: _sort,
|
|
|
|
skip: ps.offset
|
|
|
|
});
|
|
|
|
|
2019-01-08 08:45:16 +00:00
|
|
|
res(await packMany(files, { detail: true, withUser: true, self: true }));
|
2018-12-14 10:09:11 +00:00
|
|
|
}));
|