summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/admin/drive
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/api/endpoints/admin/drive')
-rw-r--r--src/server/api/endpoints/admin/drive/files.ts64
-rw-r--r--src/server/api/endpoints/admin/drive/show-file.ts16
2 files changed, 49 insertions, 31 deletions
diff --git a/src/server/api/endpoints/admin/drive/files.ts b/src/server/api/endpoints/admin/drive/files.ts
index c5a91db854..f6296b8947 100644
--- a/src/server/api/endpoints/admin/drive/files.ts
+++ b/src/server/api/endpoints/admin/drive/files.ts
@@ -1,7 +1,8 @@
import $ from 'cafy';
import define from '../../../define';
-import { fallback } from '../../../../../prelude/symbol';
import { DriveFiles } from '../../../../../models';
+import { makePaginationQuery } from '../../../common/make-pagination-query';
+import { ID } from '../../../../../misc/cafy-id';
export const meta = {
tags: ['admin'],
@@ -15,18 +16,16 @@ export const meta = {
default: 10
},
- offset: {
- validator: $.optional.num.min(0),
- default: 0
+ sinceId: {
+ validator: $.optional.type(ID),
},
- sort: {
- validator: $.optional.str.or([
- '+createdAt',
- '-createdAt',
- '+size',
- '-size',
- ]),
+ untilId: {
+ validator: $.optional.type(ID),
+ },
+
+ type: {
+ validator: $.optional.nullable.str.match(/^[a-zA-Z\/\-*]+$/)
},
origin: {
@@ -36,30 +35,37 @@ export const meta = {
'remote',
]),
default: 'local'
- }
- }
-};
+ },
-const sort: any = { // < https://github.com/Microsoft/TypeScript/issues/1863
- '+createdAt': { createdAt: -1 },
- '-createdAt': { createdAt: 1 },
- '+size': { size: -1 },
- '-size': { size: 1 },
- [fallback]: { id: -1 }
+ hostname: {
+ validator: $.optional.nullable.str,
+ default: null
+ },
+ }
};
export default define(meta, async (ps, me) => {
- const q = {} as any;
+ 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');
+ }
- if (ps.origin === 'local') q['userHost'] = null;
- if (ps.origin === 'remote') q['userHost'] = { $ne: null };
+ 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 });
+ }
+ }
- const files = await DriveFiles.find({
- where: q,
- take: ps.limit!,
- order: sort[ps.sort!] || sort[fallback],
- skip: ps.offset
- });
+ const files = await query.take(ps.limit!).getMany();
return await DriveFiles.packMany(files, { detail: true, withUser: true, self: true });
});
diff --git a/src/server/api/endpoints/admin/drive/show-file.ts b/src/server/api/endpoints/admin/drive/show-file.ts
index 415bfc28b3..36403bb1c3 100644
--- a/src/server/api/endpoints/admin/drive/show-file.ts
+++ b/src/server/api/endpoints/admin/drive/show-file.ts
@@ -12,7 +12,11 @@ export const meta = {
params: {
fileId: {
- validator: $.type(ID),
+ validator: $.optional.type(ID),
+ },
+
+ url: {
+ validator: $.optional.str,
},
},
@@ -26,7 +30,15 @@ export const meta = {
};
export default define(meta, async (ps, me) => {
- const file = await DriveFiles.findOne(ps.fileId);
+ const file = ps.fileId ? await DriveFiles.findOne(ps.fileId) : await DriveFiles.findOne({
+ where: [{
+ url: ps.url
+ }, {
+ thumbnailUrl: ps.url
+ }, {
+ webpublicUrl: ps.url
+ }]
+ });
if (file == null) {
throw new ApiError(meta.errors.noSuchFile);