2022-07-02 01:12:11 -05:00
|
|
|
import { DriveFiles } from '@/models/index.js';
|
2022-02-26 20:07:39 -06:00
|
|
|
import define from '../../../define.js';
|
|
|
|
import { ApiError } from '../../../error.js';
|
2019-01-18 18:50:38 -06:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-22 20:20:58 -06:00
|
|
|
tags: ['admin'],
|
|
|
|
|
2022-01-18 07:27:10 -06:00
|
|
|
requireCredential: true,
|
2019-01-18 18:50:38 -06:00
|
|
|
requireModerator: true,
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
errors: {
|
|
|
|
noSuchFile: {
|
|
|
|
message: 'No such file.',
|
|
|
|
code: 'NO_SUCH_FILE',
|
2021-12-09 08:58:30 -06:00
|
|
|
id: 'caf3ca38-c6e5-472e-a30c-b05377dcc240',
|
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
res: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
properties: {
|
|
|
|
id: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'id',
|
|
|
|
example: 'xxxxxxxxxx',
|
|
|
|
},
|
|
|
|
createdAt: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'date-time',
|
|
|
|
},
|
|
|
|
userId: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'id',
|
|
|
|
example: 'xxxxxxxxxx',
|
|
|
|
},
|
|
|
|
userHost: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2022-04-02 23:57:26 -05:00
|
|
|
description: 'The local host is represented with `null`.',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
md5: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'md5',
|
2021-12-09 08:58:30 -06:00
|
|
|
example: '15eca7fba0480996e2245f5185bf39f2',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
name: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: 'lenna.jpg',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
type: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: 'image/jpeg',
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
size: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: 51469,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
comment: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
blurhash: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
properties: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'object',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
properties: {
|
|
|
|
width: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: 1280,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
height: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'number',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: 720,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
avgColor: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: true, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: 'rgb(40,65,87)',
|
|
|
|
},
|
|
|
|
},
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
storedInternal: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'boolean',
|
|
|
|
optional: false, nullable: true,
|
2021-12-09 08:58:30 -06:00
|
|
|
example: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
url: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'url',
|
|
|
|
},
|
|
|
|
thumbnailUrl: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'url',
|
|
|
|
},
|
|
|
|
webpublicUrl: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'url',
|
|
|
|
},
|
|
|
|
accessKey: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
thumbnailAccessKey: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
webpublicAccessKey: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
uri: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
src: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
folderId: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'string',
|
|
|
|
optional: false, nullable: true,
|
2021-03-06 07:34:11 -06:00
|
|
|
format: 'id',
|
|
|
|
example: 'xxxxxxxxxx',
|
|
|
|
},
|
|
|
|
isSensitive: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'boolean',
|
|
|
|
optional: false, nullable: false,
|
2021-03-06 07:34:11 -06:00
|
|
|
},
|
|
|
|
isLink: {
|
2022-01-18 07:27:10 -06:00
|
|
|
type: 'boolean',
|
|
|
|
optional: false, nullable: false,
|
2021-12-09 08:58:30 -06:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-18 07:27:10 -06:00
|
|
|
} as const;
|
2019-01-18 18:50:38 -06:00
|
|
|
|
2022-02-19 22:15:40 -06:00
|
|
|
export const paramDef = {
|
2022-02-18 23:05:32 -06:00
|
|
|
type: 'object',
|
2022-04-02 23:57:26 -05:00
|
|
|
anyOf: [
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
fileId: { type: 'string', format: 'misskey:id' },
|
|
|
|
},
|
|
|
|
required: ['fileId'],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
properties: {
|
|
|
|
url: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: ['url'],
|
|
|
|
},
|
|
|
|
],
|
2022-02-18 23:05:32 -06:00
|
|
|
} as const;
|
|
|
|
|
2022-01-02 11:12:50 -06:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-02-18 23:05:32 -06:00
|
|
|
export default define(meta, paramDef, async (ps, me) => {
|
2022-03-26 01:34:00 -05:00
|
|
|
const file = ps.fileId ? await DriveFiles.findOneBy({ id: ps.fileId }) : await DriveFiles.findOne({
|
2020-10-17 06:12:00 -05:00
|
|
|
where: [{
|
2021-12-09 08:58:30 -06:00
|
|
|
url: ps.url,
|
2020-10-17 06:12:00 -05:00
|
|
|
}, {
|
2021-12-09 08:58:30 -06:00
|
|
|
thumbnailUrl: ps.url,
|
2020-10-17 06:12:00 -05:00
|
|
|
}, {
|
2021-12-09 08:58:30 -06:00
|
|
|
webpublicUrl: ps.url,
|
|
|
|
}],
|
2020-10-17 06:12:00 -05:00
|
|
|
});
|
2019-01-18 18:50:38 -06:00
|
|
|
|
|
|
|
if (file == null) {
|
2019-02-21 20:46:58 -06:00
|
|
|
throw new ApiError(meta.errors.noSuchFile);
|
2019-01-18 18:50:38 -06:00
|
|
|
}
|
|
|
|
|
2022-07-02 01:12:11 -05:00
|
|
|
if (!me.isAdmin) {
|
|
|
|
delete file.requestIp;
|
|
|
|
delete file.requestHeaders;
|
|
|
|
}
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
return file;
|
|
|
|
});
|