This commit is contained in:
tamaina 2022-02-20 01:32:35 +09:00
parent 76d945c1f7
commit 0589c065bf
303 changed files with 314 additions and 304 deletions

View File

@ -1,10 +1,13 @@
import * as fs from 'fs';
import * as Ajv from 'ajv';
import Ajv from 'ajv';
import { ILocalUser } from '@/models/entities/user';
import { IEndpointMeta } from './endpoints';
import { ApiError } from './error';
import { Schema, SchemaType } from '@/misc/schema';
import { AccessToken } from '@/models/entities/access-token';
import { ValidateFunction } from 'ajv';
import { JTDDataType } from 'ajv/dist/types/jtd-schema';
import { apiLogger } from './logger';
type SimpleUserInfo = {
id: ILocalUser['id'];
@ -36,7 +39,13 @@ ajv.addFormat('misskey:id', /^[a-z0-9]+$/);
export default function <T extends IEndpointMeta, Ps extends Schema>(meta: T, paramDef: Ps, cb: executor<T, Ps>)
: (params: any, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any) => Promise<any> {
const validate = ajv.compile(paramDef);
let validate: ValidateFunction<JTDDataType<Ps>>;
try {
validate = ajv.compile(paramDef);
} catch (error) {
apiLogger.error('FAILED TO COMPILE SCHEMA ' + JSON.stringify({ param: paramDef, error }));
}
return (params: any, user: T['requireCredential'] extends true ? SimpleUserInfo : SimpleUserInfo | null, token: AccessToken | null, file?: any) => {
function cleanup() {
@ -65,6 +74,6 @@ export default function <T extends IEndpointMeta, Ps extends Schema>(meta: T, pa
return Promise.reject(err);
}
return cb(params, user, token, file, cleanup);
return cb(params as SchemaType<Ps>, user, token, file, cleanup);
};
}

View File

@ -70,7 +70,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -18,7 +18,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
username: Users.localUsernameSchema,

View File

@ -11,7 +11,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
url: { type: 'string', minLength: 1 },

View File

@ -17,7 +17,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -17,7 +17,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },

View File

@ -44,7 +44,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
title: { type: 'string', minLength: 1 },

View File

@ -17,7 +17,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },

View File

@ -52,7 +52,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -17,7 +17,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -8,7 +8,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -19,7 +19,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -149,7 +149,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
fileId: { type: 'string', format: 'misskey:id' },

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
ids: { type: 'array', items: {

View File

@ -22,7 +22,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
fileId: { type: 'string', format: 'misskey:id' },

View File

@ -34,7 +34,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
emojiId: { type: 'string', format: 'misskey:id' },

View File

@ -11,7 +11,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
ids: { type: 'array', items: {

View File

@ -19,7 +19,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },

View File

@ -8,7 +8,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
fileId: { type: 'string', format: 'misskey:id' },

View File

@ -50,7 +50,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
query: { type: 'string', nullable: true, default: null },

View File

@ -50,7 +50,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
query: { type: 'string', nullable: true, default: null },

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
ids: { type: 'array', items: {

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
ids: { type: 'array', items: {

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
ids: { type: 'array', items: {

View File

@ -18,7 +18,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
id: { type: 'string', format: 'misskey:id' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },

View File

@ -8,7 +8,7 @@ export const meta = {
tags: ['admin'],
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -19,7 +19,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -24,7 +24,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -8,7 +8,7 @@ export const meta = {
requireAdmin: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -8,7 +8,7 @@ export const meta = {
requireAdmin: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -24,7 +24,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
noteId: { type: 'string', format: 'misskey:id' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -32,7 +32,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -32,7 +32,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -31,7 +31,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -45,7 +45,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
inbox: { type: 'string' },

View File

@ -39,7 +39,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -8,7 +8,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
inbox: { type: 'string' },

View File

@ -23,7 +23,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -12,7 +12,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
reportId: { type: 'string', format: 'misskey:id' },

View File

@ -8,7 +8,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
to: { type: 'string' },

View File

@ -87,7 +87,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -48,7 +48,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -13,7 +13,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -18,7 +18,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -13,7 +13,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -10,7 +10,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -11,7 +11,7 @@ export const meta = {
requireAdmin: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
disableRegistration: { type: 'boolean', nullable: true },

View File

@ -9,7 +9,7 @@ export const meta = {
requireModerator: true,
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
full: { type: 'boolean' },

View File

@ -51,7 +51,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },

View File

@ -32,7 +32,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 100 },

View File

@ -19,7 +19,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },

View File

@ -19,7 +19,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -33,7 +33,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },

View File

@ -24,7 +24,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },

View File

@ -37,7 +37,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },

View File

@ -22,7 +22,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
uri: { type: 'string' },

View File

@ -68,7 +68,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
uri: { type: 'string' },

View File

@ -16,7 +16,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string' },

View File

@ -20,7 +20,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
appId: { type: 'string', format: 'misskey:id' },

View File

@ -21,7 +21,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
token: { type: 'string' },

View File

@ -35,7 +35,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
appSecret: { type: 'string' },

View File

@ -37,7 +37,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
token: { type: 'string' },

View File

@ -45,7 +45,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
appSecret: { type: 'string' },

View File

@ -44,7 +44,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -44,7 +44,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },

View File

@ -20,7 +20,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },

View File

@ -26,7 +26,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 128 },

View File

@ -17,7 +17,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {},
required: [],

View File

@ -20,7 +20,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },

View File

@ -20,7 +20,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
sinceId: { type: 'string', format: 'misskey:id' },

View File

@ -20,7 +20,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
sinceId: { type: 'string', format: 'misskey:id' },

View File

@ -22,7 +22,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },

View File

@ -28,7 +28,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },

View File

@ -19,7 +19,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },

View File

@ -36,7 +36,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
channelId: { type: 'string', format: 'misskey:id' },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(activeUsersChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(apRequestChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(driveChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(federationChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(hashtagChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(instanceChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(notesChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(perUserDriveChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(perUserFollowingChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(perUserNotesChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(perUserReactionsChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -8,7 +8,7 @@ export const meta = {
res: getJsonSchema(usersChart.schema),
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
span: { type: 'string', enum: ['day', 'hour'] },

View File

@ -32,7 +32,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
clipId: { type: 'string', format: 'misskey:id' },

View File

@ -16,7 +16,7 @@ export const meta = {
},
} as const;
const paramDef = {
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 100 },

Some files were not shown because too many files have changed in this diff Show More