From 952789cc1eb77e2f2d54b489c016b56bac812ab7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 27 Jun 2019 18:04:09 +0900 Subject: Use as const #5089 --- src/server/api/endpoints/app/create.ts | 5 +-- src/server/api/endpoints/app/show.ts | 5 +-- src/server/api/endpoints/auth/session/generate.ts | 13 +++--- src/server/api/endpoints/auth/session/userkey.ts | 13 +++--- src/server/api/endpoints/blocking/list.ts | 9 ++-- src/server/api/endpoints/drive.ts | 13 +++--- src/server/api/endpoints/drive/files.ts | 9 ++-- .../api/endpoints/drive/files/attached-notes.ts | 9 ++-- .../api/endpoints/drive/files/check-existence.ts | 5 +-- src/server/api/endpoints/drive/files/create.ts | 5 +-- .../api/endpoints/drive/files/find-by-hash.ts | 9 ++-- src/server/api/endpoints/drive/files/find.ts | 9 ++-- src/server/api/endpoints/drive/files/show.ts | 5 +-- src/server/api/endpoints/drive/folders.ts | 9 ++-- src/server/api/endpoints/drive/folders/find.ts | 9 ++-- src/server/api/endpoints/drive/folders/show.ts | 5 +-- src/server/api/endpoints/drive/stream.ts | 9 ++-- src/server/api/endpoints/hashtags/list.ts | 9 ++-- src/server/api/endpoints/hashtags/search.ts | 9 ++-- src/server/api/endpoints/hashtags/show.ts | 5 +-- src/server/api/endpoints/hashtags/trend.ts | 25 ++++++----- src/server/api/endpoints/hashtags/users.ts | 9 ++-- src/server/api/endpoints/i.ts | 5 +-- src/server/api/endpoints/i/favorites.ts | 9 ++-- src/server/api/endpoints/i/notifications.ts | 9 ++-- src/server/api/endpoints/messaging/history.ts | 9 ++-- src/server/api/endpoints/messaging/messages.ts | 9 ++-- .../api/endpoints/messaging/messages/create.ts | 5 +-- src/server/api/endpoints/meta.ts | 49 +++++++++++----------- src/server/api/endpoints/mute/list.ts | 9 ++-- src/server/api/endpoints/notes.ts | 9 ++-- src/server/api/endpoints/notes/children.ts | 9 ++-- src/server/api/endpoints/notes/conversation.ts | 9 ++-- src/server/api/endpoints/notes/create.ts | 9 ++-- src/server/api/endpoints/notes/featured.ts | 9 ++-- src/server/api/endpoints/notes/global-timeline.ts | 9 ++-- src/server/api/endpoints/notes/hybrid-timeline.ts | 9 ++-- src/server/api/endpoints/notes/local-timeline.ts | 9 ++-- src/server/api/endpoints/notes/mentions.ts | 9 ++-- src/server/api/endpoints/notes/reactions.ts | 9 ++-- src/server/api/endpoints/notes/renotes.ts | 9 ++-- src/server/api/endpoints/notes/replies.ts | 9 ++-- src/server/api/endpoints/notes/search-by-tag.ts | 9 ++-- src/server/api/endpoints/notes/search.ts | 9 ++-- src/server/api/endpoints/notes/show.ts | 5 +-- src/server/api/endpoints/notes/timeline.ts | 9 ++-- .../api/endpoints/notes/user-list-timeline.ts | 9 ++-- src/server/api/endpoints/pages/create.ts | 5 +-- src/server/api/endpoints/pages/show.ts | 5 +-- src/server/api/endpoints/pinned-users.ts | 9 ++-- src/server/api/endpoints/stats.ts | 25 ++++++----- src/server/api/endpoints/users.ts | 9 ++-- src/server/api/endpoints/users/followers.ts | 9 ++-- src/server/api/endpoints/users/following.ts | 9 ++-- .../users/get-frequently-replied-users.ts | 9 ++-- src/server/api/endpoints/users/groups/create.ts | 5 +-- src/server/api/endpoints/users/groups/joined.ts | 9 ++-- src/server/api/endpoints/users/groups/owned.ts | 9 ++-- src/server/api/endpoints/users/groups/show.ts | 5 +-- src/server/api/endpoints/users/groups/transfer.ts | 5 +-- src/server/api/endpoints/users/groups/update.ts | 5 +-- src/server/api/endpoints/users/lists/create.ts | 5 +-- src/server/api/endpoints/users/lists/list.ts | 9 ++-- src/server/api/endpoints/users/lists/show.ts | 5 +-- src/server/api/endpoints/users/notes.ts | 9 ++-- src/server/api/endpoints/users/recommendation.ts | 9 ++-- src/server/api/endpoints/users/search.ts | 9 ++-- src/server/api/endpoints/users/show.ts | 5 +-- 68 files changed, 276 insertions(+), 344 deletions(-) (limited to 'src/server/api') diff --git a/src/server/api/endpoints/app/create.ts b/src/server/api/endpoints/app/create.ts index 833d5060c5..81c851f3a3 100644 --- a/src/server/api/endpoints/app/create.ts +++ b/src/server/api/endpoints/app/create.ts @@ -4,7 +4,6 @@ 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'], @@ -53,8 +52,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'App', }, }; diff --git a/src/server/api/endpoints/app/show.ts b/src/server/api/endpoints/app/show.ts index e7d3e84388..2c8cdbe396 100644 --- a/src/server/api/endpoints/app/show.ts +++ b/src/server/api/endpoints/app/show.ts @@ -3,7 +3,6 @@ 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'], @@ -15,8 +14,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'App', }, diff --git a/src/server/api/endpoints/auth/session/generate.ts b/src/server/api/endpoints/auth/session/generate.ts index 9bf27c8e77..b38c275deb 100644 --- a/src/server/api/endpoints/auth/session/generate.ts +++ b/src/server/api/endpoints/auth/session/generate.ts @@ -5,7 +5,6 @@ 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'], @@ -28,17 +27,17 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { token: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'セッションのトークン' }, url: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, format: 'url', description: 'セッションのURL' }, diff --git a/src/server/api/endpoints/auth/session/userkey.ts b/src/server/api/endpoints/auth/session/userkey.ts index b7a58c4750..1dc78eeabd 100644 --- a/src/server/api/endpoints/auth/session/userkey.ts +++ b/src/server/api/endpoints/auth/session/userkey.ts @@ -3,7 +3,6 @@ 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'], @@ -29,18 +28,18 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { accessToken: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'ユーザーのアクセストークン', }, user: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', description: '認証したユーザー' }, diff --git a/src/server/api/endpoints/blocking/list.ts b/src/server/api/endpoints/blocking/list.ts index 5ff1dc0c49..c99ba09df0 100644 --- a/src/server/api/endpoints/blocking/list.ts +++ b/src/server/api/endpoints/blocking/list.ts @@ -3,7 +3,6 @@ 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: { @@ -33,11 +32,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Blocking', } }, diff --git a/src/server/api/endpoints/drive.ts b/src/server/api/endpoints/drive.ts index 4d4516bd80..bb85bab148 100644 --- a/src/server/api/endpoints/drive.ts +++ b/src/server/api/endpoints/drive.ts @@ -1,7 +1,6 @@ import define from '../define'; import { fetchMeta } from '../../../misc/fetch-meta'; import { DriveFiles } from '../../../models'; -import { types, bool } from '../../../misc/schema'; export const meta = { desc: { @@ -16,16 +15,16 @@ export const meta = { kind: 'read:drive', res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { capacity: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, }, usage: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, } } } diff --git a/src/server/api/endpoints/drive/files.ts b/src/server/api/endpoints/drive/files.ts index d10c2a3ef4..77cefdfbe3 100644 --- a/src/server/api/endpoints/drive/files.ts +++ b/src/server/api/endpoints/drive/files.ts @@ -3,7 +3,6 @@ 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: { @@ -42,11 +41,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFile', } }, diff --git a/src/server/api/endpoints/drive/files/attached-notes.ts b/src/server/api/endpoints/drive/files/attached-notes.ts index f770bc7136..2b84e114b3 100644 --- a/src/server/api/endpoints/drive/files/attached-notes.ts +++ b/src/server/api/endpoints/drive/files/attached-notes.ts @@ -3,7 +3,6 @@ import { ID } from '../../../../../misc/cafy-id'; import define from '../../../define'; import { ApiError } from '../../../error'; import { DriveFiles, Notes } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { stability: 'stable', @@ -30,11 +29,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/drive/files/check-existence.ts b/src/server/api/endpoints/drive/files/check-existence.ts index ab19566f1c..a6cd14caf2 100644 --- a/src/server/api/endpoints/drive/files/check-existence.ts +++ b/src/server/api/endpoints/drive/files/check-existence.ts @@ -1,7 +1,6 @@ import $ from 'cafy'; import define from '../../../define'; import { DriveFiles } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -25,8 +24,8 @@ export const meta = { }, res: { - type: types.boolean, - optional: bool.false, nullable: bool.false, + type: 'boolean' as const, + optional: false as const, nullable: false as const, }, }; diff --git a/src/server/api/endpoints/drive/files/create.ts b/src/server/api/endpoints/drive/files/create.ts index 0f81a1da99..664a2b87b2 100644 --- a/src/server/api/endpoints/drive/files/create.ts +++ b/src/server/api/endpoints/drive/files/create.ts @@ -6,7 +6,6 @@ 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: { @@ -57,8 +56,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFile', }, diff --git a/src/server/api/endpoints/drive/files/find-by-hash.ts b/src/server/api/endpoints/drive/files/find-by-hash.ts index d56e63bc59..84cc4f92b1 100644 --- a/src/server/api/endpoints/drive/files/find-by-hash.ts +++ b/src/server/api/endpoints/drive/files/find-by-hash.ts @@ -1,7 +1,6 @@ import $ from 'cafy'; import define from '../../../define'; import { DriveFiles } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -24,11 +23,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFile', } }, diff --git a/src/server/api/endpoints/drive/files/find.ts b/src/server/api/endpoints/drive/files/find.ts index 82b9a97b6d..732596a33f 100644 --- a/src/server/api/endpoints/drive/files/find.ts +++ b/src/server/api/endpoints/drive/files/find.ts @@ -2,7 +2,6 @@ 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, @@ -26,11 +25,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFile', } }, diff --git a/src/server/api/endpoints/drive/files/show.ts b/src/server/api/endpoints/drive/files/show.ts index 8e74361f9c..4384b2114d 100644 --- a/src/server/api/endpoints/drive/files/show.ts +++ b/src/server/api/endpoints/drive/files/show.ts @@ -4,7 +4,6 @@ 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', @@ -39,8 +38,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFile', }, diff --git a/src/server/api/endpoints/drive/folders.ts b/src/server/api/endpoints/drive/folders.ts index dc3174cd2a..e2d22e7081 100644 --- a/src/server/api/endpoints/drive/folders.ts +++ b/src/server/api/endpoints/drive/folders.ts @@ -3,7 +3,6 @@ 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: { @@ -38,11 +37,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFolder', } }, diff --git a/src/server/api/endpoints/drive/folders/find.ts b/src/server/api/endpoints/drive/folders/find.ts index 0368d026c3..04bec1b170 100644 --- a/src/server/api/endpoints/drive/folders/find.ts +++ b/src/server/api/endpoints/drive/folders/find.ts @@ -2,7 +2,6 @@ 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'], @@ -26,11 +25,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFolder', } }, diff --git a/src/server/api/endpoints/drive/folders/show.ts b/src/server/api/endpoints/drive/folders/show.ts index a020b46aa9..f48f21d730 100644 --- a/src/server/api/endpoints/drive/folders/show.ts +++ b/src/server/api/endpoints/drive/folders/show.ts @@ -3,7 +3,6 @@ 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', @@ -30,8 +29,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFolder', }, diff --git a/src/server/api/endpoints/drive/stream.ts b/src/server/api/endpoints/drive/stream.ts index f75c4273c3..b93ee11a14 100644 --- a/src/server/api/endpoints/drive/stream.ts +++ b/src/server/api/endpoints/drive/stream.ts @@ -3,7 +3,6 @@ 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'], @@ -32,11 +31,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'DriveFile', } }, diff --git a/src/server/api/endpoints/hashtags/list.ts b/src/server/api/endpoints/hashtags/list.ts index 9023f11913..9bc2677793 100644 --- a/src/server/api/endpoints/hashtags/list.ts +++ b/src/server/api/endpoints/hashtags/list.ts @@ -1,7 +1,6 @@ import $ from 'cafy'; import define from '../../define'; import { Hashtags } from '../../../../models'; -import { types, bool } from '../../../../misc/schema'; export const meta = { tags: ['hashtags'], @@ -48,11 +47,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Hashtag', } }, diff --git a/src/server/api/endpoints/hashtags/search.ts b/src/server/api/endpoints/hashtags/search.ts index 0d2704d01c..7caaf34846 100644 --- a/src/server/api/endpoints/hashtags/search.ts +++ b/src/server/api/endpoints/hashtags/search.ts @@ -1,7 +1,6 @@ import $ from 'cafy'; import define from '../../define'; import { Hashtags } from '../../../../models'; -import { types, bool } from '../../../../misc/schema'; export const meta = { desc: { @@ -38,11 +37,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, } }, }; diff --git a/src/server/api/endpoints/hashtags/show.ts b/src/server/api/endpoints/hashtags/show.ts index 72a4cc7c87..5de906fb1f 100644 --- a/src/server/api/endpoints/hashtags/show.ts +++ b/src/server/api/endpoints/hashtags/show.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import define from '../../define'; import { ApiError } from '../../error'; import { Hashtags } from '../../../../models'; -import { types, bool } from '../../../../misc/schema'; export const meta = { desc: { @@ -24,8 +23,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Hashtag', }, diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts index 53a3514718..3154461e5a 100644 --- a/src/server/api/endpoints/hashtags/trend.ts +++ b/src/server/api/endpoints/hashtags/trend.ts @@ -2,7 +2,6 @@ import define from '../../define'; import { fetchMeta } from '../../../../misc/fetch-meta'; import { Notes } from '../../../../models'; import { Note } from '../../../../models/entities/note'; -import { types, bool } from '../../../../misc/schema'; /* トレンドに載るためには「『直近a分間のユニーク投稿数が今からa分前~今からb分前の間のユニーク投稿数のn倍以上』のハッシュタグの上位5位以内に入る」ことが必要 @@ -24,27 +23,27 @@ export const meta = { requireCredential: false, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { tag: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, }, chart: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, } }, usersCount: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, } } } diff --git a/src/server/api/endpoints/hashtags/users.ts b/src/server/api/endpoints/hashtags/users.ts index b842f9de64..59210f4604 100644 --- a/src/server/api/endpoints/hashtags/users.ts +++ b/src/server/api/endpoints/hashtags/users.ts @@ -1,7 +1,6 @@ import $ from 'cafy'; import define from '../../define'; import { Users } from '../../../../models'; -import { types, bool } from '../../../../misc/schema'; export const meta = { requireCredential: false, @@ -48,11 +47,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', } }, diff --git a/src/server/api/endpoints/i.ts b/src/server/api/endpoints/i.ts index 4ecd507e16..20a0c604f6 100644 --- a/src/server/api/endpoints/i.ts +++ b/src/server/api/endpoints/i.ts @@ -1,6 +1,5 @@ import define from '../define'; import { Users } from '../../../models'; -import { types, bool } from '../../../misc/schema'; export const meta = { stability: 'stable', @@ -16,8 +15,8 @@ export const meta = { params: {}, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', }, }; diff --git a/src/server/api/endpoints/i/favorites.ts b/src/server/api/endpoints/i/favorites.ts index d1e90dd15c..1bbc16256a 100644 --- a/src/server/api/endpoints/i/favorites.ts +++ b/src/server/api/endpoints/i/favorites.ts @@ -3,7 +3,6 @@ import { ID } from '../../../../misc/cafy-id'; import define from '../../define'; import { NoteFavorites } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; -import { types, bool } from '../../../../misc/schema'; export const meta = { desc: { @@ -33,11 +32,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'NoteFavorite', } }, diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts index 41513e5daa..aa72e9a176 100644 --- a/src/server/api/endpoints/i/notifications.ts +++ b/src/server/api/endpoints/i/notifications.ts @@ -4,7 +4,6 @@ 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: { @@ -54,11 +53,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Notification', } }, diff --git a/src/server/api/endpoints/messaging/history.ts b/src/server/api/endpoints/messaging/history.ts index 833ec37e4c..2c143c26b5 100644 --- a/src/server/api/endpoints/messaging/history.ts +++ b/src/server/api/endpoints/messaging/history.ts @@ -3,7 +3,6 @@ import define from '../../define'; import { MessagingMessage } from '../../../../models/entities/messaging-message'; import { MessagingMessages, Mutings, UserGroupJoinings } from '../../../../models'; import { Brackets } from 'typeorm'; -import { types, bool } from '../../../../misc/schema'; export const meta = { desc: { @@ -30,11 +29,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'MessagingMessage', } }, diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts index ffd58c714e..b0b3e20d02 100644 --- a/src/server/api/endpoints/messaging/messages.ts +++ b/src/server/api/endpoints/messaging/messages.ts @@ -5,7 +5,6 @@ import { ApiError } from '../../error'; import { getUser } from '../../common/getters'; import { MessagingMessages, UserGroups, UserGroupJoinings } from '../../../../models'; import { makePaginationQuery } from '../../common/make-pagination-query'; -import { types, bool } from '../../../../misc/schema'; import { Brackets } from 'typeorm'; import { readUserMessagingMessage, readGroupMessagingMessage } from '../../common/read-messaging-message'; @@ -58,11 +57,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'MessagingMessage', } }, diff --git a/src/server/api/endpoints/messaging/messages/create.ts b/src/server/api/endpoints/messaging/messages/create.ts index feffc9a0c6..d0c1ee4941 100644 --- a/src/server/api/endpoints/messaging/messages/create.ts +++ b/src/server/api/endpoints/messaging/messages/create.ts @@ -9,7 +9,6 @@ import { getUser } from '../../../common/getters'; import { MessagingMessages, DriveFiles, Mutings, UserGroups, UserGroupJoinings } from '../../../../../models'; import { MessagingMessage } from '../../../../../models/entities/messaging-message'; import { genId } from '../../../../../misc/gen-id'; -import { types, bool } from '../../../../../misc/schema'; import { User } from '../../../../../models/entities/user'; import { UserGroup } from '../../../../../models/entities/user-group'; import { Not } from 'typeorm'; @@ -53,8 +52,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'MessagingMessage', }, diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index 1aa9a855dd..a3390a011d 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -5,7 +5,6 @@ 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'; import { getConnection } from 'typeorm'; import redis from '../../../db/redis'; @@ -29,40 +28,40 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { version: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'The version of Misskey of this instance.', example: pkg.version }, name: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'The name of this instance.', }, description: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'The description of this instance.', }, announcements: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { title: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'The title of the announcement.', }, text: { - type: types.string, - optional: bool.false, nullable: bool.false, + type: 'string' as const, + optional: false as const, nullable: false as const, description: 'The text of the announcement. (can be HTML)', }, } @@ -70,23 +69,23 @@ export const meta = { description: 'The announcements of this instance.', }, disableRegistration: { - type: types.boolean, - optional: bool.false, nullable: bool.false, + type: 'boolean' as const, + optional: false as const, nullable: false as const, description: 'Whether disabled open registration.', }, disableLocalTimeline: { - type: types.boolean, - optional: bool.false, nullable: bool.false, + type: 'boolean' as const, + optional: false as const, nullable: false as const, description: 'Whether disabled LTL and STL.', }, disableGlobalTimeline: { - type: types.boolean, - optional: bool.false, nullable: bool.false, + type: 'boolean' as const, + optional: false as const, nullable: false as const, description: 'Whether disabled GTL.', }, enableEmojiReaction: { - type: types.boolean, - optional: bool.false, nullable: bool.false, + type: 'boolean' as const, + optional: false as const, nullable: false as const, description: 'Whether enabled emoji reaction.', }, } diff --git a/src/server/api/endpoints/mute/list.ts b/src/server/api/endpoints/mute/list.ts index f9ea380c76..1afc120f5f 100644 --- a/src/server/api/endpoints/mute/list.ts +++ b/src/server/api/endpoints/mute/list.ts @@ -3,7 +3,6 @@ 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: { @@ -33,11 +32,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Muting', } }, diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts index 7aa19c9a2b..fab8455d78 100644 --- a/src/server/api/endpoints/notes.ts +++ b/src/server/api/endpoints/notes.ts @@ -3,7 +3,6 @@ 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: { @@ -63,11 +62,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/children.ts b/src/server/api/endpoints/notes/children.ts index e8861eafa1..bc8407f31c 100644 --- a/src/server/api/endpoints/notes/children.ts +++ b/src/server/api/endpoints/notes/children.ts @@ -6,7 +6,6 @@ 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: { @@ -42,11 +41,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/conversation.ts b/src/server/api/endpoints/notes/conversation.ts index acd3ac75ef..245d427923 100644 --- a/src/server/api/endpoints/notes/conversation.ts +++ b/src/server/api/endpoints/notes/conversation.ts @@ -5,7 +5,6 @@ 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: { @@ -38,11 +37,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 46db274581..1650de9071 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -10,7 +10,6 @@ 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; @@ -175,12 +174,12 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { createdNote: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', description: '作成した投稿' } diff --git a/src/server/api/endpoints/notes/featured.ts b/src/server/api/endpoints/notes/featured.ts index 64750815b0..0a1d8668b0 100644 --- a/src/server/api/endpoints/notes/featured.ts +++ b/src/server/api/endpoints/notes/featured.ts @@ -2,7 +2,6 @@ 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: { @@ -25,11 +24,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts index f46fa208df..8654cf889a 100644 --- a/src/server/api/endpoints/notes/global-timeline.ts +++ b/src/server/api/endpoints/notes/global-timeline.ts @@ -7,7 +7,6 @@ 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: { @@ -47,11 +46,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/hybrid-timeline.ts b/src/server/api/endpoints/notes/hybrid-timeline.ts index 7be13fc47f..8c4c7a60b9 100644 --- a/src/server/api/endpoints/notes/hybrid-timeline.ts +++ b/src/server/api/endpoints/notes/hybrid-timeline.ts @@ -9,7 +9,6 @@ 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: { @@ -90,11 +89,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts index 73cbebace2..c688b9325e 100644 --- a/src/server/api/endpoints/notes/local-timeline.ts +++ b/src/server/api/endpoints/notes/local-timeline.ts @@ -9,7 +9,6 @@ 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: { @@ -64,11 +63,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts index 02e44492ba..fd3767f632 100644 --- a/src/server/api/endpoints/notes/mentions.ts +++ b/src/server/api/endpoints/notes/mentions.ts @@ -7,7 +7,6 @@ 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: { @@ -44,11 +43,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/reactions.ts b/src/server/api/endpoints/notes/reactions.ts index 0773b4faa2..7bea24d316 100644 --- a/src/server/api/endpoints/notes/reactions.ts +++ b/src/server/api/endpoints/notes/reactions.ts @@ -4,7 +4,6 @@ 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: { @@ -45,11 +44,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'NoteReaction', } }, diff --git a/src/server/api/endpoints/notes/renotes.ts b/src/server/api/endpoints/notes/renotes.ts index 00dfac3770..a5db706e32 100644 --- a/src/server/api/endpoints/notes/renotes.ts +++ b/src/server/api/endpoints/notes/renotes.ts @@ -7,7 +7,6 @@ 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: { @@ -43,11 +42,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index 5fb0fd989f..cd38d41652 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -5,7 +5,6 @@ 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: { @@ -47,11 +46,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/search-by-tag.ts b/src/server/api/endpoints/notes/search-by-tag.ts index 0b49f896ad..7f53b26995 100644 --- a/src/server/api/endpoints/notes/search-by-tag.ts +++ b/src/server/api/endpoints/notes/search-by-tag.ts @@ -6,7 +6,6 @@ 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: { @@ -82,11 +81,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/search.ts b/src/server/api/endpoints/notes/search.ts index 65ce20074a..d3fb33c420 100644 --- a/src/server/api/endpoints/notes/search.ts +++ b/src/server/api/endpoints/notes/search.ts @@ -4,7 +4,6 @@ import define from '../../define'; import { ApiError } from '../../error'; import { Notes } from '../../../../models'; import { In } from 'typeorm'; -import { types, bool } from '../../../../misc/schema'; import { ID } from '../../../../misc/cafy-id'; export const meta = { @@ -44,11 +43,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/show.ts b/src/server/api/endpoints/notes/show.ts index 54b420813d..75abbae55f 100644 --- a/src/server/api/endpoints/notes/show.ts +++ b/src/server/api/endpoints/notes/show.ts @@ -4,7 +4,6 @@ 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', @@ -29,8 +28,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', }, diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts index f9442f8b90..25876f655a 100644 --- a/src/server/api/endpoints/notes/timeline.ts +++ b/src/server/api/endpoints/notes/timeline.ts @@ -7,7 +7,6 @@ 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: { @@ -89,11 +88,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/notes/user-list-timeline.ts b/src/server/api/endpoints/notes/user-list-timeline.ts index c16018d434..f66221537d 100644 --- a/src/server/api/endpoints/notes/user-list-timeline.ts +++ b/src/server/api/endpoints/notes/user-list-timeline.ts @@ -6,7 +6,6 @@ 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: { @@ -95,11 +94,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/pages/create.ts b/src/server/api/endpoints/pages/create.ts index e6b813648b..ffe0d38ea6 100644 --- a/src/server/api/endpoints/pages/create.ts +++ b/src/server/api/endpoints/pages/create.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import * as ms from 'ms'; import define from '../../define'; import { ID } from '../../../../misc/cafy-id'; -import { types, bool } from '../../../../misc/schema'; import { Pages, DriveFiles } from '../../../../models'; import { genId } from '../../../../misc/gen-id'; import { Page } from '../../../../models/entities/page'; @@ -61,8 +60,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Page', }, diff --git a/src/server/api/endpoints/pages/show.ts b/src/server/api/endpoints/pages/show.ts index e3d6e6a15f..84808418f3 100644 --- a/src/server/api/endpoints/pages/show.ts +++ b/src/server/api/endpoints/pages/show.ts @@ -2,7 +2,6 @@ import $ from 'cafy'; import define from '../../define'; import { ApiError } from '../../error'; import { Pages, Users } from '../../../../models'; -import { types, bool } from '../../../../misc/schema'; import { ID } from '../../../../misc/cafy-id'; import { Page } from '../../../../models/entities/page'; @@ -34,8 +33,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Page', }, diff --git a/src/server/api/endpoints/pinned-users.ts b/src/server/api/endpoints/pinned-users.ts index de0e17a2ec..853e1cd4b8 100644 --- a/src/server/api/endpoints/pinned-users.ts +++ b/src/server/api/endpoints/pinned-users.ts @@ -1,6 +1,5 @@ import define from '../define'; import { Users } from '../../../models'; -import { types, bool } from '../../../misc/schema'; import { fetchMeta } from '../../../misc/fetch-meta'; import parseAcct from '../../../misc/acct/parse'; import { User } from '../../../models/entities/user'; @@ -14,11 +13,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', } }, diff --git a/src/server/api/endpoints/stats.ts b/src/server/api/endpoints/stats.ts index 4dca62445f..c86d893d5e 100644 --- a/src/server/api/endpoints/stats.ts +++ b/src/server/api/endpoints/stats.ts @@ -1,7 +1,6 @@ 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, @@ -16,32 +15,32 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, properties: { notesCount: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, description: 'The count of all (local/remote) notes of this instance.', }, originalNotesCount: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, description: 'The count of all local notes of this instance.', }, usersCount: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, description: 'The count of all (local/remote) accounts of this instance.', }, originalUsersCount: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, description: 'The count of all local accounts of this instance.', }, instances: { - type: types.number, - optional: bool.false, nullable: bool.false, + type: 'number' as const, + optional: false as const, nullable: false as const, description: 'The count of federated instances.', }, } diff --git a/src/server/api/endpoints/users.ts b/src/server/api/endpoints/users.ts index 539f2ef897..93cf01a6f8 100644 --- a/src/server/api/endpoints/users.ts +++ b/src/server/api/endpoints/users.ts @@ -2,7 +2,6 @@ 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,11 +52,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', } }, diff --git a/src/server/api/endpoints/users/followers.ts b/src/server/api/endpoints/users/followers.ts index 465b71e2e6..68c32fe983 100644 --- a/src/server/api/endpoints/users/followers.ts +++ b/src/server/api/endpoints/users/followers.ts @@ -5,7 +5,6 @@ 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: { @@ -49,11 +48,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Following', } }, diff --git a/src/server/api/endpoints/users/following.ts b/src/server/api/endpoints/users/following.ts index 2a7748ac64..eb699b2903 100644 --- a/src/server/api/endpoints/users/following.ts +++ b/src/server/api/endpoints/users/following.ts @@ -5,7 +5,6 @@ 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: { @@ -49,11 +48,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Following', } }, diff --git a/src/server/api/endpoints/users/get-frequently-replied-users.ts b/src/server/api/endpoints/users/get-frequently-replied-users.ts index 24d1bd194c..1a17b488f0 100644 --- a/src/server/api/endpoints/users/get-frequently-replied-users.ts +++ b/src/server/api/endpoints/users/get-frequently-replied-users.ts @@ -6,7 +6,6 @@ import { ApiError } from '../../error'; import { getUser } from '../../common/getters'; import { Not, In, IsNull } from 'typeorm'; import { Notes, Users } from '../../../../models'; -import { types, bool } from '../../../../misc/schema'; export const meta = { tags: ['users'], @@ -29,11 +28,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', } }, diff --git a/src/server/api/endpoints/users/groups/create.ts b/src/server/api/endpoints/users/groups/create.ts index ee6cade8d0..2a6e5135e5 100644 --- a/src/server/api/endpoints/users/groups/create.ts +++ b/src/server/api/endpoints/users/groups/create.ts @@ -3,7 +3,6 @@ import define from '../../../define'; import { UserGroups, UserGroupJoinings } from '../../../../../models'; import { genId } from '../../../../../misc/gen-id'; import { UserGroup } from '../../../../../models/entities/user-group'; -import { types, bool } from '../../../../../misc/schema'; import { UserGroupJoining } from '../../../../../models/entities/user-group-joining'; export const meta = { @@ -25,8 +24,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserGroup', }, }; diff --git a/src/server/api/endpoints/users/groups/joined.ts b/src/server/api/endpoints/users/groups/joined.ts index 97d168e527..c60ba57c09 100644 --- a/src/server/api/endpoints/users/groups/joined.ts +++ b/src/server/api/endpoints/users/groups/joined.ts @@ -1,6 +1,5 @@ import define from '../../../define'; import { UserGroups, UserGroupJoinings } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; import { Not, In } from 'typeorm'; export const meta = { @@ -15,11 +14,11 @@ export const meta = { kind: 'read:user-groups', res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserGroup', } }, diff --git a/src/server/api/endpoints/users/groups/owned.ts b/src/server/api/endpoints/users/groups/owned.ts index 6cf39a142b..e2c0bf2fc1 100644 --- a/src/server/api/endpoints/users/groups/owned.ts +++ b/src/server/api/endpoints/users/groups/owned.ts @@ -1,6 +1,5 @@ import define from '../../../define'; import { UserGroups } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -14,11 +13,11 @@ export const meta = { kind: 'read:user-groups', res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserGroup', } }, diff --git a/src/server/api/endpoints/users/groups/show.ts b/src/server/api/endpoints/users/groups/show.ts index 4f8374a222..643f1acf7a 100644 --- a/src/server/api/endpoints/users/groups/show.ts +++ b/src/server/api/endpoints/users/groups/show.ts @@ -3,7 +3,6 @@ import { ID } from '../../../../../misc/cafy-id'; import define from '../../../define'; import { ApiError } from '../../../error'; import { UserGroups, UserGroupJoinings } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -24,8 +23,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserGroup', }, diff --git a/src/server/api/endpoints/users/groups/transfer.ts b/src/server/api/endpoints/users/groups/transfer.ts index b4284ab484..012f9f4ef3 100644 --- a/src/server/api/endpoints/users/groups/transfer.ts +++ b/src/server/api/endpoints/users/groups/transfer.ts @@ -4,7 +4,6 @@ import define from '../../../define'; import { ApiError } from '../../../error'; import { getUser } from '../../../common/getters'; import { UserGroups, UserGroupJoinings } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -33,8 +32,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserGroup', }, diff --git a/src/server/api/endpoints/users/groups/update.ts b/src/server/api/endpoints/users/groups/update.ts index bc974621a3..2fc0a803a1 100644 --- a/src/server/api/endpoints/users/groups/update.ts +++ b/src/server/api/endpoints/users/groups/update.ts @@ -3,7 +3,6 @@ import { ID } from '../../../../../misc/cafy-id'; import define from '../../../define'; import { ApiError } from '../../../error'; import { UserGroups } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -36,8 +35,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserGroup', }, diff --git a/src/server/api/endpoints/users/lists/create.ts b/src/server/api/endpoints/users/lists/create.ts index 79efffbf9e..28af3c8d86 100644 --- a/src/server/api/endpoints/users/lists/create.ts +++ b/src/server/api/endpoints/users/lists/create.ts @@ -3,7 +3,6 @@ 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: { @@ -24,8 +23,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserList', }, }; diff --git a/src/server/api/endpoints/users/lists/list.ts b/src/server/api/endpoints/users/lists/list.ts index 684086b5c6..7b89d34314 100644 --- a/src/server/api/endpoints/users/lists/list.ts +++ b/src/server/api/endpoints/users/lists/list.ts @@ -1,6 +1,5 @@ import define from '../../../define'; import { UserLists } from '../../../../../models'; -import { types, bool } from '../../../../../misc/schema'; export const meta = { desc: { @@ -14,11 +13,11 @@ export const meta = { kind: 'read:account', res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserList', } }, diff --git a/src/server/api/endpoints/users/lists/show.ts b/src/server/api/endpoints/users/lists/show.ts index 395f9352d4..01d03d1bfb 100644 --- a/src/server/api/endpoints/users/lists/show.ts +++ b/src/server/api/endpoints/users/lists/show.ts @@ -3,7 +3,6 @@ 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: { @@ -24,8 +23,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'UserList', }, diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts index fdc50e4dae..ef564b3c34 100644 --- a/src/server/api/endpoints/users/notes.ts +++ b/src/server/api/endpoints/users/notes.ts @@ -8,7 +8,6 @@ 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: { @@ -120,11 +119,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'Note', } }, diff --git a/src/server/api/endpoints/users/recommendation.ts b/src/server/api/endpoints/users/recommendation.ts index 38b420c332..73d8fe6208 100644 --- a/src/server/api/endpoints/users/recommendation.ts +++ b/src/server/api/endpoints/users/recommendation.ts @@ -3,7 +3,6 @@ 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: { @@ -29,11 +28,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', } }, diff --git a/src/server/api/endpoints/users/search.ts b/src/server/api/endpoints/users/search.ts index 5c413defbc..9aa9e398e3 100644 --- a/src/server/api/endpoints/users/search.ts +++ b/src/server/api/endpoints/users/search.ts @@ -2,7 +2,6 @@ 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: { @@ -55,11 +54,11 @@ export const meta = { }, res: { - type: types.array, - optional: bool.false, nullable: bool.false, + type: 'array' as const, + optional: false as const, nullable: false as const, items: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', } }, diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts index 820c44e81b..30660aed3a 100644 --- a/src/server/api/endpoints/users/show.ts +++ b/src/server/api/endpoints/users/show.ts @@ -6,7 +6,6 @@ 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: { @@ -43,8 +42,8 @@ export const meta = { }, res: { - type: types.object, - optional: bool.false, nullable: bool.false, + type: 'object' as const, + optional: false as const, nullable: false as const, ref: 'User', }, -- cgit v1.2.3-freya From a8379e3bc9b506aaff99deb02bc6b41811734420 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 28 Jun 2019 16:38:48 +0900 Subject: Use as const #5089 --- src/models/id.ts | 2 +- src/server/api/endpoints/users/show.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/server/api') diff --git a/src/models/id.ts b/src/models/id.ts index be2cccfe3b..cdb8259073 100644 --- a/src/models/id.ts +++ b/src/models/id.ts @@ -1,4 +1,4 @@ export const id = () => ({ - type: 'varchar' as 'varchar', + type: 'varchar' as const, length: 32 }); diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts index 30660aed3a..d17dd51c0a 100644 --- a/src/server/api/endpoints/users/show.ts +++ b/src/server/api/endpoints/users/show.ts @@ -52,7 +52,7 @@ export const meta = { message: 'Failed to resolve remote user.', code: 'FAILED_TO_RESOLVE_REMOTE_USER', id: 'ef7b9be4-9cba-4e6f-ab41-90ed171c7d3c', - kind: 'server' as 'server' + kind: 'server' as const }, noSuchUser: { -- cgit v1.2.3-freya From 0141affe056e2b7103f67088f6f5bdb276c8d5d3 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Fri, 28 Jun 2019 18:54:10 +0900 Subject: Fix: AP object / actor type (#5086) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * attributedToがArrayの場合などに対応 * attachment以外で来るDocument系のObjectに対応 * Renote, Reply 対応 * 表示をいい感じに * fix type * revert as const * Fix Note / Question type * attributedToのtypeで複合配列を想定する --- src/models/repositories/note.ts | 4 +-- src/remote/activitypub/kernel/announce/index.ts | 14 +++------ src/remote/activitypub/kernel/announce/note.ts | 15 +++++----- src/remote/activitypub/kernel/create/image.ts | 6 ---- src/remote/activitypub/kernel/create/index.ts | 19 +++--------- src/remote/activitypub/kernel/delete/index.ts | 26 ++++------------- src/remote/activitypub/models/note.ts | 33 ++++++++++----------- src/remote/activitypub/models/question.ts | 13 +++++++-- src/remote/activitypub/type.ts | 39 ++++++++++++++++++++++--- src/server/api/endpoints/ap/show.ts | 4 +-- 10 files changed, 86 insertions(+), 87 deletions(-) delete mode 100644 src/remote/activitypub/kernel/create/image.ts (limited to 'src/server/api') diff --git a/src/models/repositories/note.ts b/src/models/repositories/note.ts index 3ac490b001..03a50fecec 100644 --- a/src/models/repositories/note.ts +++ b/src/models/repositories/note.ts @@ -144,8 +144,8 @@ export class NoteRepository extends Repository { let text = note.text; - if (note.name) { - text = `【${note.name}】\n${note.text}`; + if (note.name && note.uri) { + text = `【${note.name}】\n${(note.text || '').trim()}\n${note.uri}`; } const reactionEmojis = unique(concat([note.emojis, Object.keys(note.reactions)])); diff --git a/src/remote/activitypub/kernel/announce/index.ts b/src/remote/activitypub/kernel/announce/index.ts index ebd5a27b92..68fce52e17 100644 --- a/src/remote/activitypub/kernel/announce/index.ts +++ b/src/remote/activitypub/kernel/announce/index.ts @@ -1,13 +1,13 @@ import Resolver from '../../resolver'; import { IRemoteUser } from '../../../../models/entities/user'; import announceNote from './note'; -import { IAnnounce, INote } from '../../type'; +import { IAnnounce, INote, validPost, getApId } from '../../type'; import { apLogger } from '../../logger'; const logger = apLogger; export default async (actor: IRemoteUser, activity: IAnnounce): Promise => { - const uri = activity.id || activity; + const uri = getApId(activity); logger.info(`Announce: ${uri}`); @@ -22,15 +22,9 @@ export default async (actor: IRemoteUser, activity: IAnnounce): Promise => throw e; } - switch (object.type) { - case 'Note': - case 'Question': - case 'Article': + if (validPost.includes(object.type)) { announceNote(resolver, actor, activity, object as INote); - break; - - default: + } else { logger.warn(`Unknown announce type: ${object.type}`); - break; } }; diff --git a/src/remote/activitypub/kernel/announce/note.ts b/src/remote/activitypub/kernel/announce/note.ts index 6843041475..2a07f50c8a 100644 --- a/src/remote/activitypub/kernel/announce/note.ts +++ b/src/remote/activitypub/kernel/announce/note.ts @@ -1,7 +1,7 @@ import Resolver from '../../resolver'; import post from '../../../../services/note/create'; import { IRemoteUser, User } from '../../../../models/entities/user'; -import { IAnnounce, INote } from '../../type'; +import { IAnnounce, INote, getApId, getApIds } from '../../type'; import { fetchNote, resolveNote } from '../../models/note'; import { resolvePerson } from '../../models/person'; import { apLogger } from '../../logger'; @@ -14,17 +14,13 @@ const logger = apLogger; * アナウンスアクティビティを捌きます */ export default async function(resolver: Resolver, actor: IRemoteUser, activity: IAnnounce, note: INote): Promise { - const uri = activity.id || activity; + const uri = getApId(activity); // アナウンサーが凍結されていたらスキップ if (actor.isSuspended) { return; } - if (typeof uri !== 'string') { - throw new Error('invalid announce'); - } - // アナウンス先をブロックしてたら中断 const meta = await fetchMeta(); if (meta.blockedHosts.includes(extractDbHost(uri))) return; @@ -52,11 +48,14 @@ export default async function(resolver: Resolver, actor: IRemoteUser, activity: logger.info(`Creating the (Re)Note: ${uri}`); //#region Visibility - const visibility = getVisibility(activity.to || [], activity.cc || [], actor); + const to = getApIds(activity.to); + const cc = getApIds(activity.cc); + + const visibility = getVisibility(to, cc, actor); let visibleUsers: User[] = []; if (visibility == 'specified') { - visibleUsers = await Promise.all((note.to || []).map(uri => resolvePerson(uri))); + visibleUsers = await Promise.all(to.map(uri => resolvePerson(uri))); } //#endergion diff --git a/src/remote/activitypub/kernel/create/image.ts b/src/remote/activitypub/kernel/create/image.ts deleted file mode 100644 index 7720e8f1bd..0000000000 --- a/src/remote/activitypub/kernel/create/image.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { IRemoteUser } from '../../../../models/entities/user'; -import { createImage } from '../../models/image'; - -export default async function(actor: IRemoteUser, image: any): Promise { - await createImage(image.url, actor); -} diff --git a/src/remote/activitypub/kernel/create/index.ts b/src/remote/activitypub/kernel/create/index.ts index 0326b591f8..a6fa2336f3 100644 --- a/src/remote/activitypub/kernel/create/index.ts +++ b/src/remote/activitypub/kernel/create/index.ts @@ -1,14 +1,13 @@ import Resolver from '../../resolver'; import { IRemoteUser } from '../../../../models/entities/user'; -import createImage from './image'; import createNote from './note'; -import { ICreate } from '../../type'; +import { ICreate, getApId, validPost } from '../../type'; import { apLogger } from '../../logger'; const logger = apLogger; export default async (actor: IRemoteUser, activity: ICreate): Promise => { - const uri = activity.id || activity; + const uri = getApId(activity); logger.info(`Create: ${uri}`); @@ -23,19 +22,9 @@ export default async (actor: IRemoteUser, activity: ICreate): Promise => { throw e; } - switch (object.type) { - case 'Image': - createImage(actor, object); - break; - - case 'Note': - case 'Question': - case 'Article': + if (validPost.includes(object.type)) { createNote(resolver, actor, object); - break; - - default: + } else { logger.warn(`Unknown type: ${object.type}`); - break; } }; diff --git a/src/remote/activitypub/kernel/delete/index.ts b/src/remote/activitypub/kernel/delete/index.ts index 199a6a6187..be7779e026 100644 --- a/src/remote/activitypub/kernel/delete/index.ts +++ b/src/remote/activitypub/kernel/delete/index.ts @@ -1,9 +1,8 @@ import Resolver from '../../resolver'; import deleteNote from './note'; import { IRemoteUser } from '../../../../models/entities/user'; -import { IDelete } from '../../type'; +import { IDelete, getApId, validPost } from '../../type'; import { apLogger } from '../../logger'; -import { Notes } from '../../../../models'; /** * 削除アクティビティを捌きます @@ -17,24 +16,11 @@ export default async (actor: IRemoteUser, activity: IDelete): Promise => { const object = await resolver.resolve(activity.object); - const uri = (object as any).id; + const uri = getApId(object); - switch (object.type) { - case 'Note': - case 'Question': - case 'Article': - deleteNote(actor, uri); - break; - - case 'Tombstone': - const note = await Notes.findOne({ uri }); - if (note != null) { - deleteNote(actor, uri); - } - break; - - default: - apLogger.warn(`Unknown type: ${object.type}`); - break; + if (validPost.includes(object.type) || object.type === 'Tombstone') { + deleteNote(actor, uri); + } else { + apLogger.warn(`Unknown type: ${object.type}`); } }; diff --git a/src/remote/activitypub/models/note.ts b/src/remote/activitypub/models/note.ts index bb9465d90d..14425d7496 100644 --- a/src/remote/activitypub/models/note.ts +++ b/src/remote/activitypub/models/note.ts @@ -17,7 +17,7 @@ import { deliverQuestionUpdate } from '../../../services/note/polls/update'; import { extractDbHost, toPuny } from '../../../misc/convert-host'; import { Notes, Emojis, Polls } from '../../../models'; import { Note } from '../../../models/entities/note'; -import { IObject, INote } from '../type'; +import { IObject, INote, getApIds, getOneApId, getApId, validPost } from '../type'; import { Emoji } from '../../../models/entities/emoji'; import { genId } from '../../../misc/gen-id'; import { fetchMeta } from '../../../misc/fetch-meta'; @@ -32,7 +32,7 @@ export function validateNote(object: any, uri: string) { return new Error('invalid Note: object is null'); } - if (!['Note', 'Question', 'Article'].includes(object.type)) { + if (!validPost.includes(object.type)) { return new Error(`invalid Note: invalied object type ${object.type}`); } @@ -40,7 +40,7 @@ export function validateNote(object: any, uri: string) { return new Error(`invalid Note: id has different host. expected: ${expectHost}, actual: ${extractDbHost(object.id)}`); } - if (object.attributedTo && extractDbHost(object.attributedTo) !== expectHost) { + if (object.attributedTo && extractDbHost(getOneApId(object.attributedTo)) !== expectHost) { return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${extractDbHost(object.attributedTo)}`); } @@ -53,8 +53,7 @@ export function validateNote(object: any, uri: string) { * Misskeyに対象のNoteが登録されていればそれを返します。 */ export async function fetchNote(value: string | IObject, resolver?: Resolver): Promise { - const uri = typeof value == 'string' ? value : value.id; - if (uri == null) throw new Error('missing uri'); + const uri = getApId(value); // URIがこのサーバーを指しているならデータベースからフェッチ if (uri.startsWith(config.url + '/')) { @@ -76,12 +75,12 @@ export async function fetchNote(value: string | IObject, resolver?: Resolver): P /** * Noteを作成します。 */ -export async function createNote(value: any, resolver?: Resolver, silent = false): Promise { +export async function createNote(value: string | IObject, resolver?: Resolver, silent = false): Promise { if (resolver == null) resolver = new Resolver(); const object: any = await resolver.resolve(value); - const entryUri = value.id || value; + const entryUri = getApId(value); const err = validateNote(object, entryUri); if (err) { logger.error(`${err.message}`, { @@ -101,7 +100,7 @@ export async function createNote(value: any, resolver?: Resolver, silent = false logger.info(`Creating the Note: ${note.id}`); // 投稿者をフェッチ - const actor = await resolvePerson(note.attributedTo, resolver) as IRemoteUser; + const actor = await resolvePerson(getOneApId(note.attributedTo), resolver) as IRemoteUser; // 投稿者が凍結されていたらスキップ if (actor.isSuspended) { @@ -109,24 +108,24 @@ export async function createNote(value: any, resolver?: Resolver, silent = false } //#region Visibility - note.to = note.to == null ? [] : typeof note.to == 'string' ? [note.to] : note.to; - note.cc = note.cc == null ? [] : typeof note.cc == 'string' ? [note.cc] : note.cc; + const to = getApIds(note.to); + const cc = getApIds(note.cc); let visibility = 'public'; let visibleUsers: User[] = []; - if (!note.to.includes('https://www.w3.org/ns/activitystreams#Public')) { - if (note.cc.includes('https://www.w3.org/ns/activitystreams#Public')) { + if (!to.includes('https://www.w3.org/ns/activitystreams#Public')) { + if (cc.includes('https://www.w3.org/ns/activitystreams#Public')) { visibility = 'home'; - } else if (note.to.includes(`${actor.uri}/followers`)) { // TODO: person.followerと照合するべき? + } else if (to.includes(`${actor.uri}/followers`)) { // TODO: person.followerと照合するべき? visibility = 'followers'; } else { visibility = 'specified'; - visibleUsers = await Promise.all(note.to.map(uri => resolvePerson(uri, resolver))); + visibleUsers = await Promise.all(to.map(uri => resolvePerson(uri, resolver))); } } //#endergion - const apMentions = await extractMentionedUsers(actor, note.to, note.cc, resolver); + const apMentions = await extractMentionedUsers(actor, to, cc, resolver); const apHashtags = await extractHashtags(note.tag); @@ -217,11 +216,11 @@ export async function createNote(value: any, resolver?: Resolver, silent = false const apEmojis = emojis.map(emoji => emoji.name); const questionUri = note._misskey_question; - const poll = await extractPollFromQuestion(note._misskey_question || note).catch(() => undefined); + const poll = await extractPollFromQuestion(note._misskey_question || note, resolver).catch(() => undefined); // ユーザーの情報が古かったらついでに更新しておく if (actor.lastFetchedAt == null || Date.now() - actor.lastFetchedAt.getTime() > 1000 * 60 * 60 * 24) { - updatePerson(note.attributedTo); + if (actor.uri) updatePerson(actor.uri); } return await post(actor, { diff --git a/src/remote/activitypub/models/question.ts b/src/remote/activitypub/models/question.ts index 5c126c3a56..01086a7cf8 100644 --- a/src/remote/activitypub/models/question.ts +++ b/src/remote/activitypub/models/question.ts @@ -1,12 +1,19 @@ import config from '../../../config'; import Resolver from '../resolver'; -import { IQuestion } from '../type'; +import { IObject, IQuestion, isQuestion, } from '../type'; import { apLogger } from '../logger'; import { Notes, Polls } from '../../../models'; import { IPoll } from '../../../models/entities/poll'; -export async function extractPollFromQuestion(source: string | IQuestion): Promise { - const question = typeof source === 'string' ? await new Resolver().resolve(source) as IQuestion : source; +export async function extractPollFromQuestion(source: string | IObject, resolver?: Resolver): Promise { + if (resolver == null) resolver = new Resolver(); + + const question = await resolver.resolve(source); + + if (!isQuestion(question)) { + throw new Error('invalid type'); + } + const multiple = !question.oneOf; const expiresAt = question.endTime ? new Date(question.endTime) : null; diff --git a/src/remote/activitypub/type.ts b/src/remote/activitypub/type.ts index 95c69fb8ac..66163d39b0 100644 --- a/src/remote/activitypub/type.ts +++ b/src/remote/activitypub/type.ts @@ -6,9 +6,9 @@ export interface IObject { id?: string; summary?: string; published?: string; - cc?: string[]; - to?: string[]; - attributedTo: string; + cc?: IObject | string | (IObject | string)[]; + to?: IObject | string | (IObject | string)[]; + attributedTo: IObject | string | (IObject | string)[]; attachment?: any[]; inReplyTo?: any; replies?: ICollection; @@ -23,6 +23,32 @@ export interface IObject { sensitive?: boolean; } +/** + * Get array of ActivityStreams Objects id + */ +export function getApIds(value: IObject | string | (IObject | string)[] | undefined): string[] { + if (value == null) return []; + const array = Array.isArray(value) ? value : [value]; + return array.map(x => getApId(x)); +} + +/** + * Get first ActivityStreams Object id + */ +export function getOneApId(value: IObject | string | (IObject | string)[]): string { + const firstOne = Array.isArray(value) ? value[0] : value; + return getApId(firstOne); +} + +/** + * Get ActivityStreams Object id + */ +export function getApId(value: string | IObject): string { + if (typeof value === 'string') return value; + if (typeof value.id === 'string') return value.id; + throw new Error(`cannot detemine id`); +} + export interface IActivity extends IObject { //type: 'Activity'; actor: IObject | string; @@ -42,8 +68,10 @@ export interface IOrderedCollection extends IObject { orderedItems: IObject | string | IObject[] | string[]; } +export const validPost = ['Note', 'Question', 'Article', 'Audio', 'Document', 'Image', 'Page', 'Video']; + export interface INote extends IObject { - type: 'Note' | 'Question'; + type: 'Note' | 'Question' | 'Article' | 'Audio' | 'Document' | 'Image' | 'Page' | 'Video'; _misskey_content?: string; _misskey_quote?: string; _misskey_question?: string; @@ -59,6 +87,9 @@ export interface IQuestion extends IObject { endTime?: Date; } +export const isQuestion = (object: IObject): object is IQuestion => + object.type === 'Note' || object.type === 'Question'; + interface IQuestionChoice { name?: string; replies?: ICollection; diff --git a/src/server/api/endpoints/ap/show.ts b/src/server/api/endpoints/ap/show.ts index 9724a044b1..bbaa1fa109 100644 --- a/src/server/api/endpoints/ap/show.ts +++ b/src/server/api/endpoints/ap/show.ts @@ -10,7 +10,7 @@ import { Users, Notes } from '../../../../models'; import { Note } from '../../../../models/entities/note'; import { User } from '../../../../models/entities/user'; import { fetchMeta } from '../../../../misc/fetch-meta'; -import { validActor } from '../../../../remote/activitypub/type'; +import { validActor, validPost } from '../../../../remote/activitypub/type'; export const meta = { tags: ['federation'], @@ -145,7 +145,7 @@ async function fetchAny(uri: string) { }; } - if (['Note', 'Question', 'Article'].includes(object.type)) { + if (validPost.includes(object.type)) { const note = await createNote(object.id, undefined, true); return { type: 'Note', -- cgit v1.2.3-freya From 03e999875a7678c0e5293b87397ab67040010eeb Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 1 Jul 2019 21:12:14 +0900 Subject: リモートファイルの削除が重い問題を修正 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/queue/index.ts | 7 +++ src/queue/processors/db/delete-drive-files.ts | 4 +- .../object-storage/clean-remote-files.ts | 50 +++++++++++++++++++++ src/queue/processors/object-storage/delete-file.ts | 16 +------ src/queue/processors/object-storage/index.ts | 2 + .../endpoints/admin/drive/clean-remote-files.ts | 13 +----- src/services/drive/delete-file.ts | 51 ++++++++++++++++++++++ 7 files changed, 116 insertions(+), 27 deletions(-) create mode 100644 src/queue/processors/object-storage/clean-remote-files.ts (limited to 'src/server/api') diff --git a/src/queue/index.ts b/src/queue/index.ts index 70233d8318..a7e9b9814f 100644 --- a/src/queue/index.ts +++ b/src/queue/index.ts @@ -194,6 +194,13 @@ export function createDeleteObjectStorageFileJob(key: string) { }); } +export function createCleanRemoteFilesJob() { + return objectStorageQueue.add('cleanRemoteFiles', {}, { + removeOnComplete: true, + removeOnFail: true + }); +} + export default function() { if (!program.onlyServer) { deliverQueue.process(128, processDeliver); diff --git a/src/queue/processors/db/delete-drive-files.ts b/src/queue/processors/db/delete-drive-files.ts index 5ecee9139a..a2fd9050a9 100644 --- a/src/queue/processors/db/delete-drive-files.ts +++ b/src/queue/processors/db/delete-drive-files.ts @@ -1,7 +1,7 @@ import * as Bull from 'bull'; import { queueLogger } from '../../logger'; -import { deleteFile } from '../../../services/drive/delete-file'; +import { deleteFileSync } from '../../../services/drive/delete-file'; import { Users, DriveFiles } from '../../../models'; import { MoreThan } from 'typeorm'; @@ -39,7 +39,7 @@ export async function deleteDriveFiles(job: Bull.Job, done: any): Promise cursor = files[files.length - 1].id; for (const file of files) { - await deleteFile(file); + await deleteFileSync(file); deletedCount++; } diff --git a/src/queue/processors/object-storage/clean-remote-files.ts b/src/queue/processors/object-storage/clean-remote-files.ts new file mode 100644 index 0000000000..7b34892e1f --- /dev/null +++ b/src/queue/processors/object-storage/clean-remote-files.ts @@ -0,0 +1,50 @@ +import * as Bull from 'bull'; + +import { queueLogger } from '../../logger'; +import { deleteFileSync } from '../../../services/drive/delete-file'; +import { DriveFiles } from '../../../models'; +import { MoreThan, Not, IsNull } from 'typeorm'; + +const logger = queueLogger.createSubLogger('clean-remote-files'); + +export default async function cleanRemoteFiles(job: Bull.Job, done: any): Promise { + logger.info(`Deleting cached remote files...`); + + let deletedCount = 0; + let cursor: any = null; + + while (true) { + const files = await DriveFiles.find({ + where: { + userHost: Not(IsNull()), + isLink: false, + ...(cursor ? { id: MoreThan(cursor) } : {}) + }, + take: 8, + order: { + id: 1 + } + }); + + if (files.length === 0) { + job.progress(100); + break; + } + + cursor = files[files.length - 1].id; + + await Promise.all(files.map(file => deleteFileSync(file, true))); + + deletedCount += 8; + + const total = await DriveFiles.count({ + userHost: Not(IsNull()), + isLink: false, + }); + + job.progress(deletedCount / total); + } + + logger.succ(`All cahced remote files has been deleted.`); + done(); +} diff --git a/src/queue/processors/object-storage/delete-file.ts b/src/queue/processors/object-storage/delete-file.ts index 8e6b5f959e..f899df7d2e 100644 --- a/src/queue/processors/object-storage/delete-file.ts +++ b/src/queue/processors/object-storage/delete-file.ts @@ -1,22 +1,10 @@ import * as Bull from 'bull'; -import * as Minio from 'minio'; -import { fetchMeta } from '../../../misc/fetch-meta'; +import { deleteObjectStorageFile } from '../../../services/drive/delete-file'; export default async (job: Bull.Job) => { - const meta = await fetchMeta(); - - const minio = new Minio.Client({ - endPoint: meta.objectStorageEndpoint!, - region: meta.objectStorageRegion ? meta.objectStorageRegion : undefined, - port: meta.objectStoragePort ? meta.objectStoragePort : undefined, - useSSL: meta.objectStorageUseSSL, - accessKey: meta.objectStorageAccessKey!, - secretKey: meta.objectStorageSecretKey!, - }); - const key: string = job.data.key; - await minio.removeObject(meta.objectStorageBucket!, key); + await deleteObjectStorageFile(key); return 'Success'; }; diff --git a/src/queue/processors/object-storage/index.ts b/src/queue/processors/object-storage/index.ts index 60f732ca64..33ef665b38 100644 --- a/src/queue/processors/object-storage/index.ts +++ b/src/queue/processors/object-storage/index.ts @@ -1,8 +1,10 @@ import * as Bull from 'bull'; import deleteFile from './delete-file'; +import cleanRemoteFiles from './clean-remote-files'; const jobs = { deleteFile, + cleanRemoteFiles, } as any; export default function(q: Bull.Queue) { diff --git a/src/server/api/endpoints/admin/drive/clean-remote-files.ts b/src/server/api/endpoints/admin/drive/clean-remote-files.ts index 69cfe0db94..e837ae1bb6 100644 --- a/src/server/api/endpoints/admin/drive/clean-remote-files.ts +++ b/src/server/api/endpoints/admin/drive/clean-remote-files.ts @@ -1,7 +1,5 @@ -import { Not, IsNull } from 'typeorm'; import define from '../../../define'; -import { deleteFile } from '../../../../../services/drive/delete-file'; -import { DriveFiles } from '../../../../../models'; +import { createCleanRemoteFilesJob } from '../../../../../queue'; export const meta = { tags: ['admin'], @@ -11,12 +9,5 @@ export const meta = { }; export default define(meta, async (ps, me) => { - const files = await DriveFiles.find({ - userHost: Not(IsNull()), - isLink: false, - }); - - for (const file of files) { - deleteFile(file, true); - } + createCleanRemoteFilesJob(); }); diff --git a/src/services/drive/delete-file.ts b/src/services/drive/delete-file.ts index 258c0853fb..5b44a0817a 100644 --- a/src/services/drive/delete-file.ts +++ b/src/services/drive/delete-file.ts @@ -1,8 +1,10 @@ +import * as Minio from 'minio'; import { DriveFile } from '../../models/entities/drive-file'; import { InternalStorage } from './internal-storage'; import { DriveFiles, Instances, Notes } from '../../models'; import { driveChart, perUserDriveChart, instanceChart } from '../chart'; import { createDeleteObjectStorageFileJob } from '../../queue'; +import { fetchMeta } from '../../misc/fetch-meta'; export async function deleteFile(file: DriveFile, isExpired = false) { if (file.storedInternal) { @@ -27,6 +29,40 @@ export async function deleteFile(file: DriveFile, isExpired = false) { } } + postProcess(file, isExpired); +} + +export async function deleteFileSync(file: DriveFile, isExpired = false) { + if (file.storedInternal) { + InternalStorage.del(file.accessKey!); + + if (file.thumbnailUrl) { + InternalStorage.del(file.thumbnailAccessKey!); + } + + if (file.webpublicUrl) { + InternalStorage.del(file.webpublicAccessKey!); + } + } else if (!file.isLink) { + const promises = []; + + promises.push(deleteObjectStorageFile(file.accessKey!)); + + if (file.thumbnailUrl) { + promises.push(deleteObjectStorageFile(file.thumbnailAccessKey!)); + } + + if (file.webpublicUrl) { + promises.push(deleteObjectStorageFile(file.webpublicAccessKey!)); + } + + await Promise.all(promises); + } + + postProcess(file, isExpired); +} + +function postProcess(file: DriveFile, isExpired = false) { // リモートファイル期限切れ削除後は直リンクにする if (isExpired && file.userHost !== null && file.uri != null) { DriveFiles.update(file.id, { @@ -53,3 +89,18 @@ export async function deleteFile(file: DriveFile, isExpired = false) { Instances.decrement({ host: file.userHost }, 'driveFiles', 1); } } + +export async function deleteObjectStorageFile(key: string) { + const meta = await fetchMeta(); + + const minio = new Minio.Client({ + endPoint: meta.objectStorageEndpoint!, + region: meta.objectStorageRegion ? meta.objectStorageRegion : undefined, + port: meta.objectStoragePort ? meta.objectStoragePort : undefined, + useSSL: meta.objectStorageUseSSL, + accessKey: meta.objectStorageAccessKey!, + secretKey: meta.objectStorageSecretKey!, + }); + + await minio.removeObject(meta.objectStorageBucket!, key); +} -- cgit v1.2.3-freya From f17e229c1e390eb98f167c918dde87dbbfcaacf2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 3 Jul 2019 03:58:45 +0900 Subject: Resolve #5072 --- locales/ja-JP.yml | 3 +++ src/client/app/admin/views/db.vue | 26 +++++++++++++++++++++++-- src/server/api/endpoints/admin/vacuum.ts | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/server/api/endpoints/admin/vacuum.ts (limited to 'src/server/api') diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index a192093576..9d104456f8 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -1235,6 +1235,9 @@ admin/views/index.vue: admin/views/db.vue: tables: "テーブル" + vacuum: "バキューム" + vacuum-info: "データベースの掃除を行います。データはそのままで、ディスク使用量を減らします。通常この操作は自動で定期的に行われます。" + vacuum-exclamation: "バキュームを行うと、しばらくの間データベースの負荷が高くなり、ユーザーの操作を受け付けなくなる場合があります。" admin/views/dashboard.vue: dashboard: "ダッシュボード" diff --git a/src/client/app/admin/views/db.vue b/src/client/app/admin/views/db.vue index 7818546e76..9f87a749b6 100644 --- a/src/client/app/admin/views/db.vue +++ b/src/client/app/admin/views/db.vue @@ -5,6 +5,14 @@
{{ table }} {{ tables[table].count | number }} {{ tables[table].size | bytes }}
+
+
{{ $t('vacuum') }}
+ {{ $t('vacuum-info') }} + FULL + ANALYZE + {{ $t('vacuum') }} + {{ $t('vacuum-exclamation') }} +
@@ -12,7 +20,7 @@ diff --git a/src/server/api/endpoints/admin/vacuum.ts b/src/server/api/endpoints/admin/vacuum.ts new file mode 100644 index 0000000000..6990706282 --- /dev/null +++ b/src/server/api/endpoints/admin/vacuum.ts @@ -0,0 +1,33 @@ +import $ from 'cafy'; +import define from '../../define'; +import { getConnection } from 'typeorm'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + params: { + full: { + validator: $.bool, + }, + analyze: { + validator: $.bool, + }, + } +}; + +export default define(meta, async (ps) => { + const params: string[] = []; + + if (ps.full) { + params.push('FULL'); + } + + if (ps.analyze) { + params.push('ANALYZE'); + } + + getConnection().query('VACUUM ' + params.join(' ')); +}); -- cgit v1.2.3-freya From fd94b817abd8fa628586746eed3a1f61b4a2b3d8 Mon Sep 17 00:00:00 2001 From: Mary Date: Wed, 3 Jul 2019 07:18:07 -0400 Subject: Implement Webauthn 🎉 (#5088) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Implement Webauthn :tada: * Share hexifyAB * Move hr inside template and add AttestationChallenges janitor daemon * Apply suggestions from code review Co-Authored-By: Acid Chicken (硫酸鶏) * Add newline at the end of file * Fix stray newline in promise chain * Ignore var in try{}catch(){} block Co-Authored-By: Acid Chicken (硫酸鶏) * Add missing comma * Add missing semicolon * Support more attestation formats * add support for more key types and linter pass * Refactor * Refactor * credentialId --> id * Fix * Improve readability * Add indexes * fixes for credentialId->id * Avoid changing store state * Fix syntax error and code style * Remove unused import * Refactor of getkey API * Create 1561706992953-webauthn.ts * Update ja-JP.yml * Add type annotations * Fix code style * Specify depedency version * Fix code style * Fix janitor daemon and login requesting 2FA regardless of status --- locales/en-US.yml | 13 +- locales/ja-JP.yml | 11 + migration/1561706992953-webauthn.ts | 29 ++ package.json | 4 + src/boot/master.ts | 1 + src/client/app/common/scripts/2fa.ts | 5 + .../app/common/views/components/settings/2fa.vue | 163 +++++++- src/client/app/common/views/components/signin.vue | 182 +++++++-- src/daemons/janitor.ts | 18 + src/db/postgre.ts | 6 +- src/models/entities/attestation-challenge.ts | 46 +++ src/models/entities/user-profile.ts | 5 + src/models/entities/user-security-key.ts | 48 +++ src/models/index.ts | 4 + src/models/repositories/user.ts | 16 +- src/server/api/2fa.ts | 422 +++++++++++++++++++++ src/server/api/endpoints/i/2fa/getkeys.ts | 67 ++++ src/server/api/endpoints/i/2fa/key-done.ts | 151 ++++++++ src/server/api/endpoints/i/2fa/register-key.ts | 60 +++ src/server/api/endpoints/i/2fa/remove-key.ts | 46 +++ src/server/api/private/signin.ts | 137 +++++-- 21 files changed, 1373 insertions(+), 61 deletions(-) create mode 100644 migration/1561706992953-webauthn.ts create mode 100644 src/client/app/common/scripts/2fa.ts create mode 100644 src/daemons/janitor.ts create mode 100644 src/models/entities/attestation-challenge.ts create mode 100644 src/models/entities/user-security-key.ts create mode 100644 src/server/api/2fa.ts create mode 100644 src/server/api/endpoints/i/2fa/getkeys.ts create mode 100644 src/server/api/endpoints/i/2fa/key-done.ts create mode 100644 src/server/api/endpoints/i/2fa/register-key.ts create mode 100644 src/server/api/endpoints/i/2fa/remove-key.ts (limited to 'src/server/api') diff --git a/locales/en-US.yml b/locales/en-US.yml index fd8e965887..158b8c6490 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -601,6 +601,8 @@ common/views/components/signin.vue: signin-with-github: "Sign in with GitHub" signin-with-discord: "Sign in with Discord" login-failed: "Logging in has failed. Make sure you have entered the correct username and password." + tap-key: "Activate your security key by tapping or clicking it to login" + enter-2fa-code: "Enter your 2FA code below" common/views/components/signup.vue: invitation-code: "Invitation code" invitation-info: "If you do not have an invitation code, please contact an administrator." @@ -984,7 +986,7 @@ desktop/views/components/settings.2fa.vue: url: "https://www.google.com/landing/2step/" caution: "If you lose access to your registered device, you won't be able to connect to Misskey anymore!" register: "Register a device" - already-registered: "This device is already registered" + already-registered: "Your account is currently registered to an authenticator application" unregister: "Unregister" unregistered: "Two-factor authentication has been disabled." enter-password: "Enter the password" @@ -997,6 +999,15 @@ desktop/views/components/settings.2fa.vue: success: "Settings saved!" failed: "Failed to setup. Please ensure that the token is correct." info: "From the next time you sign in to Misskey, the token displayed on your device will be necessary too, as well as the password." + totp-header: "Authenticator App" + security-key-header: "Security Keys" + security-key: "You can use a hardware security key supporting FIDO2 to log into your account for enhanced security. When you sign-in, you'll need a registered security key or your authenticator app." + last-used: "Last used:" + activate-key: "Please activate your security key by tapping or clicking it" + security-key-name: "Key Name" + register-security-key: "Finish Key Registration" + something-went-wrong: "Oops! Something went wrong while trying to register your key:" + key-unregistered: "Key Removed" common/views/components/media-image.vue: sensitive: "NSFW" click-to-show: "Click to show" diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml index 9d104456f8..5767a51b0f 100644 --- a/locales/ja-JP.yml +++ b/locales/ja-JP.yml @@ -646,6 +646,8 @@ common/views/components/signin.vue: signin-with-github: "GitHubでログイン" signin-with-discord: "Discordでログイン" login-failed: "ログインできませんでした。ユーザー名とパスワードを確認してください。" + tap-key: "セキュリティキーをクリックしてログイン" + enter-2fa-code: "認証コードを入力してください" common/views/components/signup.vue: invitation-code: "招待コード" @@ -1100,6 +1102,15 @@ desktop/views/components/settings.2fa.vue: success: "設定が完了しました!" failed: "設定に失敗しました。トークンに誤りがないかご確認ください。" info: "次回サインインからは、同様にパスワードに加えてデバイスに表示されているトークンを入力します。" + totp-header: "認証アプリ" + security-key-header: "セキュリティキー" + security-key: "セキュリティを強化するために、FIDO2をサポートするハードウェアセキュリティキーを使用してアカウントにログインできます。 サインインの際は、登録されたセキュリティキーまたは認証アプリが必要になります。" + last-used: "最後の使用:" + activate-key: "クリックしてセキュリティキーをアクティベートしてください" + security-key-name: "キー名" + register-security-key: "キーの登録を完了" + something-went-wrong: "わー! キーを登録する際に問題が発生しました:" + key-unregistered: "キーが削除されました" common/views/components/media-image.vue: sensitive: "閲覧注意" diff --git a/migration/1561706992953-webauthn.ts b/migration/1561706992953-webauthn.ts new file mode 100644 index 0000000000..fc1f0c042f --- /dev/null +++ b/migration/1561706992953-webauthn.ts @@ -0,0 +1,29 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class webauthn1561706992953 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE "attestation_challenge" ("id" character varying(32) NOT NULL, "userId" character varying(32) NOT NULL, "challenge" character varying(64) NOT NULL, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "registrationChallenge" boolean NOT NULL DEFAULT false, CONSTRAINT "PK_d0ba6786e093f1bcb497572a6b5" PRIMARY KEY ("id", "userId"))`); + await queryRunner.query(`CREATE INDEX "IDX_f1a461a618fa1755692d0e0d59" ON "attestation_challenge" ("userId") `); + await queryRunner.query(`CREATE INDEX "IDX_47efb914aed1f72dd39a306c7b" ON "attestation_challenge" ("challenge") `); + await queryRunner.query(`CREATE TABLE "user_security_key" ("id" character varying NOT NULL, "userId" character varying(32) NOT NULL, "publicKey" character varying NOT NULL, "lastUsed" TIMESTAMP WITH TIME ZONE NOT NULL, "name" character varying(30) NOT NULL, CONSTRAINT "PK_3e508571121ab39c5f85d10c166" PRIMARY KEY ("id"))`); + await queryRunner.query(`CREATE INDEX "IDX_ff9ca3b5f3ee3d0681367a9b44" ON "user_security_key" ("userId") `); + await queryRunner.query(`CREATE INDEX "IDX_0d7718e562dcedd0aa5cf2c9f7" ON "user_security_key" ("publicKey") `); + await queryRunner.query(`ALTER TABLE "user_profile" ADD "securityKeysAvailable" boolean NOT NULL DEFAULT false`); + await queryRunner.query(`ALTER TABLE "attestation_challenge" ADD CONSTRAINT "FK_f1a461a618fa1755692d0e0d592" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE "user_security_key" ADD CONSTRAINT "FK_ff9ca3b5f3ee3d0681367a9b447" FOREIGN KEY ("userId") REFERENCES "user"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE "user_security_key" DROP CONSTRAINT "FK_ff9ca3b5f3ee3d0681367a9b447"`); + await queryRunner.query(`ALTER TABLE "attestation_challenge" DROP CONSTRAINT "FK_f1a461a618fa1755692d0e0d592"`); + await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "securityKeysAvailable"`); + await queryRunner.query(`DROP INDEX "IDX_0d7718e562dcedd0aa5cf2c9f7"`); + await queryRunner.query(`DROP INDEX "IDX_ff9ca3b5f3ee3d0681367a9b44"`); + await queryRunner.query(`DROP TABLE "user_security_key"`); + await queryRunner.query(`DROP INDEX "IDX_47efb914aed1f72dd39a306c7b"`); + await queryRunner.query(`DROP INDEX "IDX_f1a461a618fa1755692d0e0d59"`); + await queryRunner.query(`DROP TABLE "attestation_challenge"`); + } + +} diff --git a/package.json b/package.json index 79009380ce..119deacaf6 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "@koa/cors": "3.0.0", "@types/bcryptjs": "2.4.2", "@types/bull": "3.5.15", + "@types/cbor": "2.0.0", "@types/dateformat": "3.0.0", "@types/deep-equal": "1.0.1", "@types/double-ended-queue": "2.1.1", @@ -104,9 +105,11 @@ "autosize": "4.0.2", "autwh": "0.1.0", "bcryptjs": "2.4.3", + "bootstrap": "4.3.1", "bootstrap-vue": "2.0.0-rc.13", "bull": "3.10.0", "cafy": "15.1.1", + "cbor": "4.1.5", "chai": "4.2.0", "chalk": "2.4.2", "cli-highlight": "2.1.1", @@ -148,6 +151,7 @@ "jsdom": "15.1.1", "json5": "2.1.0", "json5-loader": "3.0.0", + "jsrsasign": "8.0.12", "katex": "0.10.2", "koa": "2.7.0", "koa-bodyparser": "4.2.1", diff --git a/src/boot/master.ts b/src/boot/master.ts index 6c23a528fa..b698548d47 100644 --- a/src/boot/master.ts +++ b/src/boot/master.ts @@ -79,6 +79,7 @@ export async function masterMain() { require('../daemons/server-stats').default(); require('../daemons/notes-stats').default(); require('../daemons/queue-stats').default(); + require('../daemons/janitor').default(); } bootLogger.succ(`Now listening on port ${config.port} on ${config.url}`, null, true); diff --git a/src/client/app/common/scripts/2fa.ts b/src/client/app/common/scripts/2fa.ts new file mode 100644 index 0000000000..f638cce156 --- /dev/null +++ b/src/client/app/common/scripts/2fa.ts @@ -0,0 +1,5 @@ +export function hexifyAB(buffer) { + return Array.from(new Uint8Array(buffer)) + .map(item => item.toString(16).padStart(2, 0)) + .join(''); +} diff --git a/src/client/app/common/views/components/settings/2fa.vue b/src/client/app/common/views/components/settings/2fa.vue index 6e8d19d83a..eb645898e2 100644 --- a/src/client/app/common/views/components/settings/2fa.vue +++ b/src/client/app/common/views/components/settings/2fa.vue @@ -1,11 +1,54 @@
@@ -424,6 +425,32 @@ export default Vue.extend({ }); }, + async testEmail() { + const { canceled, result: to } = await this.$root.dialog({ + title: this.$t('test-email-to'), + input: { + type: 'email', + }, + showCancelButton: true + }); + if (canceled) return; + this.$root.api('admin/send-email', { + to: to, + subject: 'Test email', + text: 'Yo' + }).then(x => { + this.$root.dialog({ + type: 'success', + splash: true + }); + }).catch(e => { + this.$root.dialog({ + type: 'error', + text: e + }); + }); + }, + updateMeta() { this.$root.api('admin/update-meta', { maintainerName: this.maintainerName, diff --git a/src/server/api/endpoints/admin/send-email.ts b/src/server/api/endpoints/admin/send-email.ts new file mode 100644 index 0000000000..fed4f2df14 --- /dev/null +++ b/src/server/api/endpoints/admin/send-email.ts @@ -0,0 +1,26 @@ +import $ from 'cafy'; +import define from '../../define'; +import { sendEmail } from '../../../../services/send-email'; + +export const meta = { + tags: ['admin'], + + requireCredential: true, + requireModerator: true, + + params: { + to: { + validator: $.str, + }, + subject: { + validator: $.str, + }, + text: { + validator: $.str, + }, + } +}; + +export default define(meta, async (ps) => { + await sendEmail(ps.to, ps.subject, ps.text); +}); -- cgit v1.2.3-freya From d3edf0312572d765c379580766d8153e6fb7f9c4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 5 Jul 2019 02:00:54 +0900 Subject: Fix errors --- src/server/api/2fa.ts | 8 ++++---- src/server/api/endpoints/i/2fa/key-done.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/server/api') diff --git a/src/server/api/2fa.ts b/src/server/api/2fa.ts index bc5f6e6d7d..3bc4627a62 100644 --- a/src/server/api/2fa.ts +++ b/src/server/api/2fa.ts @@ -63,15 +63,15 @@ function verifyCertificateChain(certificates: string[]) { const CACert = i + 1 >= certificates.length ? Cert : certificates[i + 1]; - const certStruct = jsrsasign.ASN1HEX.getTLVbyList(certificate.hex, 0, [0]); + const certStruct = jsrsasign.ASN1HEX.getTLVbyList(certificate.hex!, 0, [0]); const algorithm = certificate.getSignatureAlgorithmField(); const signatureHex = certificate.getSignatureValueHex(); // Verify against CA - const Signature = new jsrsasign.crypto.Signature({alg: algorithm}); + const Signature = new jsrsasign.KJUR.crypto.Signature({alg: algorithm}); Signature.init(CACert); Signature.updateHex(certStruct); - valid = valid && Signature.verify(signatureHex); // true if CA signed the certificate + valid = valid && !!Signature.verify(signatureHex); // true if CA signed the certificate } return valid; @@ -260,7 +260,7 @@ export const procedures = { } const certificateChain = header.x5c - .map(key => PEMString(key)) + .map((key: any) => PEMString(key)) .concat([GSR2]); if (getCertSubject(certificateChain[0]).CN != 'attest.android.com') { diff --git a/src/server/api/endpoints/i/2fa/key-done.ts b/src/server/api/endpoints/i/2fa/key-done.ts index 074ab22bf0..d751dabc41 100644 --- a/src/server/api/endpoints/i/2fa/key-done.ts +++ b/src/server/api/endpoints/i/2fa/key-done.ts @@ -14,7 +14,7 @@ import config from '../../../../../config'; import { procedures, hash } from '../../../2fa'; import { publishMainStream } from '../../../../../services/stream'; -const cborDecodeFirst = promisify(cbor.decodeFirst); +const cborDecodeFirst = promisify(cbor.decodeFirst) as any; export const meta = { requireCredential: true, @@ -90,11 +90,11 @@ export default define(meta, async (ps, user) => { throw new Error('alg mismatch'); } - if (!procedures[attestation.fmt]) { + if (!(procedures as any)[attestation.fmt]) { throw new Error('unsupported fmt'); } - const verificationData = procedures[attestation.fmt].verify({ + const verificationData = (procedures as any)[attestation.fmt].verify({ attStmt: attestation.attStmt, authenticatorData: authData, clientDataHash: clientDataJSONHash, -- cgit v1.2.3-freya