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