2018-12-14 11:09:11 +01:00
|
|
|
import $ from 'cafy';
|
|
|
|
import define from '../../../define';
|
2019-04-07 14:50:36 +02:00
|
|
|
import { DriveFiles } from '../../../../../models';
|
2020-10-17 13:12:00 +02:00
|
|
|
import { makePaginationQuery } from '../../../common/make-pagination-query';
|
|
|
|
import { ID } from '../../../../../misc/cafy-id';
|
2018-12-14 11:09:11 +01:00
|
|
|
|
|
|
|
export const meta = {
|
2021-03-06 14:34:11 +01:00
|
|
|
desc: {
|
|
|
|
'ja-JP': '管理用のドライブの一覧を表示します。',
|
|
|
|
'en-US': 'Displays a list of management drives.'
|
|
|
|
},
|
|
|
|
|
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
|
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
sinceId: {
|
|
|
|
validator: $.optional.type(ID),
|
2018-12-14 11:09:11 +01:00
|
|
|
},
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
untilId: {
|
|
|
|
validator: $.optional.type(ID),
|
|
|
|
},
|
|
|
|
|
|
|
|
type: {
|
|
|
|
validator: $.optional.nullable.str.match(/^[a-zA-Z\/\-*]+$/)
|
2018-12-14 11:09:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
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'
|
2020-10-17 13:12:00 +02:00
|
|
|
},
|
2018-12-14 11:09:11 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
hostname: {
|
|
|
|
validator: $.optional.nullable.str,
|
|
|
|
default: null
|
|
|
|
},
|
2021-03-06 14:34:11 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
|
|
|
type: 'array' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
items: {
|
|
|
|
type: 'object' as const,
|
|
|
|
optional: false as const, nullable: false as const,
|
|
|
|
ref: 'DriveFile'
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
}
|
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) => {
|
2020-10-17 13:12:00 +02:00
|
|
|
const query = makePaginationQuery(DriveFiles.createQueryBuilder('file'), ps.sinceId, ps.untilId);
|
|
|
|
|
|
|
|
if (ps.origin === 'local') {
|
|
|
|
query.andWhere('file.userHost IS NULL');
|
|
|
|
} else if (ps.origin === 'remote') {
|
|
|
|
query.andWhere('file.userHost IS NOT NULL');
|
|
|
|
}
|
2018-12-14 16:09:04 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
if (ps.hostname) {
|
|
|
|
query.andWhere('file.userHost = :hostname', { hostname: ps.hostname });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ps.type) {
|
|
|
|
if (ps.type.endsWith('/*')) {
|
|
|
|
query.andWhere('file.type like :type', { type: ps.type.replace('/*', '/') + '%' });
|
|
|
|
} else {
|
|
|
|
query.andWhere('file.type = :type', { type: ps.type });
|
|
|
|
}
|
|
|
|
}
|
2018-12-14 11:09:11 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
const files = await query.take(ps.limit!).getMany();
|
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
|
|
|
});
|