Refactor API (#4770)

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update description.ts

* wip
This commit is contained in:
syuilo
2019-04-23 22:35:26 +09:00
committed by GitHub
parent f31f986d66
commit 0463c6bb0f
105 changed files with 1622 additions and 808 deletions

View File

@ -3,6 +3,7 @@ import { ILocalUser } from '../../models/entities/user';
import { IEndpointMeta } from './endpoints';
import { ApiError } from './error';
import { App } from '../../models/entities/app';
import { SchemaType } from '../../misc/schema';
type Params<T extends IEndpointMeta> = {
[P in keyof T['params']]: NonNullable<T['params']>[P]['transform'] extends Function
@ -12,7 +13,11 @@ type Params<T extends IEndpointMeta> = {
export type Response = Record<string, any> | void;
export default function <T extends IEndpointMeta>(meta: T, cb: (params: Params<T>, user: ILocalUser, app: App, file?: any, cleanup?: Function) => Promise<Response>): (params: any, user: ILocalUser, app: App, file?: any) => Promise<any> {
type executor<T extends IEndpointMeta> =
(params: Params<T>, user: ILocalUser, app: App, file?: any, cleanup?: Function) => Promise<T['res'] extends undefined ? Response : SchemaType<NonNullable<T['res']>>>;
export default function <T extends IEndpointMeta>(meta: T, cb: executor<T>)
: (params: any, user: ILocalUser, app: App, file?: any) => Promise<any> {
return (params: any, user: ILocalUser, app: App, file?: any) => {
function cleanup() {
fs.unlink(file.path, () => {});

View File

@ -4,12 +4,13 @@ import define from '../../define';
import { Apps } from '../../../../models';
import { genId } from '../../../../misc/gen-id';
import { unique } from '../../../../prelude/array';
import { types, bool } from '../../../../misc/schema';
export const meta = {
tags: ['app'],
requireCredential: false,
desc: {
'ja-JP': 'アプリを作成します。',
'en-US': 'Create a application.'
@ -50,29 +51,12 @@ export const meta = {
}
},
},
res: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'アプリケーションのID'
},
name: {
type: 'string',
description: 'アプリケーションの名前'
},
callbackUrl: {
type: 'string',
nullable: true,
description: 'コールバックするURL'
},
secret: {
type: 'string',
description: 'アプリケーションのシークレットキー'
}
}
}
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'App',
},
};
export default define(meta, async (ps, user) => {

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { ApiError } from '../../error';
import { Apps } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
tags: ['app'],
@ -13,6 +14,12 @@ export const meta = {
},
},
res: {
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'App',
},
errors: {
noSuchApp: {
message: 'No such app.',

View File

@ -5,12 +5,13 @@ import define from '../../../define';
import { ApiError } from '../../../error';
import { Apps, AuthSessions } from '../../../../../models';
import { genId } from '../../../../../misc/gen-id';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
tags: ['auth'],
requireCredential: false,
desc: {
'ja-JP': 'アプリを認証するためのトークンを作成します。',
'en-US': 'Generate a token for authorize application.'
@ -27,14 +28,18 @@ export const meta = {
},
res: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
token: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'セッションのトークン'
},
url: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
format: 'url',
description: 'セッションのURL'
},
}

View File

@ -3,6 +3,7 @@ import define from '../../../define';
import { ApiError } from '../../../error';
import { Apps, AuthSessions, AccessTokens, Users } from '../../../../../models';
import { ensure } from '../../../../../prelude/ensure';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
tags: ['auth'],
@ -28,15 +29,19 @@ export const meta = {
},
res: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
accessToken: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'ユーザーのアクセストークン',
},
user: {
type: 'User',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
description: '認証したユーザー'
},
}

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { Blockings } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -32,9 +33,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Blocking',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Blocking',
}
},
};

View File

@ -1,6 +1,7 @@
import define from '../define';
import fetchMeta from '../../../misc/fetch-meta';
import { DriveFiles } from '../../../models';
import { types, bool } from '../../../misc/schema';
export const meta = {
desc: {
@ -15,13 +16,16 @@ export const meta = {
kind: 'read:drive',
res: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
capacity: {
type: 'number'
type: types.number,
optional: bool.false, nullable: bool.false,
},
usage: {
type: 'number'
type: types.number,
optional: bool.false, nullable: bool.false,
}
}
}

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { DriveFiles } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -41,10 +42,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'DriveFile',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFile',
}
},
};

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { DriveFiles } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
stability: 'stable',
@ -29,10 +30,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -1,6 +1,7 @@
import $ from 'cafy';
import define from '../../../define';
import { DriveFiles } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
desc: {
@ -24,7 +25,13 @@ export const meta = {
},
res: {
type: 'DriveFile',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFile',
}
},
};

View File

@ -6,6 +6,7 @@ import define from '../../../define';
import { apiLogger } from '../../../logger';
import { ApiError } from '../../../error';
import { DriveFiles } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
desc: {
@ -56,7 +57,9 @@ export const meta = {
},
res: {
type: 'DriveFile',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFile',
},
errors: {
@ -87,7 +90,7 @@ export default define(meta, async (ps, user, app, file, cleanup) => {
try {
// Create file
const driveFile = await create(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive);
return DriveFiles.pack(driveFile, { self: true });
return await DriveFiles.pack(driveFile, { self: true });
} catch (e) {
apiLogger.error(e);
throw new ApiError();

View File

@ -2,6 +2,7 @@ import $ from 'cafy';
import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define';
import { DriveFiles } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
requireCredential: true,
@ -22,7 +23,17 @@ export const meta = {
'ja-JP': 'フォルダID'
}
},
}
},
res: {
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFile',
}
},
};
export default define(meta, async (ps, user) => {

View File

@ -4,6 +4,7 @@ import define from '../../../define';
import { ApiError } from '../../../error';
import { DriveFile } from '../../../../../models/entities/drive-file';
import { DriveFiles } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
stability: 'stable',
@ -38,7 +39,9 @@ export const meta = {
},
res: {
type: 'DriveFile',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFile',
},
errors: {

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { DriveFolders } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -37,10 +38,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'DriveFolder',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFolder',
}
},
};

View File

@ -2,6 +2,7 @@ import $ from 'cafy';
import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define';
import { DriveFolders } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
tags: ['drive'],
@ -25,10 +26,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'DriveFolder',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFolder',
}
},
};

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { DriveFolders } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
stability: 'stable',
@ -29,7 +30,9 @@ export const meta = {
},
res: {
type: 'DriveFolder',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFolder',
},
errors: {

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { DriveFiles } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
tags: ['drive'],
@ -31,10 +32,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'DriveFile',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'DriveFile',
}
},
};

View File

@ -1,6 +1,7 @@
import $ from 'cafy';
import define from '../../define';
import { Hashtags } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
tags: ['hashtags'],
@ -47,9 +48,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Hashtag'
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Hashtag',
}
},
};

View File

@ -1,6 +1,7 @@
import $ from 'cafy';
import define from '../../define';
import { Hashtags } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -37,9 +38,11 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'string'
type: types.string,
optional: bool.false, nullable: bool.false,
}
},
};

View File

@ -1,6 +1,7 @@
import $ from 'cafy';
import define from '../../define';
import { Users } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
requireCredential: false,
@ -47,9 +48,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'User'
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
}
},
};

View File

@ -1,5 +1,6 @@
import define from '../define';
import { Users } from '../../../models';
import { types, bool } from '../../../misc/schema';
export const meta = {
stability: 'stable',
@ -15,8 +16,10 @@ export const meta = {
params: {},
res: {
type: 'User',
}
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
},
};
export default define(meta, async (ps, user, app) => {

View File

@ -4,6 +4,7 @@ import { readNotification } from '../../common/read-notification';
import define from '../../define';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notifications, Followings, Mutings } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -53,10 +54,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Notification',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Notification',
}
},
};

View File

@ -3,6 +3,7 @@ import define from '../../define';
import { MessagingMessage } from '../../../../models/entities/messaging-message';
import { MessagingMessages, Mutings } from '../../../../models';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -24,10 +25,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'MessagingMessage',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'MessagingMessage',
}
},
};

View File

@ -6,6 +6,7 @@ import { ApiError } from '../../error';
import { getUser } from '../../common/getters';
import { MessagingMessages } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -48,10 +49,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'MessagingMessage',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'MessagingMessage',
}
},
errors: {

View File

@ -9,6 +9,7 @@ import { getUser } from '../../../common/getters';
import { MessagingMessages, DriveFiles, Mutings } from '../../../../../models';
import { MessagingMessage } from '../../../../../models/entities/messaging-message';
import { genId } from '../../../../../misc/gen-id';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
desc: {
@ -41,7 +42,9 @@ export const meta = {
},
res: {
type: 'MessagingMessage',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'MessagingMessage',
},
errors: {

View File

@ -5,6 +5,7 @@ import define from '../define';
import fetchMeta from '../../../misc/fetch-meta';
import * as pkg from '../../../../package.json';
import { Emojis } from '../../../models';
import { types, bool } from '../../../misc/schema';
export const meta = {
stability: 'stable',
@ -26,32 +27,40 @@ export const meta = {
},
res: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
version: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'The version of Misskey of this instance.',
example: pkg.version
},
name: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'The name of this instance.',
},
description: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'The description of this instance.',
},
announcements: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
title: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'The title of the announcement.',
},
text: {
type: 'string',
type: types.string,
optional: bool.false, nullable: bool.false,
description: 'The text of the announcement. (can be HTML)',
},
}
@ -59,19 +68,23 @@ export const meta = {
description: 'The announcements of this instance.',
},
disableRegistration: {
type: 'boolean',
type: types.boolean,
optional: bool.false, nullable: bool.false,
description: 'Whether disabled open registration.',
},
disableLocalTimeline: {
type: 'boolean',
type: types.boolean,
optional: bool.false, nullable: bool.false,
description: 'Whether disabled LTL and STL.',
},
disableGlobalTimeline: {
type: 'boolean',
type: types.boolean,
optional: bool.false, nullable: bool.false,
description: 'Whether disabled GTL.',
},
enableEmojiReaction: {
type: 'boolean',
type: types.boolean,
optional: bool.false, nullable: bool.false,
description: 'Whether enabled emoji reaction.',
},
}

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../misc/cafy-id';
import define from '../../define';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Mutings } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -32,9 +33,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Muting',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Muting',
}
},
};

View File

@ -3,6 +3,7 @@ import { ID } from '../../../misc/cafy-id';
import define from '../define';
import { makePaginationQuery } from '../common/make-pagination-query';
import { Notes } from '../../../models';
import { types, bool } from '../../../misc/schema';
export const meta = {
desc: {
@ -62,9 +63,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -6,6 +6,7 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { Brackets } from 'typeorm';
import { Notes } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -41,10 +42,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -5,6 +5,7 @@ import { ApiError } from '../../error';
import { getNote } from '../../common/getters';
import { Note } from '../../../../models/entities/note';
import { Notes } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -37,10 +38,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -10,6 +10,7 @@ import { User } from '../../../../models/entities/user';
import { Users, DriveFiles, Notes } from '../../../../models';
import { DriveFile } from '../../../../models/entities/drive-file';
import { Note } from '../../../../models/entities/note';
import { types, bool } from '../../../../misc/schema';
let maxNoteTextLength = 1000;
@ -174,10 +175,13 @@ export const meta = {
},
res: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
createdNote: {
type: 'Note',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
description: '作成した投稿'
}
}

View File

@ -2,6 +2,7 @@ import $ from 'cafy';
import define from '../../define';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { Notes } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -24,10 +25,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -7,6 +7,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notes } from '../../../../models';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { activeUsersChart } from '../../../../services/chart';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -46,10 +47,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -9,6 +9,7 @@ import { Brackets } from 'typeorm';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { activeUsersChart } from '../../../../services/chart';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -89,10 +90,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -9,6 +9,7 @@ import { makePaginationQuery } from '../../common/make-pagination-query';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { activeUsersChart } from '../../../../services/chart';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -63,10 +64,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -7,6 +7,7 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -43,10 +44,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -4,6 +4,7 @@ import define from '../../define';
import { getNote } from '../../common/getters';
import { ApiError } from '../../error';
import { NoteReactions } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -44,9 +45,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Reaction'
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'NoteReaction',
}
},

View File

@ -7,6 +7,7 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { Notes } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -42,10 +43,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -5,6 +5,7 @@ import { Notes } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -46,10 +47,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -6,6 +6,7 @@ import { Notes } from '../../../../models';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -81,10 +82,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -4,6 +4,7 @@ import define from '../../define';
import { ApiError } from '../../error';
import { Notes } from '../../../../models';
import { In } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -32,10 +33,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -4,6 +4,7 @@ import define from '../../define';
import { getNote } from '../../common/getters';
import { ApiError } from '../../error';
import { Notes } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
stability: 'stable',
@ -28,7 +29,9 @@ export const meta = {
},
res: {
type: 'Note',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
},
errors: {

View File

@ -7,6 +7,7 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { generateMuteQuery } from '../../common/generate-mute-query';
import { activeUsersChart } from '../../../../services/chart';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -88,10 +89,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
};

View File

@ -6,6 +6,7 @@ import { UserLists, UserListJoinings, Notes } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { generateVisibilityQuery } from '../../common/generate-visibility-query';
import { activeUsersChart } from '../../../../services/chart';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -94,10 +95,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -1,6 +1,7 @@
import define from '../define';
import { Notes, Users } from '../../../models';
import { federationChart, driveChart } from '../../../services/chart';
import { bool, types } from '../../../misc/schema';
export const meta = {
requireCredential: false,
@ -15,26 +16,32 @@ export const meta = {
},
res: {
type: 'object',
type: types.object,
optional: bool.false, nullable: bool.false,
properties: {
notesCount: {
type: 'number',
type: types.number,
optional: bool.false, nullable: bool.false,
description: 'The count of all (local/remote) notes of this instance.',
},
originalNotesCount: {
type: 'number',
type: types.number,
optional: bool.false, nullable: bool.false,
description: 'The count of all local notes of this instance.',
},
usersCount: {
type: 'number',
type: types.number,
optional: bool.false, nullable: bool.false,
description: 'The count of all (local/remote) accounts of this instance.',
},
originalUsersCount: {
type: 'number',
type: types.number,
optional: bool.false, nullable: bool.false,
description: 'The count of all local accounts of this instance.',
},
instances: {
type: 'number',
type: types.number,
optional: bool.false, nullable: bool.false,
description: 'The count of federated instances.',
},
}
@ -42,7 +49,14 @@ export const meta = {
};
export default define(meta, async () => {
const [notesCount, originalNotesCount, usersCount, originalUsersCount, instances, driveUsageLocal, driveUsageRemote] = await Promise.all([
const [notesCount,
originalNotesCount,
usersCount,
originalUsersCount,
instances,
driveUsageLocal,
driveUsageRemote
] = await Promise.all([
Notes.count(),
Notes.count({ userHost: null }),
Users.count(),
@ -53,6 +67,12 @@ export default define(meta, async () => {
]);
return {
notesCount, originalNotesCount, usersCount, originalUsersCount, instances, driveUsageLocal, driveUsageRemote
notesCount,
originalNotesCount,
usersCount,
originalUsersCount,
instances,
driveUsageLocal,
driveUsageRemote
};
});

View File

@ -2,6 +2,7 @@ import $ from 'cafy';
import define from '../define';
import { Users } from '../../../models';
import { generateMuteQueryForUsers } from '../common/generate-mute-query';
import { types, bool } from '../../../misc/schema';
export const meta = {
tags: ['users'],
@ -53,9 +54,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'User',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
}
},
};

View File

@ -5,6 +5,7 @@ import { ApiError } from '../../error';
import { Users, Followings } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { toPunyNullable } from '../../../../misc/convert-host';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -48,10 +49,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Following',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Following',
}
},
errors: {

View File

@ -5,6 +5,7 @@ import { ApiError } from '../../error';
import { Users, Followings } from '../../../../models';
import { makePaginationQuery } from '../../common/make-pagination-query';
import { toPunyNullable } from '../../../../misc/convert-host';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -48,10 +49,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Following',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Following',
}
},
errors: {

View File

@ -6,6 +6,7 @@ import { ApiError } from '../../error';
import { getUser } from '../../common/getters';
import { Not, In } from 'typeorm';
import { Notes, Users } from '../../../../models';
import { types, bool } from '../../../../misc/schema';
export const meta = {
tags: ['users'],
@ -28,9 +29,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'User',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
}
},

View File

@ -3,6 +3,7 @@ import define from '../../../define';
import { UserLists } from '../../../../../models';
import { genId } from '../../../../../misc/gen-id';
import { UserList } from '../../../../../models/entities/user-list';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
desc: {
@ -17,10 +18,16 @@ export const meta = {
kind: 'write:account',
params: {
title: {
name: {
validator: $.str.range(1, 100)
}
}
},
res: {
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'UserList',
},
};
export default define(meta, async (ps, user) => {
@ -28,7 +35,7 @@ export default define(meta, async (ps, user) => {
id: genId(),
createdAt: new Date(),
userId: user.id,
name: ps.title,
name: ps.name,
} as UserList);
return await UserLists.pack(userList);

View File

@ -1,5 +1,6 @@
import define from '../../../define';
import { UserLists } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
desc: {
@ -13,10 +14,13 @@ export const meta = {
kind: 'read:account',
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'UserList',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'UserList',
}
},
};

View File

@ -3,6 +3,7 @@ import { ID } from '../../../../../misc/cafy-id';
import define from '../../../define';
import { ApiError } from '../../../error';
import { UserLists } from '../../../../../models';
import { types, bool } from '../../../../../misc/schema';
export const meta = {
desc: {
@ -23,7 +24,9 @@ export const meta = {
},
res: {
type: 'UserList'
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'UserList',
},
errors: {

View File

@ -8,6 +8,7 @@ import { generateVisibilityQuery } from '../../common/generate-visibility-query'
import { Notes } from '../../../../models';
import { generateMuteQuery } from '../../common/generate-mute-query';
import { Brackets } from 'typeorm';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -119,10 +120,13 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'Note',
},
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'Note',
}
},
errors: {

View File

@ -3,6 +3,7 @@ import $ from 'cafy';
import define from '../../define';
import { Users, Followings } from '../../../../models';
import { generateMuteQueryForUsers } from '../../common/generate-mute-query';
import { types, bool } from '../../../../misc/schema';
export const meta = {
desc: {
@ -28,9 +29,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'User',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
}
},
};

View File

@ -2,6 +2,7 @@ import $ from 'cafy';
import define from '../../define';
import { Users } from '../../../../models';
import { User } from '../../../../models/entities/user';
import { bool, types } from '../../../../misc/schema';
export const meta = {
desc: {
@ -54,9 +55,12 @@ export const meta = {
},
res: {
type: 'array',
type: types.array,
optional: bool.false, nullable: bool.false,
items: {
type: 'User',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
}
},
};

View File

@ -6,6 +6,7 @@ import { ApiError } from '../../error';
import { ID } from '../../../../misc/cafy-id';
import { Users } from '../../../../models';
import { In } from 'typeorm';
import { bool, types } from '../../../../misc/schema';
export const meta = {
desc: {
@ -42,7 +43,9 @@ export const meta = {
},
res: {
type: 'User',
type: types.object,
optional: bool.false, nullable: bool.false,
ref: 'User',
},
errors: {

View File

@ -44,20 +44,20 @@ export function getDescription(lang = 'ja-JP'): string {
const descriptions = {
'ja-JP': `**Misskey is a decentralized microblogging platform.**
## Usage
# Usage
**APIはすべてPOSTでリクエスト/レスポンスともにJSON形式です。**
一部のAPIはリクエストに認証情報(APIキー)が必要です。リクエストの際に\`i\`というパラメータでAPIキーを添付してください。
### 自分のアカウントのAPIキーを取得する
## 自分のアカウントのAPIキーを取得する
「設定 > API」で、自分のAPIキーを取得できます。
> アカウントを不正利用される可能性があるため、このトークンは第三者に教えないでください(アプリなどにも入力しないでください)。
### アプリケーションとしてAPIキーを取得する
## アプリケーションとしてAPIキーを取得する
直接ユーザーのAPIキーをアプリケーションが扱うのはセキュリティ上のリスクがあるので、
アプリケーションからAPIを利用する際には、アプリケーションとアプリケーションを利用するユーザーが結び付けられた専用のAPIキーを発行します。
#### 1.アプリケーションを登録する
### 1.アプリケーションを登録する
まず、あなたのアプリケーションやWebサービス(以後、あなたのアプリと呼びます)をMisskeyに登録します。
[デベロッパーセンター](/dev)にアクセスし、「アプリ > アプリ作成」からアプリを作成してください。
@ -65,7 +65,7 @@ export function getDescription(lang = 'ja-JP'): string {
> アプリに成りすまされる可能性があるため、極力このシークレットキーは公開しないようにしてください。</p>
#### 2.ユーザーに認証させる
### 2.ユーザーに認証させる
アプリを使ってもらうには、ユーザーにアカウントへのアクセスの許可をもらう必要があります。
認証セッションを開始するには、[${config.apiUrl}/auth/session/generate](#operation/auth/session/generate) へパラメータに\`appSecret\`としてシークレットキーを含めたリクエストを送信します。
@ -76,7 +76,7 @@ export function getDescription(lang = 'ja-JP'): string {
あなたのアプリがコールバックURLを設定していない場合、ユーザーがあなたのアプリの連携を許可したことを(何らかの方法で(たとえばボタンを押させるなど))確認出来るようにしてください。
#### 3.アクセストークンを取得する
### 3.アクセストークンを取得する
ユーザーが連携を許可したら、[${config.apiUrl}/auth/session/userkey](#operation/auth/session/userkey) へリクエストを送信します。
上手くいけば、認証したユーザーのアクセストークンがレスポンスとして取得できます。おめでとうございます!
@ -88,7 +88,7 @@ APIキーの生成方法を擬似コードで表すと次のようになりま
const i = sha256(userToken + secretKey);
\`\`\`
## Permissions
# Permissions
|Permisson (kind)|Description|Endpoints|
|:--|:--|:--|
${permissionTable}

View File

@ -2,9 +2,8 @@ import endpoints from '../endpoints';
import { Context } from 'cafy';
import config from '../../../config';
import { errors as basicErrors } from './errors';
import { schemas } from './schemas';
import { schemas, convertSchemaToOpenApiSchema } from './schemas';
import { getDescription } from './description';
import { convertOpenApiSchema } from '../../../misc/schema';
export function genOpenapiSpec(lang = 'ja-JP') {
const spec = {
@ -59,7 +58,7 @@ export function genOpenapiSpec(lang = 'ja-JP') {
deprecated: (param.data || {}).deprecated,
...((param.data || {}).default ? { default: (param.data || {}).default } : {}),
type: param.name === 'ID' ? 'string' : param.name.toLowerCase(),
...(param.name === 'ID' ? { example: 'xxxxxxxxxxxxxxxxxxxxxxxx', format: 'id' } : {}),
...(param.name === 'ID' ? { example: 'xxxxxxxxxx', format: 'id' } : {}),
nullable: param.isNullable,
...(param.name === 'String' ? {
...((param as any).enum ? { enum: (param as any).enum } : {}),
@ -106,7 +105,7 @@ export function genOpenapiSpec(lang = 'ja-JP') {
const required = endpoint.meta.params ? Object.entries(endpoint.meta.params).filter(([k, v]) => !v.validator.isOptional).map(([k, v]) => k) : [];
const resSchema = endpoint.meta.res ? convertOpenApiSchema(endpoint.meta.res) : {};
const resSchema = endpoint.meta.res ? convertSchemaToOpenApiSchema(endpoint.meta.res) : {};
let desc = (endpoint.meta.desc ? endpoint.meta.desc[lang] : 'No description provided.') + '\n\n';
desc += `**Credential required**: *${endpoint.meta.requireCredential ? 'Yes' : 'No'}*`;

View File

@ -1,3 +1,39 @@
import { packedUserSchema } from '../../../models/repositories/user';
import { Schema } from '../../../misc/schema';
import { packedNoteSchema } from '../../../models/repositories/note';
import { packedUserListSchema } from '../../../models/repositories/user-list';
import { packedAppSchema } from '../../../models/repositories/app';
import { packedMessagingMessageSchema } from '../../../models/repositories/messaging-message';
import { packedNotificationSchema } from '../../../models/repositories/notification';
import { packedDriveFileSchema } from '../../../models/repositories/drive-file';
import { packedDriveFolderSchema } from '../../../models/repositories/drive-folder';
import { packedFollowingSchema } from '../../../models/repositories/following';
import { packedMutingSchema } from '../../../models/repositories/muting';
import { packedBlockingSchema } from '../../../models/repositories/blocking';
import { packedNoteReactionSchema } from '../../../models/repositories/note-reaction';
export function convertSchemaToOpenApiSchema(schema: Schema) {
const res: any = schema;
if (schema.type === 'object' && schema.properties) {
res.required = Object.entries(schema.properties).filter(([k, v]) => v.optional !== true).map(([k]) => k);
for (const k of Object.keys(schema.properties)) {
res.properties[k] = convertSchemaToOpenApiSchema(schema.properties[k]);
}
}
if (schema.type === 'array' && schema.items) {
res.items = convertSchemaToOpenApiSchema(schema.items);
}
if (schema.ref) {
res.$ref = `#/components/schemas/${schema.ref}`;
}
return res;
}
export const schemas = {
Error: {
type: 'object',
@ -26,413 +62,18 @@ export const schemas = {
required: ['error']
},
User: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this User.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
username: {
type: 'string',
description: 'The screen name, handle, or alias that this user identifies themselves with.',
example: 'ai'
},
name: {
type: 'string',
nullable: true,
description: 'The name of the user, as theyve defined it.',
example: '藍'
},
host: {
type: 'string',
nullable: true,
example: 'misskey.example.com'
},
description: {
type: 'string',
nullable: true,
description: 'The user-defined UTF-8 string describing their account.',
example: 'Hi masters, I am Ai!'
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the user account was created on Misskey.'
},
followersCount: {
type: 'number',
description: 'The number of followers this account currently has.'
},
followingCount: {
type: 'number',
description: 'The number of users this account is following.'
},
notesCount: {
type: 'number',
description: 'The number of Notes (including renotes) issued by the user.'
},
isBot: {
type: 'boolean',
description: 'Whether this account is a bot.'
},
isCat: {
type: 'boolean',
description: 'Whether this account is a cat.'
},
isAdmin: {
type: 'boolean',
description: 'Whether this account is the admin.'
},
isVerified: {
type: 'boolean'
},
isLocked: {
type: 'boolean'
},
},
required: ['id', 'name', 'username', 'createdAt']
},
UserList: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this UserList.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the UserList was created.'
},
title: {
type: 'string',
description: 'The name of the UserList.'
},
},
required: ['id', 'createdAt', 'title']
},
MessagingMessage: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this MessagingMessage.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the MessagingMessage was created.'
},
text: {
type: 'string',
nullable: true
},
file: {
type: 'DriveFile',
nullable: true
},
recipientId: {
type: 'string',
format: 'id',
},
recipient: {
$ref: '#/components/schemas/User'
},
},
required: ['id', 'createdAt']
},
Note: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this Note.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the Note was created on Misskey.'
},
text: {
type: 'string'
},
cw: {
type: 'string'
},
userId: {
type: 'string',
format: 'id',
},
user: {
$ref: '#/components/schemas/User'
},
replyId: {
type: 'string',
format: 'id',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
renoteId: {
type: 'string',
format: 'id',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
reply: {
$ref: '#/components/schemas/Note'
},
renote: {
$ref: '#/components/schemas/Note'
},
viaMobile: {
type: 'boolean'
},
visibility: {
type: 'string'
},
},
required: ['id', 'userId', 'createdAt']
},
Notification: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this notification.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the notification was created.'
},
type: {
type: 'string',
enum: ['follow', 'receiveFollowRequest', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote'],
description: 'The type of the notification.'
},
},
required: ['id', 'createdAt', 'type']
},
DriveFile: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this Drive file.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the Drive file was created on Misskey.'
},
name: {
type: 'string',
description: 'The file name with extension.',
example: 'lenna.jpg'
},
type: {
type: 'string',
description: 'The MIME type of this Drive file.',
example: 'image/jpeg'
},
md5: {
type: 'string',
format: 'md5',
description: 'The MD5 hash of this Drive file.',
example: '15eca7fba0480996e2245f5185bf39f2'
},
size: {
type: 'number',
description: 'The size of this Drive file. (bytes)',
example: 51469
},
folderId: {
type: 'string',
format: 'id',
nullable: true,
description: 'The parent folder ID of this Drive file.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
isSensitive: {
type: 'boolean',
description: 'Whether this Drive file is sensitive.',
},
},
required: ['id', 'createdAt', 'name', 'type', 'size', 'md5']
},
DriveFolder: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this Drive folder.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the Drive folder was created.'
},
name: {
type: 'string',
description: 'The folder name.',
},
foldersCount: {
type: 'number',
description: 'The count of child folders.',
},
filesCount: {
type: 'number',
description: 'The count of child files.',
},
parentId: {
type: 'string',
format: 'id',
nullable: true,
description: 'The parent folder ID of this folder.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
parent: {
$ref: '#/components/schemas/DriveFolder'
},
},
required: ['id', 'createdAt', 'name']
},
Following: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this following.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the following was created.'
},
followeeId: {
type: 'string',
format: 'id',
},
followee: {
$ref: '#/components/schemas/User',
description: 'The followee.'
},
followerId: {
type: 'string',
format: 'id',
},
follower: {
$ref: '#/components/schemas/User',
description: 'The follower.'
},
},
required: ['id', 'createdAt', 'followeeId', 'followerId']
},
Muting: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this mute.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the mute was created.'
},
mutee: {
$ref: '#/components/schemas/User',
description: 'The mutee.'
},
},
required: ['id', 'createdAt', 'mutee']
},
Blocking: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this block.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the block was created.'
},
blockee: {
$ref: '#/components/schemas/User',
description: 'The blockee.'
},
},
required: ['id', 'createdAt', 'blockee']
},
Reaction: {
type: 'object',
properties: {
id: {
type: 'string',
format: 'id',
description: 'The unique identifier for this reaction.',
example: 'xxxxxxxxxxxxxxxxxxxxxxxx',
},
createdAt: {
type: 'string',
format: 'date-time',
description: 'The date that the reaction was created.'
},
user: {
$ref: '#/components/schemas/User',
description: 'User who performed this reaction.'
},
type: {
type: 'string',
enum: [
'like',
'love',
'laugh',
'hmm',
'surprise',
'congrats',
'angry',
'confused',
'rip',
'pudding',
'star'
],
description: 'The reaction type.'
},
},
required: ['id', 'createdAt', 'user', 'type']
},
User: convertSchemaToOpenApiSchema(packedUserSchema),
UserList: convertSchemaToOpenApiSchema(packedUserListSchema),
App: convertSchemaToOpenApiSchema(packedAppSchema),
MessagingMessage: convertSchemaToOpenApiSchema(packedMessagingMessageSchema),
Note: convertSchemaToOpenApiSchema(packedNoteSchema),
Notification: convertSchemaToOpenApiSchema(packedNotificationSchema),
DriveFile: convertSchemaToOpenApiSchema(packedDriveFileSchema),
DriveFolder: convertSchemaToOpenApiSchema(packedDriveFolderSchema),
Following: convertSchemaToOpenApiSchema(packedFollowingSchema),
Muting: convertSchemaToOpenApiSchema(packedMutingSchema),
Blocking: convertSchemaToOpenApiSchema(packedBlockingSchema),
NoteReaction: convertSchemaToOpenApiSchema(packedNoteReactionSchema),
Hashtag: {
type: 'object',

View File

@ -135,7 +135,7 @@ export default async (ctx: Koa.BaseContext) => {
includeSecrets: true
});
res.token = secret;
(res as any).token = secret;
ctx.body = res;
};

View File

@ -3,6 +3,7 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import fetchMeta from '../../../../misc/fetch-meta';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
export default class extends Channel {
public readonly chName = 'globalTimeline';
@ -21,7 +22,7 @@ export default class extends Channel {
}
@autobind
private async onNote(note: any) {
private async onNote(note: PackedNote) {
if (note.visibility !== 'public') return;
// リプライなら再pack

View File

@ -2,6 +2,7 @@ import autobind from 'autobind-decorator';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
export default class extends Channel {
public readonly chName = 'hashtag';
@ -20,8 +21,8 @@ export default class extends Channel {
}
@autobind
private async onNote(note: any) {
const noteTags = note.tags.map((t: string) => t.toLowerCase());
private async onNote(note: PackedNote) {
const noteTags = note.tags ? note.tags.map((t: string) => t.toLowerCase()) : [];
const matched = this.q.some(tags => tags.every(tag => noteTags.includes(tag.toLowerCase())));
if (!matched) return;

View File

@ -2,6 +2,7 @@ import autobind from 'autobind-decorator';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
export default class extends Channel {
public readonly chName = 'homeTimeline';
@ -15,7 +16,7 @@ export default class extends Channel {
}
@autobind
private async onNote(note: any) {
private async onNote(note: PackedNote) {
// その投稿のユーザーをフォローしていなかったら弾く
if (this.user!.id !== note.userId && !this.following.includes(note.userId)) return;

View File

@ -3,6 +3,8 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import fetchMeta from '../../../../misc/fetch-meta';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { PackedUser } from '../../../../models/repositories/user';
export default class extends Channel {
public readonly chName = 'hybridTimeline';
@ -19,12 +21,12 @@ export default class extends Channel {
}
@autobind
private async onNote(note: any) {
private async onNote(note: PackedNote) {
// 自分自身の投稿 または その投稿のユーザーをフォローしている または 全体公開のローカルの投稿 の場合だけ
if (!(
this.user!.id === note.userId ||
this.following.includes(note.userId) ||
(note.user.host == null && note.visibility === 'public')
((note.user as PackedUser).host == null && note.visibility === 'public')
)) return;
if (['followers', 'specified'].includes(note.visibility)) {

View File

@ -3,6 +3,8 @@ import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import Channel from '../channel';
import fetchMeta from '../../../../misc/fetch-meta';
import { Notes } from '../../../../models';
import { PackedNote } from '../../../../models/repositories/note';
import { PackedUser } from '../../../../models/repositories/user';
export default class extends Channel {
public readonly chName = 'localTimeline';
@ -21,8 +23,8 @@ export default class extends Channel {
}
@autobind
private async onNote(note: any) {
if (note.user.host !== null) return;
private async onNote(note: PackedNote) {
if ((note.user as PackedUser).host !== null) return;
if (note.visibility === 'home') return;
if (['followers', 'specified'].includes(note.visibility)) {

View File

@ -3,6 +3,7 @@ import Channel from '../channel';
import { Notes, UserListJoinings } from '../../../../models';
import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
import { User } from '../../../../models/entities/user';
import { PackedNote } from '../../../../models/repositories/note';
export default class extends Channel {
public readonly chName = 'userList';
@ -38,7 +39,7 @@ export default class extends Channel {
}
@autobind
private async onNote(note: any) {
private async onNote(note: PackedNote) {
if (!this.listUsers.includes(note.userId)) return;
if (['followers', 'specified'].includes(note.visibility)) {