From d53d45f797946ced21f6eaeee0fa4c713b19f782 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 5 Jul 2018 22:35:35 +0900 Subject: [PATCH 01/13] wip --- src/server/api/endpoints/notes/create.ts | 39 ++++++++++++++++++------ src/server/api/get-params.ts | 30 ++++++++++++++++++ 2 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 src/server/api/get-params.ts diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 64f3b5ce2..2bd0b430d 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -4,22 +4,43 @@ import User, { ILocalUser, IUser } from '../../../../models/user'; import DriveFile from '../../../../models/drive-file'; import create from '../../../../services/note/create'; import { IApp } from '../../../../models/app'; +import getParams from '../../get-params'; + +export const meta = { + params: { + visibility: { + def: $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']), + default: 'public', + desc: { + ja: '投稿の公開範囲' + } + }, + visibleUserIds: { + def: $.arr($.type(ID)).optional().unique().min(1), + desc: { + ja: '(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー' + } + }, + text: { + def: $.str.optional().nullable().pipe(isValidText), + default: null, + desc: { + ja: '投稿内容' + } + }, + } +}; /** * Create a note */ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { - // Get 'visibility' parameter - const [visibility = 'public', visibilityErr] = $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']).get(params.visibility); - if (visibilityErr) return rej('invalid visibility'); - - // Get 'visibleUserIds' parameter - const [visibleUserIds, visibleUserIdsErr] = $.arr($.type(ID)).optional().unique().min(1).get(params.visibleUserIds); - if (visibleUserIdsErr) return rej('invalid visibleUserIds'); + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); let visibleUsers: IUser[] = []; - if (visibleUserIds !== undefined) { - visibleUsers = await Promise.all(visibleUserIds.map(id => User.findOne({ + if (ps.visibleUserIds !== undefined) { + visibleUsers = await Promise.all(ps.visibleUserIds.map(id => User.findOne({ _id: id }))); } diff --git a/src/server/api/get-params.ts b/src/server/api/get-params.ts new file mode 100644 index 000000000..6b047a28f --- /dev/null +++ b/src/server/api/get-params.ts @@ -0,0 +1,30 @@ +import { Query } from 'cafy'; + +type Defs = { + params: {[key: string]: { + def: Query; + default?: any; + }} +}; + +export default function (defs: T, params: any): [{ + [P in keyof T['params']]: ReturnType[0]; +}, Error] { + const x: any = {}; + let err: Error = null; + Object.keys(defs.params).some(k => { + const [v, e] = defs.params[k].def.get(params[k]); + if (e) { + err = e; + return true; + } else { + if (v === undefined && defs.params[k].default) { + x[k] = defs.params[k].default; + } else { + x[k] = v; + } + return false; + } + }); + return [x, err]; +} From 11439afde76015b80e8d2e680808161cbc1800d5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 5 Jul 2018 23:36:07 +0900 Subject: [PATCH 02/13] wip --- package.json | 2 +- src/cafy-id.ts | 4 +- src/server/api/endpoints/aggregation/posts.ts | 2 +- src/server/api/endpoints/aggregation/users.ts | 2 +- .../endpoints/aggregation/users/activity.ts | 2 +- src/server/api/endpoints/app/create.ts | 2 +- src/server/api/endpoints/app/show.ts | 4 +- src/server/api/endpoints/drive/files.ts | 10 +- .../api/endpoints/drive/files/create.ts | 2 +- src/server/api/endpoints/drive/files/find.ts | 2 +- .../api/endpoints/drive/files/update.ts | 4 +- .../endpoints/drive/files/upload_from_url.ts | 2 +- src/server/api/endpoints/drive/folders.ts | 8 +- .../api/endpoints/drive/folders/create.ts | 4 +- .../api/endpoints/drive/folders/find.ts | 2 +- .../api/endpoints/drive/folders/update.ts | 4 +- src/server/api/endpoints/drive/stream.ts | 8 +- src/server/api/endpoints/i/authorized_apps.ts | 6 +- src/server/api/endpoints/i/favorites.ts | 6 +- src/server/api/endpoints/i/notifications.ts | 12 +- src/server/api/endpoints/i/signin_history.ts | 6 +- src/server/api/endpoints/i/update.ts | 22 +-- .../api/endpoints/i/update_client_setting.ts | 2 +- src/server/api/endpoints/messaging/history.ts | 2 +- .../api/endpoints/messaging/messages.ts | 8 +- .../endpoints/messaging/messages/create.ts | 4 +- src/server/api/endpoints/mute/list.ts | 6 +- src/server/api/endpoints/my/apps.ts | 4 +- src/server/api/endpoints/notes.ts | 18 +-- .../api/endpoints/notes/conversation.ts | 4 +- src/server/api/endpoints/notes/create.ts | 147 +++++++++--------- .../api/endpoints/notes/global-timeline.ts | 12 +- .../api/endpoints/notes/local-timeline.ts | 12 +- src/server/api/endpoints/notes/mentions.ts | 8 +- .../endpoints/notes/polls/recommendation.ts | 4 +- src/server/api/endpoints/notes/reactions.ts | 6 +- src/server/api/endpoints/notes/replies.ts | 4 +- src/server/api/endpoints/notes/reposts.ts | 6 +- src/server/api/endpoints/notes/search.ts | 4 +- .../api/endpoints/notes/search_by_tag.ts | 28 ++-- src/server/api/endpoints/notes/timeline.ts | 16 +- src/server/api/endpoints/notes/trend.ts | 12 +- .../api/endpoints/notes/user-list-timeline.ts | 16 +- src/server/api/endpoints/reversi/games.ts | 8 +- src/server/api/endpoints/users.ts | 6 +- src/server/api/endpoints/users/followers.ts | 6 +- src/server/api/endpoints/users/following.ts | 6 +- .../users/get_frequently_replied_users.ts | 2 +- src/server/api/endpoints/users/notes.ts | 20 +-- .../api/endpoints/users/recommendation.ts | 4 +- src/server/api/endpoints/users/search.ts | 2 +- .../api/endpoints/users/search_by_username.ts | 4 +- src/server/api/endpoints/users/show.ts | 8 +- src/server/api/get-params.ts | 15 +- 54 files changed, 260 insertions(+), 260 deletions(-) diff --git a/package.json b/package.json index b5cc2457c..42b8fdf5e 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "autwh": "0.1.0", "bcryptjs": "2.4.3", "bootstrap-vue": "2.0.0-rc.11", - "cafy": "8.0.0", + "cafy": "11.0.0", "chalk": "2.4.1", "crc-32": "1.2.0", "css-loader": "0.28.11", diff --git a/src/cafy-id.ts b/src/cafy-id.ts index dac0f97bd..9b7f4f97b 100644 --- a/src/cafy-id.ts +++ b/src/cafy-id.ts @@ -1,5 +1,5 @@ import * as mongo from 'mongodb'; -import { Query } from 'cafy'; +import { Context } from 'cafy'; export const isAnId = (x: any) => mongo.ObjectID.isValid(x); export const isNotAnId = (x: any) => !isAnId(x); @@ -7,7 +7,7 @@ export const isNotAnId = (x: any) => !isAnId(x); /** * ID */ -export default class ID extends Query { +export default class ID extends Context { constructor() { super(); diff --git a/src/server/api/endpoints/aggregation/posts.ts b/src/server/api/endpoints/aggregation/posts.ts index 48e344312..5de578995 100644 --- a/src/server/api/endpoints/aggregation/posts.ts +++ b/src/server/api/endpoints/aggregation/posts.ts @@ -6,7 +6,7 @@ import Note from '../../../../models/note'; */ module.exports = (params: any) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit); + const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); if (limitErr) return rej('invalid limit param'); const datas = await Note diff --git a/src/server/api/endpoints/aggregation/users.ts b/src/server/api/endpoints/aggregation/users.ts index c084404d0..3ab96b66d 100644 --- a/src/server/api/endpoints/aggregation/users.ts +++ b/src/server/api/endpoints/aggregation/users.ts @@ -6,7 +6,7 @@ import User from '../../../../models/user'; */ module.exports = (params: any) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit); + const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); if (limitErr) return rej('invalid limit param'); const users = await User diff --git a/src/server/api/endpoints/aggregation/users/activity.ts b/src/server/api/endpoints/aggregation/users/activity.ts index d4c716d65..98c7d3a1d 100644 --- a/src/server/api/endpoints/aggregation/users/activity.ts +++ b/src/server/api/endpoints/aggregation/users/activity.ts @@ -9,7 +9,7 @@ import Note from '../../../../../models/note'; */ module.exports = (params: any) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit); + const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'userId' parameter diff --git a/src/server/api/endpoints/app/create.ts b/src/server/api/endpoints/app/create.ts index c7bc91a07..5da87e5a3 100644 --- a/src/server/api/endpoints/app/create.ts +++ b/src/server/api/endpoints/app/create.ts @@ -78,7 +78,7 @@ module.exports = async (params: any, user: ILocalUser) => new Promise(async (res // Get 'callbackUrl' parameter // TODO: Check it is valid url - const [callbackUrl = null, callbackUrlErr] = $.str.optional().nullable().get(params.callbackUrl); + const [callbackUrl = null, callbackUrlErr] = $.str.optional.nullable.get(params.callbackUrl); if (callbackUrlErr) return rej('invalid callbackUrl param'); // Generate secret diff --git a/src/server/api/endpoints/app/show.ts b/src/server/api/endpoints/app/show.ts index 2b98a3f14..982c87c4e 100644 --- a/src/server/api/endpoints/app/show.ts +++ b/src/server/api/endpoints/app/show.ts @@ -39,11 +39,11 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async const isSecure = user != null && app == null; // Get 'appId' parameter - const [appId, appIdErr] = $.type(ID).optional().get(params.appId); + const [appId, appIdErr] = $.type(ID).optional.get(params.appId); if (appIdErr) return rej('invalid appId param'); // Get 'nameId' parameter - const [nameId, nameIdErr] = $.str.optional().get(params.nameId); + const [nameId, nameIdErr] = $.str.optional.get(params.nameId); if (nameIdErr) return rej('invalid nameId param'); if (appId === undefined && nameId === undefined) { diff --git a/src/server/api/endpoints/drive/files.ts b/src/server/api/endpoints/drive/files.ts index efce75074..fa99c4a51 100644 --- a/src/server/api/endpoints/drive/files.ts +++ b/src/server/api/endpoints/drive/files.ts @@ -7,15 +7,15 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = async (params: any, user: ILocalUser) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) throw 'invalid sinceId param'; // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) throw 'invalid untilId param'; // Check if both of sinceId and untilId is specified @@ -24,11 +24,11 @@ module.exports = async (params: any, user: ILocalUser) => { } // Get 'folderId' parameter - const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId); + const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId); if (folderIdErr) throw 'invalid folderId param'; // Get 'type' parameter - const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type); + const [type, typeErr] = $.str.optional.match(/^[a-zA-Z\/\-\*]+$/).get(params.type); if (typeErr) throw 'invalid type param'; // Construct query diff --git a/src/server/api/endpoints/drive/files/create.ts b/src/server/api/endpoints/drive/files/create.ts index db2626af0..4c348c130 100644 --- a/src/server/api/endpoints/drive/files/create.ts +++ b/src/server/api/endpoints/drive/files/create.ts @@ -28,7 +28,7 @@ module.exports = async (file: any, params: any, user: ILocalUser): Promise } // Get 'folderId' parameter - const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId); + const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId); if (folderIdErr) throw 'invalid folderId param'; function cleanup() { diff --git a/src/server/api/endpoints/drive/files/find.ts b/src/server/api/endpoints/drive/files/find.ts index 75ab91f0a..dfca4e039 100644 --- a/src/server/api/endpoints/drive/files/find.ts +++ b/src/server/api/endpoints/drive/files/find.ts @@ -11,7 +11,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) if (nameErr) return rej('invalid name param'); // Get 'folderId' parameter - const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId); + const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId); if (folderIdErr) return rej('invalid folderId param'); // Issue query diff --git a/src/server/api/endpoints/drive/files/update.ts b/src/server/api/endpoints/drive/files/update.ts index 825683b21..76656beaa 100644 --- a/src/server/api/endpoints/drive/files/update.ts +++ b/src/server/api/endpoints/drive/files/update.ts @@ -24,12 +24,12 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) } // Get 'name' parameter - const [name, nameErr] = $.str.optional().pipe(validateFileName).get(params.name); + const [name, nameErr] = $.str.optional.pipe(validateFileName).get(params.name); if (nameErr) return rej('invalid name param'); if (name) file.filename = name; // Get 'folderId' parameter - const [folderId, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId); + const [folderId, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId); if (folderIdErr) return rej('invalid folderId param'); if (folderId !== undefined) { diff --git a/src/server/api/endpoints/drive/files/upload_from_url.ts b/src/server/api/endpoints/drive/files/upload_from_url.ts index cb617d851..442a0d394 100644 --- a/src/server/api/endpoints/drive/files/upload_from_url.ts +++ b/src/server/api/endpoints/drive/files/upload_from_url.ts @@ -16,7 +16,7 @@ module.exports = async (params: any, user: ILocalUser): Promise => { if (urlErr) throw 'invalid url param'; // Get 'folderId' parameter - const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId); + const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId); if (folderIdErr) throw 'invalid folderId param'; return pack(await uploadFromUrl(url, user, folderId)); diff --git a/src/server/api/endpoints/drive/folders.ts b/src/server/api/endpoints/drive/folders.ts index 341377895..878c747a4 100644 --- a/src/server/api/endpoints/drive/folders.ts +++ b/src/server/api/endpoints/drive/folders.ts @@ -7,15 +7,15 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified @@ -24,7 +24,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) } // Get 'folderId' parameter - const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId); + const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId); if (folderIdErr) return rej('invalid folderId param'); // Construct query diff --git a/src/server/api/endpoints/drive/folders/create.ts b/src/server/api/endpoints/drive/folders/create.ts index 8f06b0f66..c06a40ded 100644 --- a/src/server/api/endpoints/drive/folders/create.ts +++ b/src/server/api/endpoints/drive/folders/create.ts @@ -8,11 +8,11 @@ import { ILocalUser } from '../../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'name' parameter - const [name = '無題のフォルダー', nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name); + const [name = '無題のフォルダー', nameErr] = $.str.optional.pipe(isValidFolderName).get(params.name); if (nameErr) return rej('invalid name param'); // Get 'parentId' parameter - const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId); + const [parentId = null, parentIdErr] = $.type(ID).optional.nullable.get(params.parentId); if (parentIdErr) return rej('invalid parentId param'); // If the parent folder is specified diff --git a/src/server/api/endpoints/drive/folders/find.ts b/src/server/api/endpoints/drive/folders/find.ts index b3238b5c3..414202ccd 100644 --- a/src/server/api/endpoints/drive/folders/find.ts +++ b/src/server/api/endpoints/drive/folders/find.ts @@ -11,7 +11,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) if (nameErr) return rej('invalid name param'); // Get 'parentId' parameter - const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId); + const [parentId = null, parentIdErr] = $.type(ID).optional.nullable.get(params.parentId); if (parentIdErr) return rej('invalid parentId param'); // Issue query diff --git a/src/server/api/endpoints/drive/folders/update.ts b/src/server/api/endpoints/drive/folders/update.ts index f126c09f5..20675771f 100644 --- a/src/server/api/endpoints/drive/folders/update.ts +++ b/src/server/api/endpoints/drive/folders/update.ts @@ -23,12 +23,12 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) } // Get 'name' parameter - const [name, nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name); + const [name, nameErr] = $.str.optional.pipe(isValidFolderName).get(params.name); if (nameErr) return rej('invalid name param'); if (name) folder.name = name; // Get 'parentId' parameter - const [parentId, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId); + const [parentId, parentIdErr] = $.type(ID).optional.nullable.get(params.parentId); if (parentIdErr) return rej('invalid parentId param'); if (parentId !== undefined) { if (parentId === null) { diff --git a/src/server/api/endpoints/drive/stream.ts b/src/server/api/endpoints/drive/stream.ts index 515f74645..612d922c6 100644 --- a/src/server/api/endpoints/drive/stream.ts +++ b/src/server/api/endpoints/drive/stream.ts @@ -7,15 +7,15 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified @@ -24,7 +24,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) } // Get 'type' parameter - const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type); + const [type, typeErr] = $.str.optional.match(/^[a-zA-Z\/\-\*]+$/).get(params.type); if (typeErr) return rej('invalid type param'); // Construct query diff --git a/src/server/api/endpoints/i/authorized_apps.ts b/src/server/api/endpoints/i/authorized_apps.ts index cfc93c151..9c518b3c8 100644 --- a/src/server/api/endpoints/i/authorized_apps.ts +++ b/src/server/api/endpoints/i/authorized_apps.ts @@ -8,15 +8,15 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'sort' parameter - const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort); + const [sort = 'desc', sortError] = $.str.optional.or('desc asc').get(params.sort); if (sortError) return rej('invalid sort param'); // Get tokens diff --git a/src/server/api/endpoints/i/favorites.ts b/src/server/api/endpoints/i/favorites.ts index dc343afae..1ed42a98b 100644 --- a/src/server/api/endpoints/i/favorites.ts +++ b/src/server/api/endpoints/i/favorites.ts @@ -7,15 +7,15 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts index ce283fe48..93c5abf4d 100644 --- a/src/server/api/endpoints/i/notifications.ts +++ b/src/server/api/endpoints/i/notifications.ts @@ -12,27 +12,27 @@ import { ILocalUser } from '../../../../models/user'; module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'following' parameter const [following = false, followingError] = - $.bool.optional().get(params.following); + $.bool.optional.get(params.following); if (followingError) return rej('invalid following param'); // Get 'markAsRead' parameter - const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead); + const [markAsRead = true, markAsReadErr] = $.bool.optional.get(params.markAsRead); if (markAsReadErr) return rej('invalid markAsRead param'); // Get 'type' parameter - const [type, typeErr] = $.arr($.str).optional().unique().get(params.type); + const [type, typeErr] = $.arr($.str).optional.unique().get(params.type); if (typeErr) return rej('invalid type param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/i/signin_history.ts b/src/server/api/endpoints/i/signin_history.ts index 4ab9881f3..e58f48f72 100644 --- a/src/server/api/endpoints/i/signin_history.ts +++ b/src/server/api/endpoints/i/signin_history.ts @@ -7,15 +7,15 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index 57b050ebc..fc23d9fc8 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -14,57 +14,57 @@ module.exports = async (params: any, user: ILocalUser, app: IApp) => new Promise const updates = {} as any; // Get 'name' parameter - const [name, nameErr] = $.str.optional().nullable().pipe(isValidName).get(params.name); + const [name, nameErr] = $.str.optional.nullable.pipe(isValidName).get(params.name); if (nameErr) return rej('invalid name param'); if (name) updates.name = name; // Get 'description' parameter - const [description, descriptionErr] = $.str.optional().nullable().pipe(isValidDescription).get(params.description); + const [description, descriptionErr] = $.str.optional.nullable.pipe(isValidDescription).get(params.description); if (descriptionErr) return rej('invalid description param'); if (description !== undefined) updates.description = description; // Get 'location' parameter - const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location); + const [location, locationErr] = $.str.optional.nullable.pipe(isValidLocation).get(params.location); if (locationErr) return rej('invalid location param'); if (location !== undefined) updates['profile.location'] = location; // Get 'birthday' parameter - const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday); + const [birthday, birthdayErr] = $.str.optional.nullable.pipe(isValidBirthday).get(params.birthday); if (birthdayErr) return rej('invalid birthday param'); if (birthday !== undefined) updates['profile.birthday'] = birthday; // Get 'avatarId' parameter - const [avatarId, avatarIdErr] = $.type(ID).optional().nullable().get(params.avatarId); + const [avatarId, avatarIdErr] = $.type(ID).optional.nullable.get(params.avatarId); if (avatarIdErr) return rej('invalid avatarId param'); if (avatarId !== undefined) updates.avatarId = avatarId; // Get 'bannerId' parameter - const [bannerId, bannerIdErr] = $.type(ID).optional().nullable().get(params.bannerId); + const [bannerId, bannerIdErr] = $.type(ID).optional.nullable.get(params.bannerId); if (bannerIdErr) return rej('invalid bannerId param'); if (bannerId !== undefined) updates.bannerId = bannerId; // Get 'wallpaperId' parameter - const [wallpaperId, wallpaperIdErr] = $.type(ID).optional().nullable().get(params.wallpaperId); + const [wallpaperId, wallpaperIdErr] = $.type(ID).optional.nullable.get(params.wallpaperId); if (wallpaperIdErr) return rej('invalid wallpaperId param'); if (wallpaperId !== undefined) updates.wallpaperId = wallpaperId; // Get 'isLocked' parameter - const [isLocked, isLockedErr] = $.bool.optional().get(params.isLocked); + const [isLocked, isLockedErr] = $.bool.optional.get(params.isLocked); if (isLockedErr) return rej('invalid isLocked param'); if (isLocked != null) updates.isLocked = isLocked; // Get 'isBot' parameter - const [isBot, isBotErr] = $.bool.optional().get(params.isBot); + const [isBot, isBotErr] = $.bool.optional.get(params.isBot); if (isBotErr) return rej('invalid isBot param'); if (isBot != null) updates.isBot = isBot; // Get 'isCat' parameter - const [isCat, isCatErr] = $.bool.optional().get(params.isCat); + const [isCat, isCatErr] = $.bool.optional.get(params.isCat); if (isCatErr) return rej('invalid isCat param'); if (isCat != null) updates.isCat = isCat; // Get 'autoWatch' parameter - const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch); + const [autoWatch, autoWatchErr] = $.bool.optional.get(params.autoWatch); if (autoWatchErr) return rej('invalid autoWatch param'); if (autoWatch != null) updates['settings.autoWatch'] = autoWatch; diff --git a/src/server/api/endpoints/i/update_client_setting.ts b/src/server/api/endpoints/i/update_client_setting.ts index 6d6e8ed24..9eca66cfc 100644 --- a/src/server/api/endpoints/i/update_client_setting.ts +++ b/src/server/api/endpoints/i/update_client_setting.ts @@ -11,7 +11,7 @@ module.exports = async (params: any, user: ILocalUser) => new Promise(async (res if (nameErr) return rej('invalid name param'); // Get 'value' parameter - const [value, valueErr] = $.any.nullable().get(params.value); + const [value, valueErr] = $.any.nullable.get(params.value); if (valueErr) return rej('invalid value param'); const x: any = {}; diff --git a/src/server/api/endpoints/messaging/history.ts b/src/server/api/endpoints/messaging/history.ts index 713ba9dd7..d76aa7823 100644 --- a/src/server/api/endpoints/messaging/history.ts +++ b/src/server/api/endpoints/messaging/history.ts @@ -9,7 +9,7 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); const mute = await Mute.find({ diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts index 3eb20ec06..16236136d 100644 --- a/src/server/api/endpoints/messaging/messages.ts +++ b/src/server/api/endpoints/messaging/messages.ts @@ -26,19 +26,19 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) } // Get 'markAsRead' parameter - const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead); + const [markAsRead = true, markAsReadErr] = $.bool.optional.get(params.markAsRead); if (markAsReadErr) return rej('invalid markAsRead param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/messaging/messages/create.ts b/src/server/api/endpoints/messaging/messages/create.ts index b3e4f6a8c..d4f16d0dc 100644 --- a/src/server/api/endpoints/messaging/messages/create.ts +++ b/src/server/api/endpoints/messaging/messages/create.ts @@ -38,11 +38,11 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) } // Get 'text' parameter - const [text, textErr] = $.str.optional().pipe(isValidText).get(params.text); + const [text, textErr] = $.str.optional.pipe(isValidText).get(params.text); if (textErr) return rej('invalid text'); // Get 'fileId' parameter - const [fileId, fileIdErr] = $.type(ID).optional().get(params.fileId); + const [fileId, fileIdErr] = $.type(ID).optional.get(params.fileId); if (fileIdErr) return rej('invalid fileId param'); let file = null; diff --git a/src/server/api/endpoints/mute/list.ts b/src/server/api/endpoints/mute/list.ts index 8b0171be3..b632b1a1a 100644 --- a/src/server/api/endpoints/mute/list.ts +++ b/src/server/api/endpoints/mute/list.ts @@ -8,15 +8,15 @@ import { getFriendIds } from '../../common/get-friends'; */ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'iknow' parameter - const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow); + const [iknow = false, iknowErr] = $.bool.optional.get(params.iknow); if (iknowErr) return rej('invalid iknow param'); // Get 'limit' parameter - const [limit = 30, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 30, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'cursor' parameter - const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor); + const [cursor = null, cursorErr] = $.type(ID).optional.get(params.cursor); if (cursorErr) return rej('invalid cursor param'); // Construct query diff --git a/src/server/api/endpoints/my/apps.ts b/src/server/api/endpoints/my/apps.ts index 7687afd0c..8f67af885 100644 --- a/src/server/api/endpoints/my/apps.ts +++ b/src/server/api/endpoints/my/apps.ts @@ -7,11 +7,11 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); const query = { diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts index 5554e53aa..8b0c4177f 100644 --- a/src/server/api/endpoints/notes.ts +++ b/src/server/api/endpoints/notes.ts @@ -9,39 +9,39 @@ import Note, { pack } from '../../../models/note'; */ module.exports = (params: any) => new Promise(async (res, rej) => { // Get 'local' parameter - const [local, localErr] = $.bool.optional().get(params.local); + const [local, localErr] = $.bool.optional.get(params.local); if (localErr) return rej('invalid local param'); // Get 'reply' parameter - const [reply, replyErr] = $.bool.optional().get(params.reply); + const [reply, replyErr] = $.bool.optional.get(params.reply); if (replyErr) return rej('invalid reply param'); // Get 'renote' parameter - const [renote, renoteErr] = $.bool.optional().get(params.renote); + const [renote, renoteErr] = $.bool.optional.get(params.renote); if (renoteErr) return rej('invalid renote param'); // Get 'media' parameter - const [media, mediaErr] = $.bool.optional().get(params.media); + const [media, mediaErr] = $.bool.optional.get(params.media); if (mediaErr) return rej('invalid media param'); // Get 'poll' parameter - const [poll, pollErr] = $.bool.optional().get(params.poll); + const [poll, pollErr] = $.bool.optional.get(params.poll); if (pollErr) return rej('invalid poll param'); // Get 'bot' parameter - //const [bot, botErr] = $.bool.optional().get(params.bot); + //const [bot, botErr] = $.bool.optional.get(params.bot); //if (botErr) return rej('invalid bot param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/notes/conversation.ts b/src/server/api/endpoints/notes/conversation.ts index b2bc6a2e7..a8e8c4eeb 100644 --- a/src/server/api/endpoints/notes/conversation.ts +++ b/src/server/api/endpoints/notes/conversation.ts @@ -11,11 +11,11 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) if (noteIdErr) return rej('invalid noteId param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Lookup note diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 2bd0b430d..043f62cf1 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -1,33 +1,83 @@ import $ from 'cafy'; import ID from '../../../../cafy-id'; import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note'; import User, { ILocalUser, IUser } from '../../../../models/user'; -import DriveFile from '../../../../models/drive-file'; +import DriveFile, { IDriveFile } from '../../../../models/drive-file'; import create from '../../../../services/note/create'; import { IApp } from '../../../../models/app'; import getParams from '../../get-params'; export const meta = { params: { - visibility: { - def: $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']), + visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({ default: 'public', desc: { ja: '投稿の公開範囲' } - }, - visibleUserIds: { - def: $.arr($.type(ID)).optional().unique().min(1), + }), + + visibleUserIds: $.arr($.type(ID)).optional.unique().min(1).note({ desc: { ja: '(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー' } - }, - text: { - def: $.str.optional().nullable().pipe(isValidText), + }), + + text: $.str.optional.nullable.pipe(isValidText).note({ default: null, desc: { ja: '投稿内容' } - }, + }), + + cw: $.str.optional.nullable.pipe(isValidCw).note({ + desc: { + ja: 'コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。' + } + }), + + viaMobile: $.bool.optional.note({ + default: false, + desc: { + ja: 'モバイルデバイスからの投稿か否か。' + } + }), + + geo: $.obj({ + coordinates: $.arr().length(2) + .item(0, $.num.range(-180, 180)) + .item(1, $.num.range(-90, 90)), + altitude: $.num.nullable, + accuracy: $.num.nullable, + altitudeAccuracy: $.num.nullable, + heading: $.num.nullable.range(0, 360), + speed: $.num.nullable + }).optional.nullable.strict().note({ + desc: { + ja: '位置情報' + } + }), + + mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({ + desc: { + ja: '添付するメディア' + } + }), + + renoteId: $.type(ID).optional.note({ + desc: { + ja: 'Renote対象' + } + }), + + poll: $.obj({ + choices: $.arr($.str) + .unique() + .range(2, 10) + .each(c => c.length > 0 && c.length < 50) + }).optional.strict().note({ + desc: { + ja: 'アンケート' + } + }) } }; @@ -45,45 +95,12 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async }))); } - // Get 'text' parameter - const [text = null, textErr] = $.str.optional().nullable().pipe(isValidText).get(params.text); - if (textErr) return rej('invalid text'); - - // Get 'cw' parameter - const [cw, cwErr] = $.str.optional().nullable().pipe(isValidCw).get(params.cw); - if (cwErr) return rej('invalid cw'); - - // Get 'viaMobile' parameter - const [viaMobile = false, viaMobileErr] = $.bool.optional().get(params.viaMobile); - if (viaMobileErr) return rej('invalid viaMobile'); - - // Get 'tags' parameter - const [tags = [], tagsErr] = $.arr($.str.range(1, 32)).optional().unique().get(params.tags); - if (tagsErr) return rej('invalid tags'); - - // Get 'geo' parameter - const [geo, geoErr] = $.obj.optional().nullable().strict() - .have('coordinates', $.arr().length(2) - .item(0, $.num.range(-180, 180)) - .item(1, $.num.range(-90, 90))) - .have('altitude', $.num.nullable()) - .have('accuracy', $.num.nullable()) - .have('altitudeAccuracy', $.num.nullable()) - .have('heading', $.num.nullable().range(0, 360)) - .have('speed', $.num.nullable()) - .get(params.geo); - if (geoErr) return rej('invalid geo'); - - // Get 'mediaIds' parameter - const [mediaIds, mediaIdsErr] = $.arr($.type(ID)).optional().unique().range(1, 4).get(params.mediaIds); - if (mediaIdsErr) return rej('invalid mediaIds'); - - let files = []; - if (mediaIds !== undefined) { + let files: IDriveFile[] = []; + if (ps.mediaIds !== undefined) { // Fetch files // forEach だと途中でエラーなどがあっても return できないので // 敢えて for を使っています。 - for (const mediaId of mediaIds) { + for (const mediaId of ps.mediaIds) { // Fetch file // SELECT _id const entity = await DriveFile.findOne({ @@ -101,15 +118,11 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async files = null; } - // Get 'renoteId' parameter - const [renoteId, renoteIdErr] = $.type(ID).optional().get(params.renoteId); - if (renoteIdErr) return rej('invalid renoteId'); - let renote: INote = null; - if (renoteId !== undefined) { + if (ps.renoteId !== undefined) { // Fetch renote to note renote = await Note.findOne({ - _id: renoteId + _id: ps.renoteId }); if (renote == null) { @@ -120,7 +133,7 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async } // Get 'replyId' parameter - const [replyId, replyIdErr] = $.type(ID).optional().get(params.replyId); + const [replyId, replyIdErr] = $.type(ID).optional.get(params.replyId); if (replyIdErr) return rej('invalid replyId'); let reply: INote = null; @@ -140,17 +153,8 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async } } - // Get 'poll' parameter - const [poll, pollErr] = $.obj.optional().strict() - .have('choices', $.arr($.str) - .unique() - .range(2, 10) - .each(c => c.length > 0 && c.length < 50)) - .get(params.poll); - if (pollErr) return rej('invalid poll'); - - if (poll) { - (poll as any).choices = (poll as any).choices.map((choice: string, i: number) => ({ + if (ps.poll) { + (ps.poll as any).choices = (ps.poll as any).choices.map((choice: string, i: number) => ({ id: i, // IDを付与 text: choice.trim(), votes: 0 @@ -158,7 +162,7 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async } // テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー - if ((text === undefined || text === null) && files === null && renote === null && poll === undefined) { + if ((ps.text === undefined || ps.text === null) && files === null && renote === null && ps.poll === undefined) { return rej('text, mediaIds, renoteId or poll is required'); } @@ -166,17 +170,16 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async const note = await create(user, { createdAt: new Date(), media: files, - poll, - text, + poll: ps.poll, + text: ps.text, reply, renote, - cw, - tags, + cw: ps.cw, app, - viaMobile, - visibility, + viaMobile: ps.viaMobile, + visibility: ps.visibility, visibleUsers, - geo + geo: ps.geo }); const noteObj = await pack(note, user); diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts index 24ffdbcba..d032aa1a6 100644 --- a/src/server/api/endpoints/notes/global-timeline.ts +++ b/src/server/api/endpoints/notes/global-timeline.ts @@ -9,23 +9,23 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = async (params: any, user: ILocalUser) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) throw 'invalid sinceId param'; // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) throw 'invalid untilId param'; // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate); + const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); if (sinceDateErr) throw 'invalid sinceDate param'; // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate); + const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); if (untilDateErr) throw 'invalid untilDate param'; // Check if only one of sinceId, untilId, sinceDate, untilDate specified @@ -34,7 +34,7 @@ module.exports = async (params: any, user: ILocalUser) => { } // Get 'mediaOnly' parameter - const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly); + const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); if (mediaOnlyErr) throw 'invalid mediaOnly param'; // ミュートしているユーザーを取得 diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts index 48490638d..74462ce4e 100644 --- a/src/server/api/endpoints/notes/local-timeline.ts +++ b/src/server/api/endpoints/notes/local-timeline.ts @@ -9,23 +9,23 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = async (params: any, user: ILocalUser) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) throw 'invalid sinceId param'; // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) throw 'invalid untilId param'; // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate); + const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); if (sinceDateErr) throw 'invalid sinceDate param'; // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate); + const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); if (untilDateErr) throw 'invalid untilDate param'; // Check if only one of sinceId, untilId, sinceDate, untilDate specified @@ -34,7 +34,7 @@ module.exports = async (params: any, user: ILocalUser) => { } // Get 'mediaOnly' parameter - const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly); + const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); if (mediaOnlyErr) throw 'invalid mediaOnly param'; // ミュートしているユーザーを取得 diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts index 45511603a..06ddc258b 100644 --- a/src/server/api/endpoints/notes/mentions.ts +++ b/src/server/api/endpoints/notes/mentions.ts @@ -10,19 +10,19 @@ import { ILocalUser } from '../../../../models/user'; module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'following' parameter const [following = false, followingError] = - $.bool.optional().get(params.following); + $.bool.optional.get(params.following); if (followingError) return rej('invalid following param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/notes/polls/recommendation.ts b/src/server/api/endpoints/notes/polls/recommendation.ts index 640140c3d..fb1ee6dda 100644 --- a/src/server/api/endpoints/notes/polls/recommendation.ts +++ b/src/server/api/endpoints/notes/polls/recommendation.ts @@ -8,11 +8,11 @@ import { ILocalUser } from '../../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get votes diff --git a/src/server/api/endpoints/notes/reactions.ts b/src/server/api/endpoints/notes/reactions.ts index d3b2d4343..cf88f3860 100644 --- a/src/server/api/endpoints/notes/reactions.ts +++ b/src/server/api/endpoints/notes/reactions.ts @@ -12,15 +12,15 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) if (noteIdErr) return rej('invalid noteId param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'sort' parameter - const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort); + const [sort = 'desc', sortError] = $.str.optional.or('desc asc').get(params.sort); if (sortError) return rej('invalid sort param'); // Lookup note diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index 4aaf1d322..3b209b317 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -11,11 +11,11 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) if (noteIdErr) return rej('invalid noteId param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Lookup note diff --git a/src/server/api/endpoints/notes/reposts.ts b/src/server/api/endpoints/notes/reposts.ts index ea3f174e1..043a653e8 100644 --- a/src/server/api/endpoints/notes/reposts.ts +++ b/src/server/api/endpoints/notes/reposts.ts @@ -11,15 +11,15 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) if (noteIdErr) return rej('invalid noteId param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/notes/search.ts b/src/server/api/endpoints/notes/search.ts index 20c628b84..3dbf407df 100644 --- a/src/server/api/endpoints/notes/search.ts +++ b/src/server/api/endpoints/notes/search.ts @@ -11,11 +11,11 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (queryError) return rej('invalid query param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit); if (limitErr) return rej('invalid limit param'); es.search({ diff --git a/src/server/api/endpoints/notes/search_by_tag.ts b/src/server/api/endpoints/notes/search_by_tag.ts index 9be7cfffb..78487e2c0 100644 --- a/src/server/api/endpoints/notes/search_by_tag.ts +++ b/src/server/api/endpoints/notes/search_by_tag.ts @@ -14,59 +14,59 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (tagError) return rej('invalid tag param'); // Get 'includeUserIds' parameter - const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional().get(params.includeUserIds); + const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional.get(params.includeUserIds); if (includeUserIdsErr) return rej('invalid includeUserIds param'); // Get 'excludeUserIds' parameter - const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional().get(params.excludeUserIds); + const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional.get(params.excludeUserIds); if (excludeUserIdsErr) return rej('invalid excludeUserIds param'); // Get 'includeUserUsernames' parameter - const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional().get(params.includeUserUsernames); + const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional.get(params.includeUserUsernames); if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param'); // Get 'excludeUserUsernames' parameter - const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional().get(params.excludeUserUsernames); + const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional.get(params.excludeUserUsernames); if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param'); // Get 'following' parameter - const [following = null, followingErr] = $.bool.optional().nullable().get(params.following); + const [following = null, followingErr] = $.bool.optional.nullable.get(params.following); if (followingErr) return rej('invalid following param'); // Get 'mute' parameter - const [mute = 'mute_all', muteErr] = $.str.optional().get(params.mute); + const [mute = 'mute_all', muteErr] = $.str.optional.get(params.mute); if (muteErr) return rej('invalid mute param'); // Get 'reply' parameter - const [reply = null, replyErr] = $.bool.optional().nullable().get(params.reply); + const [reply = null, replyErr] = $.bool.optional.nullable.get(params.reply); if (replyErr) return rej('invalid reply param'); // Get 'renote' parameter - const [renote = null, renoteErr] = $.bool.optional().nullable().get(params.renote); + const [renote = null, renoteErr] = $.bool.optional.nullable.get(params.renote); if (renoteErr) return rej('invalid renote param'); // Get 'media' parameter - const [media = null, mediaErr] = $.bool.optional().nullable().get(params.media); + const [media = null, mediaErr] = $.bool.optional.nullable.get(params.media); if (mediaErr) return rej('invalid media param'); // Get 'poll' parameter - const [poll = null, pollErr] = $.bool.optional().nullable().get(params.poll); + const [poll = null, pollErr] = $.bool.optional.nullable.get(params.poll); if (pollErr) return rej('invalid poll param'); // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate); + const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); if (sinceDateErr) throw 'invalid sinceDate param'; // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate); + const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); if (untilDateErr) throw 'invalid untilDate param'; // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit); if (limitErr) return rej('invalid limit param'); if (includeUserUsernames != null) { diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts index 18c0acd37..9a5306be6 100644 --- a/src/server/api/endpoints/notes/timeline.ts +++ b/src/server/api/endpoints/notes/timeline.ts @@ -10,23 +10,23 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = async (params: any, user: ILocalUser) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) throw 'invalid sinceId param'; // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) throw 'invalid untilId param'; // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate); + const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); if (sinceDateErr) throw 'invalid sinceDate param'; // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate); + const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); if (untilDateErr) throw 'invalid untilDate param'; // Check if only one of sinceId, untilId, sinceDate, untilDate specified @@ -35,15 +35,15 @@ module.exports = async (params: any, user: ILocalUser) => { } // Get 'includeMyRenotes' parameter - const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes); + const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes); if (includeMyRenotesErr) throw 'invalid includeMyRenotes param'; // Get 'includeRenotedMyNotes' parameter - const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes); + const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes); if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param'; // Get 'mediaOnly' parameter - const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly); + const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); if (mediaOnlyErr) throw 'invalid mediaOnly param'; const [followings, mutedUserIds] = await Promise.all([ diff --git a/src/server/api/endpoints/notes/trend.ts b/src/server/api/endpoints/notes/trend.ts index 9c0a1bb11..b4acd7c5f 100644 --- a/src/server/api/endpoints/notes/trend.ts +++ b/src/server/api/endpoints/notes/trend.ts @@ -8,27 +8,27 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'reply' parameter - const [reply, replyErr] = $.bool.optional().get(params.reply); + const [reply, replyErr] = $.bool.optional.get(params.reply); if (replyErr) return rej('invalid reply param'); // Get 'renote' parameter - const [renote, renoteErr] = $.bool.optional().get(params.renote); + const [renote, renoteErr] = $.bool.optional.get(params.renote); if (renoteErr) return rej('invalid renote param'); // Get 'media' parameter - const [media, mediaErr] = $.bool.optional().get(params.media); + const [media, mediaErr] = $.bool.optional.get(params.media); if (mediaErr) return rej('invalid media param'); // Get 'poll' parameter - const [poll, pollErr] = $.bool.optional().get(params.poll); + const [poll, pollErr] = $.bool.optional.get(params.poll); if (pollErr) return rej('invalid poll param'); const query = { diff --git a/src/server/api/endpoints/notes/user-list-timeline.ts b/src/server/api/endpoints/notes/user-list-timeline.ts index 8aa800b71..f14a869c7 100644 --- a/src/server/api/endpoints/notes/user-list-timeline.ts +++ b/src/server/api/endpoints/notes/user-list-timeline.ts @@ -10,23 +10,23 @@ import { ILocalUser } from '../../../../models/user'; */ module.exports = async (params: any, user: ILocalUser) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) throw 'invalid sinceId param'; // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) throw 'invalid untilId param'; // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate); + const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); if (sinceDateErr) throw 'invalid sinceDate param'; // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate); + const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); if (untilDateErr) throw 'invalid untilDate param'; // Check if only one of sinceId, untilId, sinceDate, untilDate specified @@ -35,15 +35,15 @@ module.exports = async (params: any, user: ILocalUser) => { } // Get 'includeMyRenotes' parameter - const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes); + const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes); if (includeMyRenotesErr) throw 'invalid includeMyRenotes param'; // Get 'includeRenotedMyNotes' parameter - const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes); + const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes); if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param'; // Get 'mediaOnly' parameter - const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly); + const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); if (mediaOnlyErr) throw 'invalid mediaOnly param'; // Get 'listId' parameter diff --git a/src/server/api/endpoints/reversi/games.ts b/src/server/api/endpoints/reversi/games.ts index 1455f191f..e68f57c6d 100644 --- a/src/server/api/endpoints/reversi/games.ts +++ b/src/server/api/endpoints/reversi/games.ts @@ -4,19 +4,19 @@ import { ILocalUser } from '../../../../models/user'; module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'my' parameter - const [my = false, myErr] = $.bool.optional().get(params.my); + const [my = false, myErr] = $.bool.optional.get(params.my); if (myErr) return rej('invalid my param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Check if both of sinceId and untilId is specified diff --git a/src/server/api/endpoints/users.ts b/src/server/api/endpoints/users.ts index b8df6f3ec..0756ddc91 100644 --- a/src/server/api/endpoints/users.ts +++ b/src/server/api/endpoints/users.ts @@ -6,15 +6,15 @@ import User, { pack, ILocalUser } from '../../../models/user'; */ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'sort' parameter - const [sort, sortError] = $.str.optional().or('+follower|-follower').get(params.sort); + const [sort, sortError] = $.str.optional.or('+follower|-follower').get(params.sort); if (sortError) return rej('invalid sort param'); // Construct query diff --git a/src/server/api/endpoints/users/followers.ts b/src/server/api/endpoints/users/followers.ts index 53133ee96..ef36a0df4 100644 --- a/src/server/api/endpoints/users/followers.ts +++ b/src/server/api/endpoints/users/followers.ts @@ -13,15 +13,15 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (userIdErr) return rej('invalid userId param'); // Get 'iknow' parameter - const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow); + const [iknow = false, iknowErr] = $.bool.optional.get(params.iknow); if (iknowErr) return rej('invalid iknow param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'cursor' parameter - const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor); + const [cursor = null, cursorErr] = $.type(ID).optional.get(params.cursor); if (cursorErr) return rej('invalid cursor param'); // Lookup user diff --git a/src/server/api/endpoints/users/following.ts b/src/server/api/endpoints/users/following.ts index 206120019..2c38fe4f8 100644 --- a/src/server/api/endpoints/users/following.ts +++ b/src/server/api/endpoints/users/following.ts @@ -13,15 +13,15 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (userIdErr) return rej('invalid userId param'); // Get 'iknow' parameter - const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow); + const [iknow = false, iknowErr] = $.bool.optional.get(params.iknow); if (iknowErr) return rej('invalid iknow param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'cursor' parameter - const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor); + const [cursor = null, cursorErr] = $.type(ID).optional.get(params.cursor); if (cursorErr) return rej('invalid cursor param'); // Lookup user 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 ba8779d33..607742090 100644 --- a/src/server/api/endpoints/users/get_frequently_replied_users.ts +++ b/src/server/api/endpoints/users/get_frequently_replied_users.ts @@ -8,7 +8,7 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (userIdErr) return rej('invalid userId param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Lookup user diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts index 222a8d950..ac4e17946 100644 --- a/src/server/api/endpoints/users/notes.ts +++ b/src/server/api/endpoints/users/notes.ts @@ -8,11 +8,11 @@ import User, { ILocalUser } from '../../../../models/user'; */ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).optional().get(params.userId); + const [userId, userIdErr] = $.type(ID).optional.get(params.userId); if (userIdErr) return rej('invalid userId param'); // Get 'username' parameter - const [username, usernameErr] = $.str.optional().get(params.username); + const [username, usernameErr] = $.str.optional.get(params.username); if (usernameErr) return rej('invalid username param'); if (userId === undefined && username === undefined) { @@ -20,7 +20,7 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = } // Get 'host' parameter - const [host, hostErr] = $.str.optional().get(params.host); + const [host, hostErr] = $.str.optional.get(params.host); if (hostErr) return rej('invalid host param'); if (userId === undefined && host === undefined) { @@ -28,31 +28,31 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = } // Get 'includeReplies' parameter - const [includeReplies = true, includeRepliesErr] = $.bool.optional().get(params.includeReplies); + const [includeReplies = true, includeRepliesErr] = $.bool.optional.get(params.includeReplies); if (includeRepliesErr) return rej('invalid includeReplies param'); // Get 'withMedia' parameter - const [withMedia = false, withMediaErr] = $.bool.optional().get(params.withMedia); + const [withMedia = false, withMediaErr] = $.bool.optional.get(params.withMedia); if (withMediaErr) return rej('invalid withMedia param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId); + const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); if (sinceIdErr) return rej('invalid sinceId param'); // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId); + const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); if (untilIdErr) return rej('invalid untilId param'); // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate); + const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); if (sinceDateErr) throw 'invalid sinceDate param'; // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate); + const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); if (untilDateErr) throw 'invalid untilDate param'; // Check if only one of sinceId, untilId, sinceDate, untilDate specified diff --git a/src/server/api/endpoints/users/recommendation.ts b/src/server/api/endpoints/users/recommendation.ts index 1d0d889f1..6221d751b 100644 --- a/src/server/api/endpoints/users/recommendation.ts +++ b/src/server/api/endpoints/users/recommendation.ts @@ -9,11 +9,11 @@ import Mute from '../../../../models/mute'; */ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // ID list of the user itself and other users who the user follows diff --git a/src/server/api/endpoints/users/search.ts b/src/server/api/endpoints/users/search.ts index e29c8d32f..36a708d21 100644 --- a/src/server/api/endpoints/users/search.ts +++ b/src/server/api/endpoints/users/search.ts @@ -11,7 +11,7 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (queryError) return rej('invalid query param'); // Get 'max' parameter - const [max = 10, maxErr] = $.num.optional().range(1, 30).get(params.max); + const [max = 10, maxErr] = $.num.optional.range(1, 30).get(params.max); if (maxErr) return rej('invalid max param'); const escapedQuery = escapeRegexp(query); diff --git a/src/server/api/endpoints/users/search_by_username.ts b/src/server/api/endpoints/users/search_by_username.ts index 937f9af58..1c0f09449 100644 --- a/src/server/api/endpoints/users/search_by_username.ts +++ b/src/server/api/endpoints/users/search_by_username.ts @@ -10,11 +10,11 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = if (queryError) return rej('invalid query param'); // Get 'offset' parameter - const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset); + const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset); if (offsetErr) return rej('invalid offset param'); // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit); + const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); let users = await User diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts index bf7e2a231..5cbd83f64 100644 --- a/src/server/api/endpoints/users/show.ts +++ b/src/server/api/endpoints/users/show.ts @@ -11,19 +11,19 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) = let user; // Get 'userId' parameter - const [userId, userIdErr] = $.type(ID).optional().get(params.userId); + const [userId, userIdErr] = $.type(ID).optional.get(params.userId); if (userIdErr) return rej('invalid userId param'); // Get 'userIds' parameter - const [userIds, userIdsErr] = $.arr($.type(ID)).optional().get(params.userIds); + const [userIds, userIdsErr] = $.arr($.type(ID)).optional.get(params.userIds); if (userIdsErr) return rej('invalid userIds param'); // Get 'username' parameter - const [username, usernameErr] = $.str.optional().get(params.username); + const [username, usernameErr] = $.str.optional.get(params.username); if (usernameErr) return rej('invalid username param'); // Get 'host' parameter - const [host, hostErr] = $.str.optional().nullable().get(params.host); + const [host, hostErr] = $.str.optional.nullable.get(params.host); if (hostErr) return rej('invalid host param'); if (userIds) { diff --git a/src/server/api/get-params.ts b/src/server/api/get-params.ts index 6b047a28f..e495e3ef3 100644 --- a/src/server/api/get-params.ts +++ b/src/server/api/get-params.ts @@ -1,25 +1,22 @@ -import { Query } from 'cafy'; +import { Context } from 'cafy'; type Defs = { - params: {[key: string]: { - def: Query; - default?: any; - }} + params: { [key: string]: Context } }; export default function (defs: T, params: any): [{ - [P in keyof T['params']]: ReturnType[0]; + [P in keyof T['params']]: ReturnType[0]; }, Error] { const x: any = {}; let err: Error = null; Object.keys(defs.params).some(k => { - const [v, e] = defs.params[k].def.get(params[k]); + const [v, e] = defs.params[k].get(params[k]); if (e) { err = e; return true; } else { - if (v === undefined && defs.params[k].default) { - x[k] = defs.params[k].default; + if (v === undefined && defs.params[k].data.default) { + x[k] = defs.params[k].data.default; } else { x[k] = v; } From 10e9d3f32fd219b4337dc01146a4a88d9e801b36 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 5 Jul 2018 23:47:36 +0900 Subject: [PATCH 03/13] wip --- .../docs/api/endpoints/notes/create.yaml | 59 ------------------- .../docs/api/endpoints/notes/timeline.yaml | 32 ---------- src/server/api/endpoints/notes/create.ts | 13 ++++ 3 files changed, 13 insertions(+), 91 deletions(-) delete mode 100644 src/client/docs/api/endpoints/notes/create.yaml delete mode 100644 src/client/docs/api/endpoints/notes/timeline.yaml diff --git a/src/client/docs/api/endpoints/notes/create.yaml b/src/client/docs/api/endpoints/notes/create.yaml deleted file mode 100644 index 04ada2ecd..000000000 --- a/src/client/docs/api/endpoints/notes/create.yaml +++ /dev/null @@ -1,59 +0,0 @@ -endpoint: "notes/create" - -desc: - ja: "投稿します。" - en: "Compose new note." - -params: - - name: "text" - type: "string" - optional: true - desc: - ja: "投稿の本文" - en: "The text of your note" - - name: "cw" - type: "string" - optional: true - desc: - ja: "コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。" - en: "Content Warning" - - name: "mediaIds" - type: "id(DriveFile)[]" - optional: true - desc: - ja: "添付するメディア(1~4つ)" - en: "Media you want to attach (1~4)" - - name: "replyId" - type: "id(Note)" - optional: true - desc: - ja: "返信する投稿" - en: "The note you want to reply" - - name: "renoteId" - type: "id(Note)" - optional: true - desc: - ja: "引用する投稿" - en: "The note you want to quote" - - name: "poll" - type: "object" - optional: true - desc: - ja: "投票" - en: "The poll" - defName: "poll" - def: - - name: "choices" - type: "string[]" - optional: false - desc: - ja: "投票の選択肢" - en: "Choices of a poll" - -res: - - name: "createdNote" - type: "entity(Note)" - optional: false - desc: - ja: "作成した投稿" - en: "A note that created" diff --git a/src/client/docs/api/endpoints/notes/timeline.yaml b/src/client/docs/api/endpoints/notes/timeline.yaml deleted file mode 100644 index 71c346f35..000000000 --- a/src/client/docs/api/endpoints/notes/timeline.yaml +++ /dev/null @@ -1,32 +0,0 @@ -endpoint: "notes/timeline" - -desc: - ja: "タイムラインを取得します。" - en: "Get your timeline." - -params: - - name: "limit" - type: "number" - optional: true - desc: - ja: "取得する最大の数" - - name: "sinceId" - type: "id(Note)" - optional: true - desc: - ja: "指定すると、この投稿を基点としてより新しい投稿を取得します" - - name: "untilId" - type: "id(Note)" - optional: true - desc: - ja: "指定すると、この投稿を基点としてより古い投稿を取得します" - - name: "sinceDate" - type: "number" - optional: true - desc: - ja: "指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。" - - name: "untilDate" - type: "number" - optional: true - desc: - ja: "指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。" diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 043f62cf1..df772b3b3 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -7,6 +7,9 @@ import { IApp } from '../../../../models/app'; import getParams from '../../get-params'; export const meta = { + desc: { + ja: '投稿します。' + }, params: { visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({ default: 'public', @@ -78,6 +81,16 @@ export const meta = { ja: 'アンケート' } }) + }, + res: { + data: { + createdNote: { + type: 'entity(Note)', + desc: { + ja: '作成した投稿' + } + } + } } }; From fcfd9239c194e5b9d9beefec5e63fd913579d827 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 00:04:40 +0900 Subject: [PATCH 04/13] wip --- src/server/api/endpoints/notes/create.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index df772b3b3..62eafa534 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -10,6 +10,7 @@ export const meta = { desc: { ja: '投稿します。' }, + params: { visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({ default: 'public', @@ -82,8 +83,10 @@ export const meta = { } }) }, + res: { - data: { + type: 'object', + object: { createdNote: { type: 'entity(Note)', desc: { From 9b41023c43add194d69259e0a8a8c323aa44c778 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 02:58:29 +0900 Subject: [PATCH 05/13] wip --- package.json | 2 +- src/client/docs/api/gulpfile.ts | 48 +++++++------ src/client/docs/gulpfile.ts | 4 +- src/server/api/endpoints/aggregation/posts.ts | 2 +- src/server/api/endpoints/aggregation/users.ts | 2 +- .../endpoints/aggregation/users/activity.ts | 2 +- .../endpoints/aggregation/users/followers.ts | 2 +- .../endpoints/aggregation/users/following.ts | 2 +- .../api/endpoints/aggregation/users/post.ts | 2 +- .../endpoints/aggregation/users/reaction.ts | 2 +- src/server/api/endpoints/app/create.ts | 2 +- .../api/endpoints/app/name_id/available.ts | 2 +- src/server/api/endpoints/app/show.ts | 2 +- src/server/api/endpoints/auth/accept.ts | 2 +- .../api/endpoints/auth/session/generate.ts | 2 +- src/server/api/endpoints/auth/session/show.ts | 2 +- .../api/endpoints/auth/session/userkey.ts | 2 +- src/server/api/endpoints/drive.ts | 2 +- src/server/api/endpoints/drive/files.ts | 2 +- .../api/endpoints/drive/files/create.ts | 2 +- .../api/endpoints/drive/files/delete.ts | 2 +- src/server/api/endpoints/drive/files/find.ts | 2 +- src/server/api/endpoints/drive/files/show.ts | 2 +- .../api/endpoints/drive/files/update.ts | 2 +- .../endpoints/drive/files/upload_from_url.ts | 2 +- src/server/api/endpoints/drive/folders.ts | 2 +- .../api/endpoints/drive/folders/create.ts | 2 +- .../api/endpoints/drive/folders/find.ts | 2 +- .../api/endpoints/drive/folders/show.ts | 2 +- .../api/endpoints/drive/folders/update.ts | 2 +- src/server/api/endpoints/drive/stream.ts | 2 +- src/server/api/endpoints/following/create.ts | 2 +- src/server/api/endpoints/following/delete.ts | 2 +- .../endpoints/following/requests/accept.ts | 2 +- .../endpoints/following/requests/cancel.ts | 2 +- .../api/endpoints/following/requests/list.ts | 2 +- .../endpoints/following/requests/reject.ts | 2 +- src/server/api/endpoints/following/stalk.ts | 2 +- src/server/api/endpoints/following/unstalk.ts | 2 +- src/server/api/endpoints/hashtags/trend.ts | 2 +- src/server/api/endpoints/i.ts | 2 +- src/server/api/endpoints/i/2fa/done.ts | 2 +- src/server/api/endpoints/i/2fa/register.ts | 2 +- src/server/api/endpoints/i/2fa/unregister.ts | 2 +- src/server/api/endpoints/i/authorized_apps.ts | 2 +- src/server/api/endpoints/i/change_password.ts | 2 +- src/server/api/endpoints/i/favorites.ts | 2 +- src/server/api/endpoints/i/notifications.ts | 2 +- src/server/api/endpoints/i/pin.ts | 2 +- .../api/endpoints/i/regenerate_token.ts | 2 +- src/server/api/endpoints/i/signin_history.ts | 2 +- src/server/api/endpoints/i/update.ts | 2 +- .../api/endpoints/i/update_client_setting.ts | 2 +- src/server/api/endpoints/i/update_home.ts | 2 +- .../api/endpoints/i/update_mobile_home.ts | 2 +- src/server/api/endpoints/i/update_widget.ts | 2 +- src/server/api/endpoints/messaging/history.ts | 2 +- .../api/endpoints/messaging/messages.ts | 2 +- .../endpoints/messaging/messages/create.ts | 2 +- src/server/api/endpoints/meta.ts | 2 +- src/server/api/endpoints/mute/create.ts | 2 +- src/server/api/endpoints/mute/delete.ts | 2 +- src/server/api/endpoints/mute/list.ts | 2 +- src/server/api/endpoints/my/apps.ts | 2 +- src/server/api/endpoints/notes.ts | 2 +- .../api/endpoints/notes/conversation.ts | 2 +- src/server/api/endpoints/notes/create.ts | 10 ++- src/server/api/endpoints/notes/delete.ts | 2 +- .../api/endpoints/notes/favorites/create.ts | 2 +- .../api/endpoints/notes/favorites/delete.ts | 2 +- .../api/endpoints/notes/global-timeline.ts | 2 +- .../api/endpoints/notes/local-timeline.ts | 2 +- src/server/api/endpoints/notes/mentions.ts | 2 +- .../endpoints/notes/polls/recommendation.ts | 2 +- src/server/api/endpoints/notes/polls/vote.ts | 2 +- src/server/api/endpoints/notes/reactions.ts | 2 +- .../api/endpoints/notes/reactions/create.ts | 2 +- .../api/endpoints/notes/reactions/delete.ts | 2 +- src/server/api/endpoints/notes/replies.ts | 2 +- src/server/api/endpoints/notes/reposts.ts | 2 +- src/server/api/endpoints/notes/search.ts | 2 +- .../api/endpoints/notes/search_by_tag.ts | 2 +- src/server/api/endpoints/notes/show.ts | 2 +- src/server/api/endpoints/notes/timeline.ts | 2 +- src/server/api/endpoints/notes/trend.ts | 2 +- .../api/endpoints/notes/user-list-timeline.ts | 2 +- .../notifications/mark_as_read_all.ts | 2 +- src/server/api/endpoints/reversi/games.ts | 2 +- .../api/endpoints/reversi/games/show.ts | 2 +- .../api/endpoints/reversi/invitations.ts | 2 +- src/server/api/endpoints/reversi/match.ts | 2 +- .../api/endpoints/reversi/match/cancel.ts | 2 +- src/server/api/endpoints/stats.ts | 2 +- src/server/api/endpoints/sw/register.ts | 2 +- .../api/endpoints/username/available.ts | 2 +- src/server/api/endpoints/users.ts | 2 +- src/server/api/endpoints/users/followers.ts | 2 +- src/server/api/endpoints/users/following.ts | 2 +- .../users/get_frequently_replied_users.ts | 2 +- .../api/endpoints/users/lists/create.ts | 2 +- src/server/api/endpoints/users/lists/list.ts | 2 +- src/server/api/endpoints/users/lists/push.ts | 2 +- src/server/api/endpoints/users/lists/show.ts | 2 +- src/server/api/endpoints/users/notes.ts | 2 +- .../api/endpoints/users/recommendation.ts | 2 +- src/server/api/endpoints/users/search.ts | 2 +- .../api/endpoints/users/search_by_username.ts | 2 +- src/server/api/endpoints/users/show.ts | 2 +- src/server/web/docs.ts | 70 +++++++++++++++++++ 109 files changed, 212 insertions(+), 130 deletions(-) diff --git a/package.json b/package.json index 42b8fdf5e..3663d42c4 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "autwh": "0.1.0", "bcryptjs": "2.4.3", "bootstrap-vue": "2.0.0-rc.11", - "cafy": "11.0.0", + "cafy": "11.1.0", "chalk": "2.4.1", "crc-32": "1.2.0", "css-loader": "0.28.11", diff --git a/src/client/docs/api/gulpfile.ts b/src/client/docs/api/gulpfile.ts index 0eb8b8828..4b38058b5 100644 --- a/src/client/docs/api/gulpfile.ts +++ b/src/client/docs/api/gulpfile.ts @@ -16,12 +16,13 @@ import fa from '../../../build/fa'; import config from './../../../config'; import generateVars from '../vars'; +import { Context } from 'cafy'; +import ObjectContext from 'cafy/built/types/object'; const langs = Object.keys(locales); const kebab = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); -// WIP type const parseParam = (param: any) => { const id = param.type.match(/^id\((.+?)\)|^id/); const entity = param.type.match(/^entity\((.+?)\)/); @@ -58,6 +59,14 @@ const parseParam = (param: any) => { return param; }; +// WIP type +const parseEPDefParam = (key: string, param: Context) => { + return Object.assign({ + name: key, + type: param.getType() + }, param.data); +}; + const sortParams = (params: Array<{name: string}>) => { params.sort((a, b) => { if (a.name < b.name) @@ -70,17 +79,18 @@ const sortParams = (params: Array<{name: string}>) => { }; // WIP type -const extractDefs = (params: any[]) => { +const extractDefs = (params: Context[]) => { let defs: any[] = []; params.forEach(param => { - if (param.def) { + if (param.data && param.data.ref) { + const props = (param as ObjectContext).props; defs.push({ - name: param.defName, - params: sortParams(param.def.map((p: any) => parseParam(p))) + name: param.data.ref, + params: sortParams(Object.keys(props).map(k => parseEPDefParam(k, props[k]))) }); - const childDefs = extractDefs(param.def); + const childDefs = extractDefs(Object.keys(props).map(k => props[k])); defs = defs.concat(childDefs); } @@ -94,35 +104,33 @@ gulp.task('doc:api', [ 'doc:api:entities' ]); -gulp.task('doc:api:endpoints', async () => { +gulp.task('doc:api:endpoints', ['build:ts'], async () => { const commonVars = await generateVars(); - glob('./src/client/docs/api/endpoints/**/*.yaml', (globErr, files) => { + glob('./built/server/api/endpoints/**/*.js', (globErr, files) => { if (globErr) { console.error(globErr); return; } - //console.log(files); - files.forEach(file => { - const ep: any = yaml.safeLoad(fs.readFileSync(file, 'utf-8')); + console.log(files.map(file => require('../../../../' + file))); + + files.map(file => require('../../../../' + file)).filter(x => x.meta).map(x => x.meta).forEach(ep => { + console.log(ep); const vars = { - endpoint: ep.endpoint, + endpoint: ep.name, url: { host: config.api_url, - path: ep.endpoint + path: ep.name }, desc: ep.desc, // @ts-ignore - params: sortParams(ep.params.map(p => parseParam(p))), + params: sortParams(ep.params.map(p => parseEPDefParam(p))), paramDefs: extractDefs(ep.params), - // @ts-ignore - res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null, - resDefs: ep.res ? extractDefs(ep.res) : null, }; langs.forEach(lang => { pug.renderFile('./src/client/docs/api/endpoints/view.pug', Object.assign({}, vars, { lang, - title: ep.endpoint, - src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/api/endpoints/${ep.endpoint}.yaml`, + title: ep.name, + src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/api/endpoints/${ep.name}.yaml`, kebab, common: commonVars }), (renderErr, html) => { @@ -133,7 +141,7 @@ gulp.task('doc:api:endpoints', async () => { const i18n = new I18nReplacer(lang); html = html.replace(i18n.pattern, i18n.replacement); html = fa(html); - const htmlPath = `./built/client/docs/${lang}/api/endpoints/${ep.endpoint}.html`; + const htmlPath = `./built/client/docs/${lang}/api/endpoints/${ep.name}.html`; mkdirp(path.dirname(htmlPath), (mkdirErr) => { if (mkdirErr) { console.error(mkdirErr); diff --git a/src/client/docs/gulpfile.ts b/src/client/docs/gulpfile.ts index 4683a0465..5ef87315f 100644 --- a/src/client/docs/gulpfile.ts +++ b/src/client/docs/gulpfile.ts @@ -15,11 +15,11 @@ import I18nReplacer from '../../build/i18n'; import fa from '../../build/fa'; import generateVars from './vars'; -require('./api/gulpfile.ts'); +//require('./api/gulpfile.ts'); gulp.task('doc', [ 'doc:docs', - 'doc:api', + //'doc:api', 'doc:styles' ]); diff --git a/src/server/api/endpoints/aggregation/posts.ts b/src/server/api/endpoints/aggregation/posts.ts index 5de578995..629bb1910 100644 --- a/src/server/api/endpoints/aggregation/posts.ts +++ b/src/server/api/endpoints/aggregation/posts.ts @@ -4,7 +4,7 @@ import Note from '../../../../models/note'; /** * Aggregate notes */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/aggregation/users.ts b/src/server/api/endpoints/aggregation/users.ts index 3ab96b66d..f1e41cf17 100644 --- a/src/server/api/endpoints/aggregation/users.ts +++ b/src/server/api/endpoints/aggregation/users.ts @@ -4,7 +4,7 @@ import User from '../../../../models/user'; /** * Aggregate users */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/aggregation/users/activity.ts b/src/server/api/endpoints/aggregation/users/activity.ts index 98c7d3a1d..4afa6d120 100644 --- a/src/server/api/endpoints/aggregation/users/activity.ts +++ b/src/server/api/endpoints/aggregation/users/activity.ts @@ -7,7 +7,7 @@ import Note from '../../../../../models/note'; /** * Aggregate activity of a user */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/aggregation/users/followers.ts b/src/server/api/endpoints/aggregation/users/followers.ts index 847f37607..484c58ad3 100644 --- a/src/server/api/endpoints/aggregation/users/followers.ts +++ b/src/server/api/endpoints/aggregation/users/followers.ts @@ -8,7 +8,7 @@ import FollowedLog from '../../../../../models/followed-log'; /** * Aggregate followers of a user */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/aggregation/users/following.ts b/src/server/api/endpoints/aggregation/users/following.ts index 6c52752f9..16812a9f0 100644 --- a/src/server/api/endpoints/aggregation/users/following.ts +++ b/src/server/api/endpoints/aggregation/users/following.ts @@ -8,7 +8,7 @@ import FollowingLog from '../../../../../models/following-log'; /** * Aggregate following of a user */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/aggregation/users/post.ts b/src/server/api/endpoints/aggregation/users/post.ts index 28ba1482b..4965d3c7a 100644 --- a/src/server/api/endpoints/aggregation/users/post.ts +++ b/src/server/api/endpoints/aggregation/users/post.ts @@ -5,7 +5,7 @@ import Note from '../../../../../models/note'; /** * Aggregate note of a user */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/aggregation/users/reaction.ts b/src/server/api/endpoints/aggregation/users/reaction.ts index adb5acfb4..20b5e93d5 100644 --- a/src/server/api/endpoints/aggregation/users/reaction.ts +++ b/src/server/api/endpoints/aggregation/users/reaction.ts @@ -5,7 +5,7 @@ import Reaction from '../../../../../models/note-reaction'; /** * Aggregate reaction of a user */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/app/create.ts b/src/server/api/endpoints/app/create.ts index 5da87e5a3..3b3eafa69 100644 --- a/src/server/api/endpoints/app/create.ts +++ b/src/server/api/endpoints/app/create.ts @@ -59,7 +59,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Create an app */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'nameId' parameter const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId); if (nameIdErr) return rej('invalid nameId param'); diff --git a/src/server/api/endpoints/app/name_id/available.ts b/src/server/api/endpoints/app/name_id/available.ts index 58101a7e6..9f6e8dc34 100644 --- a/src/server/api/endpoints/app/name_id/available.ts +++ b/src/server/api/endpoints/app/name_id/available.ts @@ -40,7 +40,7 @@ import { isValidNameId } from '../../../../../models/app'; * @param {any} params * @return {Promise} */ -module.exports = async (params: any) => new Promise(async (res, rej) => { +export default async (params: any) => new Promise(async (res, rej) => { // Get 'nameId' parameter const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId); if (nameIdErr) return rej('invalid nameId param'); diff --git a/src/server/api/endpoints/app/show.ts b/src/server/api/endpoints/app/show.ts index 982c87c4e..2b8a92954 100644 --- a/src/server/api/endpoints/app/show.ts +++ b/src/server/api/endpoints/app/show.ts @@ -35,7 +35,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Show an app */ -module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { const isSecure = user != null && app == null; // Get 'appId' parameter diff --git a/src/server/api/endpoints/auth/accept.ts b/src/server/api/endpoints/auth/accept.ts index fc6cbc473..d14c85341 100644 --- a/src/server/api/endpoints/auth/accept.ts +++ b/src/server/api/endpoints/auth/accept.ts @@ -32,7 +32,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Accept */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'token' parameter const [token, tokenErr] = $.str.get(params.token); if (tokenErr) return rej('invalid token param'); diff --git a/src/server/api/endpoints/auth/session/generate.ts b/src/server/api/endpoints/auth/session/generate.ts index 5a4d99ff3..f70495fa4 100644 --- a/src/server/api/endpoints/auth/session/generate.ts +++ b/src/server/api/endpoints/auth/session/generate.ts @@ -44,7 +44,7 @@ import config from '../../../../../config'; * @param {any} params * @return {Promise} */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'appSecret' parameter const [appSecret, appSecretErr] = $.str.get(params.appSecret); if (appSecretErr) return rej('invalid appSecret param'); diff --git a/src/server/api/endpoints/auth/session/show.ts b/src/server/api/endpoints/auth/session/show.ts index 3d3b6bbf6..3716b49c5 100644 --- a/src/server/api/endpoints/auth/session/show.ts +++ b/src/server/api/endpoints/auth/session/show.ts @@ -45,7 +45,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Show a session */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'token' parameter const [token, tokenErr] = $.str.get(params.token); if (tokenErr) return rej('invalid token param'); diff --git a/src/server/api/endpoints/auth/session/userkey.ts b/src/server/api/endpoints/auth/session/userkey.ts index 3ea48fbe3..8d67c2bda 100644 --- a/src/server/api/endpoints/auth/session/userkey.ts +++ b/src/server/api/endpoints/auth/session/userkey.ts @@ -49,7 +49,7 @@ import { pack } from '../../../../../models/user'; * @param {any} params * @return {Promise} */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'appSecret' parameter const [appSecret, appSecretErr] = $.str.get(params.appSecret); if (appSecretErr) return rej('invalid appSecret param'); diff --git a/src/server/api/endpoints/drive.ts b/src/server/api/endpoints/drive.ts index 9caad273c..66ac30c4c 100644 --- a/src/server/api/endpoints/drive.ts +++ b/src/server/api/endpoints/drive.ts @@ -4,7 +4,7 @@ import { ILocalUser } from '../../../models/user'; /** * Get drive information */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Calculate drive usage const usage = await DriveFile .aggregate([{ diff --git a/src/server/api/endpoints/drive/files.ts b/src/server/api/endpoints/drive/files.ts index fa99c4a51..c0b6c3b06 100644 --- a/src/server/api/endpoints/drive/files.ts +++ b/src/server/api/endpoints/drive/files.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get drive files */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; diff --git a/src/server/api/endpoints/drive/files/create.ts b/src/server/api/endpoints/drive/files/create.ts index 4c348c130..5a2bef38c 100644 --- a/src/server/api/endpoints/drive/files/create.ts +++ b/src/server/api/endpoints/drive/files/create.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Create a file */ -module.exports = async (file: any, params: any, user: ILocalUser): Promise => { +export default async (file: any, params: any, user: ILocalUser): Promise => { if (file == null) { throw 'file is required'; } diff --git a/src/server/api/endpoints/drive/files/delete.ts b/src/server/api/endpoints/drive/files/delete.ts index 17eb0eb4b..992f0286f 100644 --- a/src/server/api/endpoints/drive/files/delete.ts +++ b/src/server/api/endpoints/drive/files/delete.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Delete a file */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'fileId' parameter const [fileId, fileIdErr] = $.type(ID).get(params.fileId); if (fileIdErr) throw 'invalid fileId param'; diff --git a/src/server/api/endpoints/drive/files/find.ts b/src/server/api/endpoints/drive/files/find.ts index dfca4e039..ed7674973 100644 --- a/src/server/api/endpoints/drive/files/find.ts +++ b/src/server/api/endpoints/drive/files/find.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Find a file(s) */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'name' parameter const [name, nameErr] = $.str.get(params.name); if (nameErr) return rej('invalid name param'); diff --git a/src/server/api/endpoints/drive/files/show.ts b/src/server/api/endpoints/drive/files/show.ts index e7dca486c..2e4ac06bf 100644 --- a/src/server/api/endpoints/drive/files/show.ts +++ b/src/server/api/endpoints/drive/files/show.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Show a file */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'fileId' parameter const [fileId, fileIdErr] = $.type(ID).get(params.fileId); if (fileIdErr) throw 'invalid fileId param'; diff --git a/src/server/api/endpoints/drive/files/update.ts b/src/server/api/endpoints/drive/files/update.ts index 76656beaa..73a193a56 100644 --- a/src/server/api/endpoints/drive/files/update.ts +++ b/src/server/api/endpoints/drive/files/update.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Update a file */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'fileId' parameter const [fileId, fileIdErr] = $.type(ID).get(params.fileId); if (fileIdErr) return rej('invalid fileId param'); diff --git a/src/server/api/endpoints/drive/files/upload_from_url.ts b/src/server/api/endpoints/drive/files/upload_from_url.ts index 442a0d394..7218b345b 100644 --- a/src/server/api/endpoints/drive/files/upload_from_url.ts +++ b/src/server/api/endpoints/drive/files/upload_from_url.ts @@ -9,7 +9,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Create a file from a URL */ -module.exports = async (params: any, user: ILocalUser): Promise => { +export default async (params: any, user: ILocalUser): Promise => { // Get 'url' parameter // TODO: Validate this url const [url, urlErr] = $.str.get(params.url); diff --git a/src/server/api/endpoints/drive/folders.ts b/src/server/api/endpoints/drive/folders.ts index 878c747a4..70f581f42 100644 --- a/src/server/api/endpoints/drive/folders.ts +++ b/src/server/api/endpoints/drive/folders.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get drive folders */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/drive/folders/create.ts b/src/server/api/endpoints/drive/folders/create.ts index c06a40ded..60c738389 100644 --- a/src/server/api/endpoints/drive/folders/create.ts +++ b/src/server/api/endpoints/drive/folders/create.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Create drive folder */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'name' parameter const [name = '無題のフォルダー', nameErr] = $.str.optional.pipe(isValidFolderName).get(params.name); if (nameErr) return rej('invalid name param'); diff --git a/src/server/api/endpoints/drive/folders/find.ts b/src/server/api/endpoints/drive/folders/find.ts index 414202ccd..2e4a09b80 100644 --- a/src/server/api/endpoints/drive/folders/find.ts +++ b/src/server/api/endpoints/drive/folders/find.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Find a folder(s) */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'name' parameter const [name, nameErr] = $.str.get(params.name); if (nameErr) return rej('invalid name param'); diff --git a/src/server/api/endpoints/drive/folders/show.ts b/src/server/api/endpoints/drive/folders/show.ts index c9b4930a7..edc8cb6f1 100644 --- a/src/server/api/endpoints/drive/folders/show.ts +++ b/src/server/api/endpoints/drive/folders/show.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Show a folder */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'folderId' parameter const [folderId, folderIdErr] = $.type(ID).get(params.folderId); if (folderIdErr) return rej('invalid folderId param'); diff --git a/src/server/api/endpoints/drive/folders/update.ts b/src/server/api/endpoints/drive/folders/update.ts index 20675771f..744d8fcb1 100644 --- a/src/server/api/endpoints/drive/folders/update.ts +++ b/src/server/api/endpoints/drive/folders/update.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Update a folder */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'folderId' parameter const [folderId, folderIdErr] = $.type(ID).get(params.folderId); if (folderIdErr) return rej('invalid folderId param'); diff --git a/src/server/api/endpoints/drive/stream.ts b/src/server/api/endpoints/drive/stream.ts index 612d922c6..a7aef926f 100644 --- a/src/server/api/endpoints/drive/stream.ts +++ b/src/server/api/endpoints/drive/stream.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get drive stream */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/following/create.ts b/src/server/api/endpoints/following/create.ts index 3e45b8da5..ffd399d44 100644 --- a/src/server/api/endpoints/following/create.ts +++ b/src/server/api/endpoints/following/create.ts @@ -6,7 +6,7 @@ import create from '../../../../services/following/create'; /** * Follow a user */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const follower = user; // Get 'userId' parameter diff --git a/src/server/api/endpoints/following/delete.ts b/src/server/api/endpoints/following/delete.ts index 0af8813cf..46fe13b2a 100644 --- a/src/server/api/endpoints/following/delete.ts +++ b/src/server/api/endpoints/following/delete.ts @@ -6,7 +6,7 @@ import deleteFollowing from '../../../../services/following/delete'; /** * Unfollow a user */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const follower = user; // Get 'userId' parameter diff --git a/src/server/api/endpoints/following/requests/accept.ts b/src/server/api/endpoints/following/requests/accept.ts index a09e32e4d..722fdac60 100644 --- a/src/server/api/endpoints/following/requests/accept.ts +++ b/src/server/api/endpoints/following/requests/accept.ts @@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../../models/user'; /** * Accept a follow request */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [followerId, followerIdErr] = $.type(ID).get(params.userId); if (followerIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/following/requests/cancel.ts b/src/server/api/endpoints/following/requests/cancel.ts index f2a40854c..88c1b57f4 100644 --- a/src/server/api/endpoints/following/requests/cancel.ts +++ b/src/server/api/endpoints/following/requests/cancel.ts @@ -5,7 +5,7 @@ import User, { pack, ILocalUser } from '../../../../../models/user'; /** * Cancel a follow request */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [followeeId, followeeIdErr] = $.type(ID).get(params.userId); if (followeeIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/following/requests/list.ts b/src/server/api/endpoints/following/requests/list.ts index 287c5a8e4..dfe9858f3 100644 --- a/src/server/api/endpoints/following/requests/list.ts +++ b/src/server/api/endpoints/following/requests/list.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Get all pending received follow requests */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const reqs = await FollowRequest.find({ followeeId: user._id }); diff --git a/src/server/api/endpoints/following/requests/reject.ts b/src/server/api/endpoints/following/requests/reject.ts index 69dddf135..7b7db2909 100644 --- a/src/server/api/endpoints/following/requests/reject.ts +++ b/src/server/api/endpoints/following/requests/reject.ts @@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../../models/user'; /** * Reject a follow request */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [followerId, followerIdErr] = $.type(ID).get(params.userId); if (followerIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/following/stalk.ts b/src/server/api/endpoints/following/stalk.ts index b9d19d57b..19c71cfd5 100644 --- a/src/server/api/endpoints/following/stalk.ts +++ b/src/server/api/endpoints/following/stalk.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Stalk a user */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const follower = user; // Get 'userId' parameter diff --git a/src/server/api/endpoints/following/unstalk.ts b/src/server/api/endpoints/following/unstalk.ts index 255f22ca1..03ee10783 100644 --- a/src/server/api/endpoints/following/unstalk.ts +++ b/src/server/api/endpoints/following/unstalk.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Unstalk a user */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const follower = user; // Get 'userId' parameter diff --git a/src/server/api/endpoints/hashtags/trend.ts b/src/server/api/endpoints/hashtags/trend.ts index 17af9d6a9..01dfccc71 100644 --- a/src/server/api/endpoints/hashtags/trend.ts +++ b/src/server/api/endpoints/hashtags/trend.ts @@ -15,7 +15,7 @@ const max = 5; /** * Get trends of hashtags */ -module.exports = () => new Promise(async (res, rej) => { +export default () => new Promise(async (res, rej) => { //#region 1. 直近Aの内に投稿されたハッシュタグ(とユーザーのペア)を集計 const data = await Note.aggregate([{ $match: { diff --git a/src/server/api/endpoints/i.ts b/src/server/api/endpoints/i.ts index 5c769a02f..150ab34a0 100644 --- a/src/server/api/endpoints/i.ts +++ b/src/server/api/endpoints/i.ts @@ -4,7 +4,7 @@ import { IApp } from '../../../models/app'; /** * Show myself */ -module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { const isSecure = user != null && app == null; // Serialize diff --git a/src/server/api/endpoints/i/2fa/done.ts b/src/server/api/endpoints/i/2fa/done.ts index 61f13c4c6..fef045948 100644 --- a/src/server/api/endpoints/i/2fa/done.ts +++ b/src/server/api/endpoints/i/2fa/done.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import * as speakeasy from 'speakeasy'; import User, { ILocalUser } from '../../../../../models/user'; -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'token' parameter const [token, tokenErr] = $.str.get(params.token); if (tokenErr) return rej('invalid token param'); diff --git a/src/server/api/endpoints/i/2fa/register.ts b/src/server/api/endpoints/i/2fa/register.ts index d05892c84..ac703f5b0 100644 --- a/src/server/api/endpoints/i/2fa/register.ts +++ b/src/server/api/endpoints/i/2fa/register.ts @@ -5,7 +5,7 @@ import * as QRCode from 'qrcode'; import User, { ILocalUser } from '../../../../../models/user'; import config from '../../../../../config'; -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'password' parameter const [password, passwordErr] = $.str.get(params.password); if (passwordErr) return rej('invalid password param'); diff --git a/src/server/api/endpoints/i/2fa/unregister.ts b/src/server/api/endpoints/i/2fa/unregister.ts index fc197cb1e..7d99ee397 100644 --- a/src/server/api/endpoints/i/2fa/unregister.ts +++ b/src/server/api/endpoints/i/2fa/unregister.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import * as bcrypt from 'bcryptjs'; import User, { ILocalUser } from '../../../../../models/user'; -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'password' parameter const [password, passwordErr] = $.str.get(params.password); if (passwordErr) return rej('invalid password param'); diff --git a/src/server/api/endpoints/i/authorized_apps.ts b/src/server/api/endpoints/i/authorized_apps.ts index 9c518b3c8..24c4b58f7 100644 --- a/src/server/api/endpoints/i/authorized_apps.ts +++ b/src/server/api/endpoints/i/authorized_apps.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get authorized apps of my account */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/i/change_password.ts b/src/server/api/endpoints/i/change_password.ts index 9851fa895..698db5a6e 100644 --- a/src/server/api/endpoints/i/change_password.ts +++ b/src/server/api/endpoints/i/change_password.ts @@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../models/user'; /** * Change password */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'currentPasword' parameter const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword); if (currentPasswordErr) return rej('invalid currentPasword param'); diff --git a/src/server/api/endpoints/i/favorites.ts b/src/server/api/endpoints/i/favorites.ts index 1ed42a98b..75b456ca5 100644 --- a/src/server/api/endpoints/i/favorites.ts +++ b/src/server/api/endpoints/i/favorites.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get favorited notes */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/i/notifications.ts b/src/server/api/endpoints/i/notifications.ts index 93c5abf4d..1073b0369 100644 --- a/src/server/api/endpoints/i/notifications.ts +++ b/src/server/api/endpoints/i/notifications.ts @@ -9,7 +9,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get notifications */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'following' parameter const [following = false, followingError] = $.bool.optional.get(params.following); diff --git a/src/server/api/endpoints/i/pin.ts b/src/server/api/endpoints/i/pin.ts index 7f4a45e1f..1edc57173 100644 --- a/src/server/api/endpoints/i/pin.ts +++ b/src/server/api/endpoints/i/pin.ts @@ -6,7 +6,7 @@ import { pack } from '../../../../models/user'; /** * Pin note */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/i/regenerate_token.ts b/src/server/api/endpoints/i/regenerate_token.ts index 3ffab5428..1f68e3abd 100644 --- a/src/server/api/endpoints/i/regenerate_token.ts +++ b/src/server/api/endpoints/i/regenerate_token.ts @@ -7,7 +7,7 @@ import generateUserToken from '../../common/generate-native-user-token'; /** * Regenerate native token */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'password' parameter const [password, passwordErr] = $.str.get(params.password); if (passwordErr) return rej('invalid password param'); diff --git a/src/server/api/endpoints/i/signin_history.ts b/src/server/api/endpoints/i/signin_history.ts index e58f48f72..1315a2cfb 100644 --- a/src/server/api/endpoints/i/signin_history.ts +++ b/src/server/api/endpoints/i/signin_history.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get signin history of my account */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/i/update.ts b/src/server/api/endpoints/i/update.ts index fc23d9fc8..08d17fa85 100644 --- a/src/server/api/endpoints/i/update.ts +++ b/src/server/api/endpoints/i/update.ts @@ -8,7 +8,7 @@ import { IApp } from '../../../../models/app'; /** * Update myself */ -module.exports = async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { const isSecure = user != null && app == null; const updates = {} as any; diff --git a/src/server/api/endpoints/i/update_client_setting.ts b/src/server/api/endpoints/i/update_client_setting.ts index 9eca66cfc..edcd3e742 100644 --- a/src/server/api/endpoints/i/update_client_setting.ts +++ b/src/server/api/endpoints/i/update_client_setting.ts @@ -5,7 +5,7 @@ import event from '../../../../publishers/stream'; /** * Update myself */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'name' parameter const [name, nameErr] = $.str.get(params.name); if (nameErr) return rej('invalid name param'); diff --git a/src/server/api/endpoints/i/update_home.ts b/src/server/api/endpoints/i/update_home.ts index 511a647d8..03795ae8d 100644 --- a/src/server/api/endpoints/i/update_home.ts +++ b/src/server/api/endpoints/i/update_home.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import User, { ILocalUser } from '../../../../models/user'; import event from '../../../../publishers/stream'; -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'home' parameter const [home, homeErr] = $.arr( $.obj.strict() diff --git a/src/server/api/endpoints/i/update_mobile_home.ts b/src/server/api/endpoints/i/update_mobile_home.ts index b1f25624f..a2e2a1346 100644 --- a/src/server/api/endpoints/i/update_mobile_home.ts +++ b/src/server/api/endpoints/i/update_mobile_home.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import User, { ILocalUser } from '../../../../models/user'; import event from '../../../../publishers/stream'; -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'home' parameter const [home, homeErr] = $.arr( $.obj.strict() diff --git a/src/server/api/endpoints/i/update_widget.ts b/src/server/api/endpoints/i/update_widget.ts index 82bb04d1f..006916c9f 100644 --- a/src/server/api/endpoints/i/update_widget.ts +++ b/src/server/api/endpoints/i/update_widget.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import User, { ILocalUser } from '../../../../models/user'; import event from '../../../../publishers/stream'; -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'id' parameter const [id, idErr] = $.str.get(params.id); if (idErr) return rej('invalid id param'); diff --git a/src/server/api/endpoints/messaging/history.ts b/src/server/api/endpoints/messaging/history.ts index d76aa7823..a1bd01586 100644 --- a/src/server/api/endpoints/messaging/history.ts +++ b/src/server/api/endpoints/messaging/history.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Show messaging history */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/messaging/messages.ts b/src/server/api/endpoints/messaging/messages.ts index 16236136d..6ac1cc980 100644 --- a/src/server/api/endpoints/messaging/messages.ts +++ b/src/server/api/endpoints/messaging/messages.ts @@ -7,7 +7,7 @@ import read from '../../common/read-messaging-message'; /** * Get messages */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [recipientId, recipientIdErr] = $.type(ID).get(params.userId); if (recipientIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/messaging/messages/create.ts b/src/server/api/endpoints/messaging/messages/create.ts index d4f16d0dc..bcbbd9a1f 100644 --- a/src/server/api/endpoints/messaging/messages/create.ts +++ b/src/server/api/endpoints/messaging/messages/create.ts @@ -14,7 +14,7 @@ import config from '../../../../../config'; /** * Create a message */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [recipientId, recipientIdErr] = $.type(ID).get(params.userId); if (recipientIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index ce460d0b8..836123a3a 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -38,7 +38,7 @@ const client = require('../../../../built/client/meta.json'); /** * Show core info */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { const meta: any = (await Meta.findOne()) || {}; res({ diff --git a/src/server/api/endpoints/mute/create.ts b/src/server/api/endpoints/mute/create.ts index 415745e2c..0f8d8fb09 100644 --- a/src/server/api/endpoints/mute/create.ts +++ b/src/server/api/endpoints/mute/create.ts @@ -5,7 +5,7 @@ import Mute from '../../../../models/mute'; /** * Mute a user */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const muter = user; // Get 'userId' parameter diff --git a/src/server/api/endpoints/mute/delete.ts b/src/server/api/endpoints/mute/delete.ts index 2d1d28658..bc3160c15 100644 --- a/src/server/api/endpoints/mute/delete.ts +++ b/src/server/api/endpoints/mute/delete.ts @@ -5,7 +5,7 @@ import Mute from '../../../../models/mute'; /** * Unmute a user */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { const muter = user; // Get 'userId' parameter diff --git a/src/server/api/endpoints/mute/list.ts b/src/server/api/endpoints/mute/list.ts index b632b1a1a..89287c50a 100644 --- a/src/server/api/endpoints/mute/list.ts +++ b/src/server/api/endpoints/mute/list.ts @@ -6,7 +6,7 @@ import { getFriendIds } from '../../common/get-friends'; /** * Get muted users of a user */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'iknow' parameter const [iknow = false, iknowErr] = $.bool.optional.get(params.iknow); if (iknowErr) return rej('invalid iknow param'); diff --git a/src/server/api/endpoints/my/apps.ts b/src/server/api/endpoints/my/apps.ts index 8f67af885..8e946c946 100644 --- a/src/server/api/endpoints/my/apps.ts +++ b/src/server/api/endpoints/my/apps.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get my apps */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/notes.ts b/src/server/api/endpoints/notes.ts index 8b0c4177f..dd8d09dcc 100644 --- a/src/server/api/endpoints/notes.ts +++ b/src/server/api/endpoints/notes.ts @@ -7,7 +7,7 @@ import Note, { pack } from '../../../models/note'; /** * Get all notes */ -module.exports = (params: any) => new Promise(async (res, rej) => { +export default (params: any) => new Promise(async (res, rej) => { // Get 'local' parameter const [local, localErr] = $.bool.optional.get(params.local); if (localErr) return rej('invalid local param'); diff --git a/src/server/api/endpoints/notes/conversation.ts b/src/server/api/endpoints/notes/conversation.ts index a8e8c4eeb..e47b97727 100644 --- a/src/server/api/endpoints/notes/conversation.ts +++ b/src/server/api/endpoints/notes/conversation.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Show conversation of a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/create.ts b/src/server/api/endpoints/notes/create.ts index 62eafa534..45fc77503 100644 --- a/src/server/api/endpoints/notes/create.ts +++ b/src/server/api/endpoints/notes/create.ts @@ -7,6 +7,8 @@ import { IApp } from '../../../../models/app'; import getParams from '../../get-params'; export const meta = { + name: 'notes/create', + desc: { ja: '投稿します。' }, @@ -57,7 +59,8 @@ export const meta = { }).optional.nullable.strict().note({ desc: { ja: '位置情報' - } + }, + ref: 'geo' }), mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({ @@ -80,7 +83,8 @@ export const meta = { }).optional.strict().note({ desc: { ja: 'アンケート' - } + }, + ref: 'poll' }) }, @@ -100,7 +104,7 @@ export const meta = { /** * Create a note */ -module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { const [ps, psErr] = getParams(meta, params); if (psErr) return rej(psErr); diff --git a/src/server/api/endpoints/notes/delete.ts b/src/server/api/endpoints/notes/delete.ts index 70bcdbaab..49907e444 100644 --- a/src/server/api/endpoints/notes/delete.ts +++ b/src/server/api/endpoints/notes/delete.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Delete a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/favorites/create.ts b/src/server/api/endpoints/notes/favorites/create.ts index 23f7ac5f8..9ec75dbba 100644 --- a/src/server/api/endpoints/notes/favorites/create.ts +++ b/src/server/api/endpoints/notes/favorites/create.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Favorite a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/favorites/delete.ts b/src/server/api/endpoints/notes/favorites/delete.ts index 7d2d2b4cb..f9916905b 100644 --- a/src/server/api/endpoints/notes/favorites/delete.ts +++ b/src/server/api/endpoints/notes/favorites/delete.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Unfavorite a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts index d032aa1a6..6de83ddad 100644 --- a/src/server/api/endpoints/notes/global-timeline.ts +++ b/src/server/api/endpoints/notes/global-timeline.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get timeline of global */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; diff --git a/src/server/api/endpoints/notes/local-timeline.ts b/src/server/api/endpoints/notes/local-timeline.ts index 74462ce4e..3e96877c7 100644 --- a/src/server/api/endpoints/notes/local-timeline.ts +++ b/src/server/api/endpoints/notes/local-timeline.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get timeline of local */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts index 06ddc258b..82e3371ff 100644 --- a/src/server/api/endpoints/notes/mentions.ts +++ b/src/server/api/endpoints/notes/mentions.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get mentions of myself */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'following' parameter const [following = false, followingError] = $.bool.optional.get(params.following); diff --git a/src/server/api/endpoints/notes/polls/recommendation.ts b/src/server/api/endpoints/notes/polls/recommendation.ts index fb1ee6dda..f448bb66f 100644 --- a/src/server/api/endpoints/notes/polls/recommendation.ts +++ b/src/server/api/endpoints/notes/polls/recommendation.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Get recommended polls */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts index 72ac6bb20..b86d319b3 100644 --- a/src/server/api/endpoints/notes/polls/vote.ts +++ b/src/server/api/endpoints/notes/polls/vote.ts @@ -10,7 +10,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Vote poll of a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/reactions.ts b/src/server/api/endpoints/notes/reactions.ts index cf88f3860..5e15ed3ec 100644 --- a/src/server/api/endpoints/notes/reactions.ts +++ b/src/server/api/endpoints/notes/reactions.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Show reactions of a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts index 33e457e30..709b47ab5 100644 --- a/src/server/api/endpoints/notes/reactions/create.ts +++ b/src/server/api/endpoints/notes/reactions/create.ts @@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * React to a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/reactions/delete.ts b/src/server/api/endpoints/notes/reactions/delete.ts index 1f2d66251..81671751a 100644 --- a/src/server/api/endpoints/notes/reactions/delete.ts +++ b/src/server/api/endpoints/notes/reactions/delete.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Unreact to a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/replies.ts b/src/server/api/endpoints/notes/replies.ts index 3b209b317..baefde315 100644 --- a/src/server/api/endpoints/notes/replies.ts +++ b/src/server/api/endpoints/notes/replies.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get replies of a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/reposts.ts b/src/server/api/endpoints/notes/reposts.ts index 043a653e8..118e684a8 100644 --- a/src/server/api/endpoints/notes/reposts.ts +++ b/src/server/api/endpoints/notes/reposts.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Show a renotes of a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/search.ts b/src/server/api/endpoints/notes/search.ts index 3dbf407df..badaa7afc 100644 --- a/src/server/api/endpoints/notes/search.ts +++ b/src/server/api/endpoints/notes/search.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; import { pack } from '../../../../models/note'; import es from '../../../../db/elasticsearch'; -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'query' parameter const [query, queryError] = $.str.get(params.query); if (queryError) return rej('invalid query param'); diff --git a/src/server/api/endpoints/notes/search_by_tag.ts b/src/server/api/endpoints/notes/search_by_tag.ts index 78487e2c0..a6fcae593 100644 --- a/src/server/api/endpoints/notes/search_by_tag.ts +++ b/src/server/api/endpoints/notes/search_by_tag.ts @@ -8,7 +8,7 @@ import { pack } from '../../../../models/note'; /** * Search notes by tag */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'tag' parameter const [tag, tagError] = $.str.get(params.tag); if (tagError) return rej('invalid tag param'); diff --git a/src/server/api/endpoints/notes/show.ts b/src/server/api/endpoints/notes/show.ts index 1ba714599..0a2749496 100644 --- a/src/server/api/endpoints/notes/show.ts +++ b/src/server/api/endpoints/notes/show.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Show a note */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'noteId' parameter const [noteId, noteIdErr] = $.type(ID).get(params.noteId); if (noteIdErr) return rej('invalid noteId param'); diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts index 9a5306be6..9144c6625 100644 --- a/src/server/api/endpoints/notes/timeline.ts +++ b/src/server/api/endpoints/notes/timeline.ts @@ -8,7 +8,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get timeline of myself */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; diff --git a/src/server/api/endpoints/notes/trend.ts b/src/server/api/endpoints/notes/trend.ts index b4acd7c5f..ae66234c0 100644 --- a/src/server/api/endpoints/notes/trend.ts +++ b/src/server/api/endpoints/notes/trend.ts @@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get trend notes */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/notes/user-list-timeline.ts b/src/server/api/endpoints/notes/user-list-timeline.ts index f14a869c7..8a5985739 100644 --- a/src/server/api/endpoints/notes/user-list-timeline.ts +++ b/src/server/api/endpoints/notes/user-list-timeline.ts @@ -8,7 +8,7 @@ import { ILocalUser } from '../../../../models/user'; /** * Get timeline of a user list */ -module.exports = async (params: any, user: ILocalUser) => { +export default async (params: any, user: ILocalUser) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) throw 'invalid limit param'; diff --git a/src/server/api/endpoints/notifications/mark_as_read_all.ts b/src/server/api/endpoints/notifications/mark_as_read_all.ts index faaaf65a2..6e2b13fa8 100644 --- a/src/server/api/endpoints/notifications/mark_as_read_all.ts +++ b/src/server/api/endpoints/notifications/mark_as_read_all.ts @@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../models/user'; /** * Mark as read all notifications */ -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Update documents await Notification.update({ notifieeId: user._id, diff --git a/src/server/api/endpoints/reversi/games.ts b/src/server/api/endpoints/reversi/games.ts index e68f57c6d..11da7b3c0 100644 --- a/src/server/api/endpoints/reversi/games.ts +++ b/src/server/api/endpoints/reversi/games.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id'; import ReversiGame, { pack } from '../../../../models/reversi-game'; import { ILocalUser } from '../../../../models/user'; -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'my' parameter const [my = false, myErr] = $.bool.optional.get(params.my); if (myErr) return rej('invalid my param'); diff --git a/src/server/api/endpoints/reversi/games/show.ts b/src/server/api/endpoints/reversi/games/show.ts index d70ee547a..ba5206604 100644 --- a/src/server/api/endpoints/reversi/games/show.ts +++ b/src/server/api/endpoints/reversi/games/show.ts @@ -3,7 +3,7 @@ import ReversiGame, { pack } from '../../../../../models/reversi-game'; import Reversi from '../../../../../reversi/core'; import { ILocalUser } from '../../../../../models/user'; -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'gameId' parameter const [gameId, gameIdErr] = $.type(ID).get(params.gameId); if (gameIdErr) return rej('invalid gameId param'); diff --git a/src/server/api/endpoints/reversi/invitations.ts b/src/server/api/endpoints/reversi/invitations.ts index d7727071a..179abe8cd 100644 --- a/src/server/api/endpoints/reversi/invitations.ts +++ b/src/server/api/endpoints/reversi/invitations.ts @@ -1,7 +1,7 @@ import Matching, { pack as packMatching } from '../../../../models/reversi-matching'; import { ILocalUser } from '../../../../models/user'; -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Find session const invitations = await Matching.find({ childId: user._id diff --git a/src/server/api/endpoints/reversi/match.ts b/src/server/api/endpoints/reversi/match.ts index 907df7cf4..20473d9a4 100644 --- a/src/server/api/endpoints/reversi/match.ts +++ b/src/server/api/endpoints/reversi/match.ts @@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../models/user'; import publishUserStream, { publishReversiStream } from '../../../../publishers/stream'; import { eighteight } from '../../../../reversi/maps'; -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [childId, childIdErr] = $.type(ID).get(params.userId); if (childIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/reversi/match/cancel.ts b/src/server/api/endpoints/reversi/match/cancel.ts index 1c9c799db..470d848b5 100644 --- a/src/server/api/endpoints/reversi/match/cancel.ts +++ b/src/server/api/endpoints/reversi/match/cancel.ts @@ -1,7 +1,7 @@ import Matching from '../../../../../models/reversi-matching'; import { ILocalUser } from '../../../../../models/user'; -module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { await Matching.remove({ parentId: user._id }); diff --git a/src/server/api/endpoints/stats.ts b/src/server/api/endpoints/stats.ts index 74ab6ba94..ca11f6701 100644 --- a/src/server/api/endpoints/stats.ts +++ b/src/server/api/endpoints/stats.ts @@ -3,7 +3,7 @@ import Meta from '../../../models/meta'; /** * Get the misskey's statistics */ -module.exports = () => new Promise(async (res, rej) => { +export default () => new Promise(async (res, rej) => { const meta = await Meta.findOne(); res(meta.stats); diff --git a/src/server/api/endpoints/sw/register.ts b/src/server/api/endpoints/sw/register.ts index f04a77fa4..c7bf1bfbe 100644 --- a/src/server/api/endpoints/sw/register.ts +++ b/src/server/api/endpoints/sw/register.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user'; /** * subscribe service worker */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'endpoint' parameter const [endpoint, endpointErr] = $.str.get(params.endpoint); if (endpointErr) return rej('invalid endpoint param'); diff --git a/src/server/api/endpoints/username/available.ts b/src/server/api/endpoints/username/available.ts index aad3adc51..ff12b797e 100644 --- a/src/server/api/endpoints/username/available.ts +++ b/src/server/api/endpoints/username/available.ts @@ -5,7 +5,7 @@ import { validateUsername } from '../../../../models/user'; /** * Check available username */ -module.exports = async (params: any) => new Promise(async (res, rej) => { +export default async (params: any) => new Promise(async (res, rej) => { // Get 'username' parameter const [username, usernameError] = $.str.pipe(validateUsername).get(params.username); if (usernameError) return rej('invalid username param'); diff --git a/src/server/api/endpoints/users.ts b/src/server/api/endpoints/users.ts index 0756ddc91..d7e85d3cb 100644 --- a/src/server/api/endpoints/users.ts +++ b/src/server/api/endpoints/users.ts @@ -4,7 +4,7 @@ import User, { pack, ILocalUser } from '../../../models/user'; /** * Lists all users */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/users/followers.ts b/src/server/api/endpoints/users/followers.ts index ef36a0df4..f72697677 100644 --- a/src/server/api/endpoints/users/followers.ts +++ b/src/server/api/endpoints/users/followers.ts @@ -7,7 +7,7 @@ import { getFriendIds } from '../../common/get-friends'; /** * Get followers of a user */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/users/following.ts b/src/server/api/endpoints/users/following.ts index 2c38fe4f8..1b2eb9c87 100644 --- a/src/server/api/endpoints/users/following.ts +++ b/src/server/api/endpoints/users/following.ts @@ -7,7 +7,7 @@ import { getFriendIds } from '../../common/get-friends'; /** * Get following users of a user */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); 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 607742090..98d662d29 100644 --- a/src/server/api/endpoints/users/get_frequently_replied_users.ts +++ b/src/server/api/endpoints/users/get_frequently_replied_users.ts @@ -2,7 +2,7 @@ import $ from 'cafy'; import ID from '../../../../cafy-id'; import Note from '../../../../models/note'; import User, { pack, ILocalUser } from '../../../../models/user'; -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/users/lists/create.ts b/src/server/api/endpoints/users/lists/create.ts index cdd1a0d81..f3776afee 100644 --- a/src/server/api/endpoints/users/lists/create.ts +++ b/src/server/api/endpoints/users/lists/create.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Create a user list */ -module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { // Get 'title' parameter const [title, titleErr] = $.str.range(1, 100).get(params.title); if (titleErr) return rej('invalid title param'); diff --git a/src/server/api/endpoints/users/lists/list.ts b/src/server/api/endpoints/users/lists/list.ts index bf8391d86..88fa75a11 100644 --- a/src/server/api/endpoints/users/lists/list.ts +++ b/src/server/api/endpoints/users/lists/list.ts @@ -4,7 +4,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Add a user to a user list */ -module.exports = async (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Fetch lists const userLists = await UserList.find({ userId: me._id, diff --git a/src/server/api/endpoints/users/lists/push.ts b/src/server/api/endpoints/users/lists/push.ts index d8a3b3c9a..0e7caea06 100644 --- a/src/server/api/endpoints/users/lists/push.ts +++ b/src/server/api/endpoints/users/lists/push.ts @@ -9,7 +9,7 @@ import { deliver } from '../../../../../queue'; /** * Add a user to a user list */ -module.exports = async (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'listId' parameter const [listId, listIdErr] = $.type(ID).get(params.listId); if (listIdErr) return rej('invalid listId param'); diff --git a/src/server/api/endpoints/users/lists/show.ts b/src/server/api/endpoints/users/lists/show.ts index e4ae23961..4716dd821 100644 --- a/src/server/api/endpoints/users/lists/show.ts +++ b/src/server/api/endpoints/users/lists/show.ts @@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user'; /** * Show a user list */ -module.exports = async (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default async (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'listId' parameter const [listId, listIdErr] = $.type(ID).get(params.listId); if (listIdErr) return rej('invalid listId param'); diff --git a/src/server/api/endpoints/users/notes.ts b/src/server/api/endpoints/users/notes.ts index ac4e17946..6d8d85ff5 100644 --- a/src/server/api/endpoints/users/notes.ts +++ b/src/server/api/endpoints/users/notes.ts @@ -6,7 +6,7 @@ import User, { ILocalUser } from '../../../../models/user'; /** * Get notes of a user */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'userId' parameter const [userId, userIdErr] = $.type(ID).optional.get(params.userId); if (userIdErr) return rej('invalid userId param'); diff --git a/src/server/api/endpoints/users/recommendation.ts b/src/server/api/endpoints/users/recommendation.ts index 6221d751b..b7402b7fb 100644 --- a/src/server/api/endpoints/users/recommendation.ts +++ b/src/server/api/endpoints/users/recommendation.ts @@ -7,7 +7,7 @@ import Mute from '../../../../models/mute'; /** * Get recommended users */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'limit' parameter const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); if (limitErr) return rej('invalid limit param'); diff --git a/src/server/api/endpoints/users/search.ts b/src/server/api/endpoints/users/search.ts index 36a708d21..d443d35b4 100644 --- a/src/server/api/endpoints/users/search.ts +++ b/src/server/api/endpoints/users/search.ts @@ -5,7 +5,7 @@ const escapeRegexp = require('escape-regexp'); /** * Search a user */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'query' parameter const [query, queryError] = $.str.pipe(x => x != '').get(params.query); if (queryError) return rej('invalid query param'); diff --git a/src/server/api/endpoints/users/search_by_username.ts b/src/server/api/endpoints/users/search_by_username.ts index 1c0f09449..56030a000 100644 --- a/src/server/api/endpoints/users/search_by_username.ts +++ b/src/server/api/endpoints/users/search_by_username.ts @@ -4,7 +4,7 @@ import User, { pack, ILocalUser } from '../../../../models/user'; /** * Search a user by username */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { // Get 'query' parameter const [query, queryError] = $.str.get(params.query); if (queryError) return rej('invalid query param'); diff --git a/src/server/api/endpoints/users/show.ts b/src/server/api/endpoints/users/show.ts index 5cbd83f64..276e7c325 100644 --- a/src/server/api/endpoints/users/show.ts +++ b/src/server/api/endpoints/users/show.ts @@ -7,7 +7,7 @@ const cursorOption = { fields: { data: false } }; /** * Show user(s) */ -module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => { +export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { let user; // Get 'userId' parameter diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index e65cc87b1..849194388 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -5,9 +5,53 @@ import ms = require('ms'); import * as Router from 'koa-router'; import * as send from 'koa-send'; +import { Context } from 'cafy'; +import ObjectContext from 'cafy/built/types/object'; +import config from '../../config'; +import generateVars from '../../client/docs/vars'; const docs = `${__dirname}/../../client/docs/`; +// WIP type +const parseEPDefParam = (key: string, param: Context) => { + return Object.assign({ + name: key, + type: param.getType() + }, param.data); +}; + +const sortParams = (params: Array<{name: string}>) => { + params.sort((a, b) => { + if (a.name < b.name) + return -1; + if (a.name > b.name) + return 1; + return 0; + }); + return params; +}; + +// WIP type +const extractDefs = (params: Context[]) => { + let defs: any[] = []; + + params.forEach(param => { + if (param.data && param.data.ref) { + const props = (param as ObjectContext).props; + defs.push({ + name: param.data.ref, + params: sortParams(Object.keys(props).map(k => parseEPDefParam(k, props[k]))) + }); + + const childDefs = extractDefs(Object.keys(props).map(k => props[k])); + + defs = defs.concat(childDefs); + } + }); + + return sortParams(defs); +}; + const router = new Router(); router.get('/assets/*', async ctx => { @@ -18,6 +62,32 @@ router.get('/assets/*', async ctx => { }); }); +router.get('/*/api/endpoints/*', async ctx => { + const ep = require('../../../built/server/api/endpoints/' + ctx.params[1]).meta; + + const vars = { + endpoint: ep.name, + url: { + host: config.api_url, + path: ep.name + }, + desc: ep.desc, + // @ts-ignore + params: sortParams(Object.keys(ep.params).map(k => parseEPDefParam(k, ep.params[k]))), + paramDefs: extractDefs(Object.keys(ep.params).map(k => ep.params[k])), + }; + console.log(vars); + + const commonVars = await generateVars(); + + await ctx.render('../../../../src/client/docs/api/endpoints/view', Object.assign({}, vars, { + lang: 'ja', + title: ep.name, + kebab: (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(), + common: commonVars + })); +}); + router.get('*', async ctx => { await send(ctx, `${ctx.params[0]}.html`, { root: docs From 029b92935c6119a01759c0e687eb0d9cef2dcf68 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 12:17:38 +0900 Subject: [PATCH 06/13] wip --- gulpfile.ts | 2 +- locales/index.js | 27 ++++ locales/index.ts | 34 ----- src/build/i18n.ts | 10 +- src/client/docs/api/endpoints/view.pug | 4 +- src/client/docs/api/gulpfile.ts | 201 ------------------------- src/client/docs/api/mixins.pug | 14 +- src/client/docs/gulpfile.ts | 59 -------- src/server/web/docs.ts | 8 +- webpack.config.ts | 2 +- 10 files changed, 49 insertions(+), 312 deletions(-) create mode 100644 locales/index.js delete mode 100644 locales/index.ts delete mode 100644 src/client/docs/api/gulpfile.ts diff --git a/gulpfile.ts b/gulpfile.ts index 49a80879d..607f77fc3 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -20,7 +20,7 @@ import * as replace from 'gulp-replace'; import * as htmlmin from 'gulp-htmlmin'; const uglifyes = require('uglify-es'); -import locales from './locales'; +const locales = require('./locales'); import { fa } from './src/build/fa'; const client = require('./built/client/meta.json'); import config from './src/config'; diff --git a/locales/index.js b/locales/index.js new file mode 100644 index 000000000..95cc33916 --- /dev/null +++ b/locales/index.js @@ -0,0 +1,27 @@ +/** + * Languages Loader + */ + +const fs = require('fs'); +const yaml = require('js-yaml'); + +const loadLang = lang => yaml.safeLoad( + fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')); + +const native = loadLang('ja'); + +const langs = { + 'de': loadLang('de'), + 'en': loadLang('en'), + 'fr': loadLang('fr'), + 'ja': native, + 'pl': loadLang('pl'), + 'es': loadLang('es') +}; + +Object.entries(langs).map(([, locale]) => { + // Extend native language (Japanese) + locale = Object.assign({}, native, locale); +}); + +module.exports = langs; diff --git a/locales/index.ts b/locales/index.ts deleted file mode 100644 index 45b5df095..000000000 --- a/locales/index.ts +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Languages Loader - */ - -import * as fs from 'fs'; -import * as yaml from 'js-yaml'; - -export type LangKey = 'de' | 'en' | 'fr' | 'ja' | 'pl' | 'es'; -export type LocaleObject = { [key: string]: any }; - -const loadLang = (lang: LangKey) => yaml.safeLoad( - fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')) as LocaleObject; - -const native = loadLang('ja'); - -const langs: { [key: string]: LocaleObject } = { - 'de': loadLang('de'), - 'en': loadLang('en'), - 'fr': loadLang('fr'), - 'ja': native, - 'pl': loadLang('pl'), - 'es': loadLang('es') -}; - -Object.entries(langs).map(([, locale]) => { - // Extend native language (Japanese) - locale = Object.assign({}, native, locale); -}); - -export function isAvailableLanguage(lang: string): lang is LangKey { - return lang in langs; -} - -export default langs; diff --git a/src/build/i18n.ts b/src/build/i18n.ts index dc48251c9..4ed3c7a2d 100644 --- a/src/build/i18n.ts +++ b/src/build/i18n.ts @@ -2,7 +2,7 @@ * Replace i18n texts */ -import locale, { isAvailableLanguage, LocaleObject } from '../../locales'; +const locale = require('../../locales'); export default class Replacer { private lang: string; @@ -16,8 +16,8 @@ export default class Replacer { this.replacement = this.replacement.bind(this); } - private get(path: string, key: string): string { - if (!isAvailableLanguage(this.lang)) { + public get(path: string, key: string): string { + if (!(this.lang in locale)) { console.warn(`lang '${this.lang}' is not supported`); return key; // Fallback } @@ -28,7 +28,7 @@ export default class Replacer { if (path) { if (text.hasOwnProperty(path)) { - text = text[path] as LocaleObject; + text = text[path]; } else { console.warn(`path '${path}' not found in '${this.lang}'`); return key; // Fallback @@ -38,7 +38,7 @@ export default class Replacer { // Check the key existance const error = key.split('.').some(k => { if (text.hasOwnProperty(k)) { - text = (text as LocaleObject)[k]; + text = text[k]; return false; } else { return true; diff --git a/src/client/docs/api/endpoints/view.pug b/src/client/docs/api/endpoints/view.pug index f8795c844..24fff1b79 100644 --- a/src/client/docs/api/endpoints/view.pug +++ b/src/client/docs/api/endpoints/view.pug @@ -17,7 +17,7 @@ block main p#desc= desc[lang] || desc['ja'] section - h2 %i18n:docs.api.endpoints.params% + h2= i18n('docs.api.endpoints.params') +propTable(params) if paramDefs @@ -28,5 +28,5 @@ block main if res section - h2 %i18n:docs.api.endpoints.res% + h2= i18n('docs.api.endpoints.res') +propTable(res) diff --git a/src/client/docs/api/gulpfile.ts b/src/client/docs/api/gulpfile.ts deleted file mode 100644 index 4b38058b5..000000000 --- a/src/client/docs/api/gulpfile.ts +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Gulp tasks - */ - -import * as fs from 'fs'; -import * as path from 'path'; -import * as glob from 'glob'; -import * as gulp from 'gulp'; -import * as pug from 'pug'; -import * as yaml from 'js-yaml'; -import * as mkdirp from 'mkdirp'; - -import locales from '../../../../locales'; -import I18nReplacer from '../../../build/i18n'; -import fa from '../../../build/fa'; -import config from './../../../config'; - -import generateVars from '../vars'; -import { Context } from 'cafy'; -import ObjectContext from 'cafy/built/types/object'; - -const langs = Object.keys(locales); - -const kebab = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); - -const parseParam = (param: any) => { - const id = param.type.match(/^id\((.+?)\)|^id/); - const entity = param.type.match(/^entity\((.+?)\)/); - const isObject = /^object/.test(param.type); - const isDate = /^date/.test(param.type); - const isArray = /\[\]$/.test(param.type); - if (id) { - param.kind = 'id'; - param.type = 'string'; - param.entity = id[1]; - if (isArray) { - param.type += '[]'; - } - } - if (entity) { - param.kind = 'entity'; - param.type = 'object'; - param.entity = entity[1]; - if (isArray) { - param.type += '[]'; - } - } - if (isObject) { - param.kind = 'object'; - } - if (isDate) { - param.kind = 'date'; - param.type = 'string'; - if (isArray) { - param.type += '[]'; - } - } - - return param; -}; - -// WIP type -const parseEPDefParam = (key: string, param: Context) => { - return Object.assign({ - name: key, - type: param.getType() - }, param.data); -}; - -const sortParams = (params: Array<{name: string}>) => { - params.sort((a, b) => { - if (a.name < b.name) - return -1; - if (a.name > b.name) - return 1; - return 0; - }); - return params; -}; - -// WIP type -const extractDefs = (params: Context[]) => { - let defs: any[] = []; - - params.forEach(param => { - if (param.data && param.data.ref) { - const props = (param as ObjectContext).props; - defs.push({ - name: param.data.ref, - params: sortParams(Object.keys(props).map(k => parseEPDefParam(k, props[k]))) - }); - - const childDefs = extractDefs(Object.keys(props).map(k => props[k])); - - defs = defs.concat(childDefs); - } - }); - - return sortParams(defs); -}; - -gulp.task('doc:api', [ - 'doc:api:endpoints', - 'doc:api:entities' -]); - -gulp.task('doc:api:endpoints', ['build:ts'], async () => { - const commonVars = await generateVars(); - glob('./built/server/api/endpoints/**/*.js', (globErr, files) => { - if (globErr) { - console.error(globErr); - return; - } - console.log(files.map(file => require('../../../../' + file))); - - files.map(file => require('../../../../' + file)).filter(x => x.meta).map(x => x.meta).forEach(ep => { - console.log(ep); - const vars = { - endpoint: ep.name, - url: { - host: config.api_url, - path: ep.name - }, - desc: ep.desc, - // @ts-ignore - params: sortParams(ep.params.map(p => parseEPDefParam(p))), - paramDefs: extractDefs(ep.params), - }; - langs.forEach(lang => { - pug.renderFile('./src/client/docs/api/endpoints/view.pug', Object.assign({}, vars, { - lang, - title: ep.name, - src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/api/endpoints/${ep.name}.yaml`, - kebab, - common: commonVars - }), (renderErr, html) => { - if (renderErr) { - console.error(renderErr); - return; - } - const i18n = new I18nReplacer(lang); - html = html.replace(i18n.pattern, i18n.replacement); - html = fa(html); - const htmlPath = `./built/client/docs/${lang}/api/endpoints/${ep.name}.html`; - mkdirp(path.dirname(htmlPath), (mkdirErr) => { - if (mkdirErr) { - console.error(mkdirErr); - return; - } - fs.writeFileSync(htmlPath, html, 'utf-8'); - }); - }); - }); - }); - }); -}); - -gulp.task('doc:api:entities', async () => { - const commonVars = await generateVars(); - glob('./src/client/docs/api/entities/**/*.yaml', (globErr, files) => { - if (globErr) { - console.error(globErr); - return; - } - files.forEach(file => { - const entity = yaml.safeLoad(fs.readFileSync(file, 'utf-8')) as any; - const vars = { - name: entity.name, - desc: entity.desc, - // WIP type - props: sortParams(entity.props.map((p: any) => parseParam(p))), - propDefs: extractDefs(entity.props), - }; - langs.forEach(lang => { - pug.renderFile('./src/client/docs/api/entities/view.pug', Object.assign({}, vars, { - lang, - title: entity.name, - src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/api/entities/${kebab(entity.name)}.yaml`, - kebab, - common: commonVars - }), (renderErr, html) => { - if (renderErr) { - console.error(renderErr); - return; - } - const i18n = new I18nReplacer(lang); - html = html.replace(i18n.pattern, i18n.replacement); - html = fa(html); - const htmlPath = `./built/client/docs/${lang}/api/entities/${kebab(entity.name)}.html`; - mkdirp(path.dirname(htmlPath), (mkdirErr) => { - if (mkdirErr) { - console.error(mkdirErr); - return; - } - fs.writeFileSync(htmlPath, html, 'utf-8'); - }); - }); - }); - }); - }); -}); diff --git a/src/client/docs/api/mixins.pug b/src/client/docs/api/mixins.pug index 913135a85..6762158f8 100644 --- a/src/client/docs/api/mixins.pug +++ b/src/client/docs/api/mixins.pug @@ -1,10 +1,10 @@ mixin propTable(props) table.props thead: tr - th %i18n:docs.api.props.name% - th %i18n:docs.api.props.type% - th %i18n:docs.api.props.optional% - th %i18n:docs.api.props.description% + th= i18n('docs.api.props.name') + th= i18n('docs.api.props.type') + th= i18n('docs.api.props.optional') + th= i18n('docs.api.props.description') tbody each prop in props tr @@ -31,7 +31,7 @@ mixin propTable(props) | (Date) td.optional if prop.optional - | %i18n:docs.api.props.yes% + = i18n('docs.api.props.yes') else - | %i18n:docs.api.props.no% - td.desc!= prop.desc[lang] || prop.desc['ja'] + = i18n('docs.api.props.no') + td.desc!= prop.desc ? prop.desc[lang] || prop.desc['ja'] : null diff --git a/src/client/docs/gulpfile.ts b/src/client/docs/gulpfile.ts index 5ef87315f..2a95dfbfe 100644 --- a/src/client/docs/gulpfile.ts +++ b/src/client/docs/gulpfile.ts @@ -2,73 +2,14 @@ * Gulp tasks */ -import * as fs from 'fs'; -import * as path from 'path'; -import * as glob from 'glob'; import * as gulp from 'gulp'; -import * as pug from 'pug'; -import * as mkdirp from 'mkdirp'; const stylus = require('gulp-stylus'); const cssnano = require('gulp-cssnano'); -import I18nReplacer from '../../build/i18n'; -import fa from '../../build/fa'; -import generateVars from './vars'; - -//require('./api/gulpfile.ts'); - gulp.task('doc', [ - 'doc:docs', - //'doc:api', 'doc:styles' ]); -gulp.task('doc:docs', async () => { - const commonVars = await generateVars(); - - glob('./src/client/docs/**/*.*.pug', (globErr, files) => { - if (globErr) { - console.error(globErr); - return; - } - files.forEach(file => { - const [, name, lang] = file.match(/docs\/(.+?)\.(.+?)\.pug$/); - const vars = { - common: commonVars, - lang: lang, - title: fs.readFileSync(file, 'utf-8').match(/^h1 (.+?)\r?\n/)[1], - src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/${name}.${lang}.pug`, - }; - pug.renderFile(file, vars, (renderErr, content) => { - if (renderErr) { - console.error(renderErr); - return; - } - - pug.renderFile('./src/client/docs/layout.pug', Object.assign({}, vars, { - content - }), (renderErr2, html) => { - if (renderErr2) { - console.error(renderErr2); - return; - } - const i18n = new I18nReplacer(lang); - html = html.replace(i18n.pattern, i18n.replacement); - html = fa(html); - const htmlPath = `./built/client/docs/${lang}/${name}.html`; - mkdirp(path.dirname(htmlPath), (mkdirErr) => { - if (mkdirErr) { - console.error(mkdirErr); - return; - } - fs.writeFileSync(htmlPath, html, 'utf-8'); - }); - }); - }); - }); - }); -}); - gulp.task('doc:styles', () => gulp.src('./src/client/docs/**/*.styl') .pipe(stylus()) diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index 849194388..b1916abc1 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -9,6 +9,7 @@ import { Context } from 'cafy'; import ObjectContext from 'cafy/built/types/object'; import config from '../../config'; import generateVars from '../../client/docs/vars'; +import I18n from '../../build/i18n'; const docs = `${__dirname}/../../client/docs/`; @@ -63,6 +64,7 @@ router.get('/assets/*', async ctx => { }); router.get('/*/api/endpoints/*', async ctx => { + const lang = ctx.params[0]; const ep = require('../../../built/server/api/endpoints/' + ctx.params[1]).meta; const vars = { @@ -76,14 +78,16 @@ router.get('/*/api/endpoints/*', async ctx => { params: sortParams(Object.keys(ep.params).map(k => parseEPDefParam(k, ep.params[k]))), paramDefs: extractDefs(Object.keys(ep.params).map(k => ep.params[k])), }; - console.log(vars); const commonVars = await generateVars(); + const i18n = new I18n(lang); + await ctx.render('../../../../src/client/docs/api/endpoints/view', Object.assign({}, vars, { - lang: 'ja', + lang, title: ep.name, kebab: (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(), + i18n: (key: string) => i18n.get(null, key), common: commonVars })); }); diff --git a/webpack.config.ts b/webpack.config.ts index 3c426ebb4..1e4904376 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -19,7 +19,7 @@ const constants = require('./src/const.json'); import config from './src/config'; import { licenseHtml } from './src/build/license'; -import locales from './locales'; +const locales = require('./locales'); const meta = require('./package.json'); const version = meta.clientVersion; const codename = meta.codename; From cb0f95ee7dbdc6cd6fb07d49cd0f8dad94f73af3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 12:31:57 +0900 Subject: [PATCH 07/13] wip --- locales/ja.yml | 3 --- package.json | 2 +- src/client/docs/api/mixins.pug | 6 ------ 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/locales/ja.yml b/locales/ja.yml index fc790d8c5..9c5174352 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -1092,7 +1092,4 @@ docs: props: name: "名前" type: "型" - optional: "オプション" description: "説明" - yes: "はい" - no: "いいえ" diff --git a/package.json b/package.json index 3663d42c4..2bd8dc6f4 100644 --- a/package.json +++ b/package.json @@ -89,7 +89,7 @@ "autwh": "0.1.0", "bcryptjs": "2.4.3", "bootstrap-vue": "2.0.0-rc.11", - "cafy": "11.1.0", + "cafy": "11.2.0", "chalk": "2.4.1", "crc-32": "1.2.0", "css-loader": "0.28.11", diff --git a/src/client/docs/api/mixins.pug b/src/client/docs/api/mixins.pug index 6762158f8..79665a61e 100644 --- a/src/client/docs/api/mixins.pug +++ b/src/client/docs/api/mixins.pug @@ -3,7 +3,6 @@ mixin propTable(props) thead: tr th= i18n('docs.api.props.name') th= i18n('docs.api.props.type') - th= i18n('docs.api.props.optional') th= i18n('docs.api.props.description') tbody each prop in props @@ -29,9 +28,4 @@ mixin propTable(props) | ) else if prop.kind == 'date' | (Date) - td.optional - if prop.optional - = i18n('docs.api.props.yes') - else - = i18n('docs.api.props.no') td.desc!= prop.desc ? prop.desc[lang] || prop.desc['ja'] : null From fd67d5cb4c9c3afdefed3e2eb2e629de0b226956 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 12:38:07 +0900 Subject: [PATCH 08/13] wip --- src/cafy-id.ts | 4 ++++ src/client/docs/style.styl | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/cafy-id.ts b/src/cafy-id.ts index 9b7f4f97b..f3e1f5251 100644 --- a/src/cafy-id.ts +++ b/src/cafy-id.ts @@ -26,4 +26,8 @@ export default class ID extends Context { return true; }); } + + public getType() { + return super.getType('string'); + } } diff --git a/src/client/docs/style.styl b/src/client/docs/style.styl index bc165f872..3b1361758 100644 --- a/src/client/docs/style.styl +++ b/src/client/docs/style.styl @@ -10,7 +10,7 @@ main margin 0 0 0 256px padding 64px width 100% - max-width 768px + max-width 800px section margin 32px 0 From 118db9b267c451a164ceaabfdb7ca16d4834e9e2 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 20:27:48 +0900 Subject: [PATCH 09/13] wip --- src/client/docs/api/entities/note.yaml | 4 +- src/client/docs/api/entities/view.pug | 2 +- src/client/docs/layout.pug | 14 +-- src/client/docs/vars.ts | 64 ----------- src/server/web/docs.ts | 143 +++++++++++++++++++++---- 5 files changed, 135 insertions(+), 92 deletions(-) delete mode 100644 src/client/docs/vars.ts diff --git a/src/client/docs/api/entities/note.yaml b/src/client/docs/api/entities/note.yaml index 6fd26543b..c508dab3d 100644 --- a/src/client/docs/api/entities/note.yaml +++ b/src/client/docs/api/entities/note.yaml @@ -27,8 +27,8 @@ props: type: "string" optional: true desc: - ja: "投稿の本文 (ローカルの場合Markdown風のフォーマット)" - en: "The text of this note (in Markdown like format if local)" + ja: "投稿の本文" + en: "The text of this note" - name: "mediaIds" type: "id(DriveFile)[]" optional: true diff --git a/src/client/docs/api/entities/view.pug b/src/client/docs/api/entities/view.pug index ac938151a..a930f71eb 100644 --- a/src/client/docs/api/entities/view.pug +++ b/src/client/docs/api/entities/view.pug @@ -10,7 +10,7 @@ block main p#desc= desc[lang] || desc['ja'] section - h2 %i18n:docs.api.entities.properties% + h2= i18n('docs.api.entities.properties') +propTable(props) if propDefs diff --git a/src/client/docs/layout.pug b/src/client/docs/layout.pug index 1d9ebcb4c..4186d2d36 100644 --- a/src/client/docs/layout.pug +++ b/src/client/docs/layout.pug @@ -10,24 +10,24 @@ html(lang= lang) block meta //- FontAwesome style - style #{common.facss} + style #{facss} body nav ul - each doc in common.docs + each doc in docs li: a(href=`/docs/${lang}/${doc.name}`)= doc.title[lang] || doc.title['ja'] section h2 API ul li Entities ul - each entity in common.entities - li: a(href=`/docs/${lang}/api/entities/${common.kebab(entity)}`)= entity + each entity in entities + li: a(href=`/docs/${lang}/api/entities/${kebab(entity)}`)= entity li Endpoints ul - each endpoint in common.endpoints - li: a(href=`/docs/${lang}/api/endpoints/${common.kebab(endpoint)}`)= endpoint + each endpoint in endpoints + li: a(href=`/docs/${lang}/api/endpoints/${kebab(endpoint)}`)= endpoint main article block main @@ -38,4 +38,4 @@ html(lang= lang) p | %i18n:docs.edit-this-page-on-github% a(href=src target="_blank") %i18n:docs.edit-this-page-on-github-link% - small= common.copyright + small= copyright diff --git a/src/client/docs/vars.ts b/src/client/docs/vars.ts deleted file mode 100644 index 93082767e..000000000 --- a/src/client/docs/vars.ts +++ /dev/null @@ -1,64 +0,0 @@ -import * as fs from 'fs'; -import * as util from 'util'; -import * as glob from 'glob'; -import * as yaml from 'js-yaml'; -import * as licenseChecker from 'license-checker'; -import * as tmp from 'tmp'; - -import { fa } from '../../build/fa'; -import config from '../../config'; -import { licenseHtml } from '../../build/license'; -const constants = require('../../const.json'); - -export default async function(): Promise<{ [key: string]: any }> { - const vars = {} as { [key: string]: any }; - - const endpoints = glob.sync('./src/client/docs/api/endpoints/**/*.yaml'); - vars['endpoints'] = endpoints.map(ep => { - const _ep = yaml.safeLoad(fs.readFileSync(ep, 'utf-8')) as any; - return _ep.endpoint; - }); - - const entities = glob.sync('./src/client/docs/api/entities/**/*.yaml'); - vars['entities'] = entities.map(x => { - const _x = yaml.safeLoad(fs.readFileSync(x, 'utf-8')) as any; - return _x.name; - }); - - const docs = glob.sync('./src/client/docs/**/*.*.pug'); - vars['docs'] = {}; - docs.forEach(x => { - const [, name, lang] = x.match(/docs\/(.+?)\.(.+?)\.pug$/); - if (vars['docs'][name] == null) { - vars['docs'][name] = { - name, - title: {} - }; - } - vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1]; - }); - - vars['kebab'] = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); - - vars['config'] = config; - - vars['copyright'] = constants.copyright; - - vars['facss'] = fa.dom.css(); - - vars['license'] = licenseHtml; - - const tmpObj = tmp.fileSync(); - fs.writeFileSync(tmpObj.name, JSON.stringify({ - licenseText: '' - }), 'utf-8'); - const dependencies = await util.promisify(licenseChecker.init).bind(licenseChecker)({ - start: __dirname + '/../../../', - customPath: tmpObj.name - }); - tmpObj.removeCallback(); - - vars['dependencies'] = dependencies; - - return vars; -} diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index b1916abc1..c7430e073 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -2,17 +2,66 @@ * Docs */ +import * as fs from 'fs'; +import * as path from 'path'; import ms = require('ms'); import * as Router from 'koa-router'; import * as send from 'koa-send'; import { Context } from 'cafy'; +import * as glob from 'glob'; +import * as yaml from 'js-yaml'; import ObjectContext from 'cafy/built/types/object'; import config from '../../config'; -import generateVars from '../../client/docs/vars'; import I18n from '../../build/i18n'; +import { fa } from '../../build/fa'; +import { licenseHtml } from '../../build/license'; +const constants = require('../../const.json'); const docs = `${__dirname}/../../client/docs/`; +async function genVars(lang: string): Promise<{ [key: string]: any }> { + const vars = {} as { [key: string]: any }; + + vars['lang'] = lang; + + const endpoints = glob.sync('./built/server/api/endpoints/**/*.js'); + vars['endpoints'] = endpoints.map(ep => require('../../../' + ep)).filter(x => x.meta).map(x => x.meta.name); + + const entities = glob.sync('./src/client/docs/api/entities/**/*.yaml'); + vars['entities'] = entities.map(x => { + const _x = yaml.safeLoad(fs.readFileSync(x, 'utf-8')) as any; + return _x.name; + }); + + const docs = glob.sync('./src/client/docs/**/*.*.pug'); + vars['docs'] = {}; + docs.forEach(x => { + const [, name, lang] = x.match(/docs\/(.+?)\.(.+?)\.pug$/); + if (vars['docs'][name] == null) { + vars['docs'][name] = { + name, + title: {} + }; + } + vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1]; + }); + + vars['kebab'] = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(); + + vars['config'] = config; + + vars['copyright'] = constants.copyright; + + vars['facss'] = fa.dom.css(); + + vars['license'] = licenseHtml; + + const i18n = new I18n(lang); + vars['i18n'] = (key: string) => i18n.get(null, key); + + return vars; +} + // WIP type const parseEPDefParam = (key: string, param: Context) => { return Object.assign({ @@ -21,6 +70,46 @@ const parseEPDefParam = (key: string, param: Context) => { }, param.data); }; +const parseParam = (param: any) => { + const id = param.type.match(/^id\((.+?)\)|^id/); + const entity = param.type.match(/^entity\((.+?)\)/); + const isObject = /^object/.test(param.type); + const isDate = /^date/.test(param.type); + const isArray = /\[\]$/.test(param.type); + if (id) { + param.kind = 'id'; + param.type = 'string'; + param.entity = id[1]; + if (isArray) { + param.type += '[]'; + } + } + if (entity) { + param.kind = 'entity'; + param.type = 'object'; + param.entity = entity[1]; + if (isArray) { + param.type += '[]'; + } + } + if (isObject) { + param.kind = 'object'; + } + if (isDate) { + param.kind = 'date'; + param.type = 'string'; + if (isArray) { + param.type += '[]'; + } + } + + if (param.optional) { + param.type += '?'; + } + + return param; +}; + const sortParams = (params: Array<{name: string}>) => { params.sort((a, b) => { if (a.name < b.name) @@ -33,7 +122,7 @@ const sortParams = (params: Array<{name: string}>) => { }; // WIP type -const extractDefs = (params: Context[]) => { +const extractEPDefs = (params: Context[]) => { let defs: any[] = []; params.forEach(param => { @@ -44,7 +133,26 @@ const extractDefs = (params: Context[]) => { params: sortParams(Object.keys(props).map(k => parseEPDefParam(k, props[k]))) }); - const childDefs = extractDefs(Object.keys(props).map(k => props[k])); + const childDefs = extractEPDefs(Object.keys(props).map(k => props[k])); + + defs = defs.concat(childDefs); + } + }); + + return sortParams(defs); +}; + +const extractDefs = (params: any[]) => { + let defs: any[] = []; + + params.forEach(param => { + if (param.def) { + defs.push({ + name: param.defName, + params: sortParams(param.def.map((p: any) => parseParam(p))) + }); + + const childDefs = extractDefs(param.def); defs = defs.concat(childDefs); } @@ -68,6 +176,7 @@ router.get('/*/api/endpoints/*', async ctx => { const ep = require('../../../built/server/api/endpoints/' + ctx.params[1]).meta; const vars = { + title: ep.name, endpoint: ep.name, url: { host: config.api_url, @@ -76,26 +185,24 @@ router.get('/*/api/endpoints/*', async ctx => { desc: ep.desc, // @ts-ignore params: sortParams(Object.keys(ep.params).map(k => parseEPDefParam(k, ep.params[k]))), - paramDefs: extractDefs(Object.keys(ep.params).map(k => ep.params[k])), + paramDefs: extractEPDefs(Object.keys(ep.params).map(k => ep.params[k])), }; - const commonVars = await generateVars(); + await ctx.render('../../../../src/client/docs/api/endpoints/view', Object.assign(await genVars(lang), vars)); +}); - const i18n = new I18n(lang); +router.get('/*/api/entities/*', async ctx => { + const lang = ctx.params[0]; + const entity = ctx.params[1]; - await ctx.render('../../../../src/client/docs/api/endpoints/view', Object.assign({}, vars, { - lang, - title: ep.name, - kebab: (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase(), - i18n: (key: string) => i18n.get(null, key), - common: commonVars + const x = yaml.safeLoad(fs.readFileSync(path.resolve('./src/client/docs/api/entities/' + entity + '.yaml'), 'utf-8')) as any; + + await ctx.render('../../../../src/client/docs/api/entities/view', Object.assign(await genVars(lang), { + name: x.name, + desc: x.desc, + props: sortParams(x.props.map((p: any) => parseParam(p))), + propDefs: extractDefs(x.props) })); }); -router.get('*', async ctx => { - await send(ctx, `${ctx.params[0]}.html`, { - root: docs - }); -}); - export default router; From a81a34cd765b1b226a6ad1382e3c076572aa1dd9 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 20:40:44 +0900 Subject: [PATCH 10/13] =?UTF-8?q?=E6=96=B0=E5=BD=A2=E5=BC=8F=E3=81=AB?= =?UTF-8?q?=E7=A7=BB=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints/notes/timeline.ts | 121 +++++++++++++-------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts index 9144c6625..eb491bc8e 100644 --- a/src/server/api/endpoints/notes/timeline.ts +++ b/src/server/api/endpoints/notes/timeline.ts @@ -4,48 +4,81 @@ import Mute from '../../../../models/mute'; import { getFriends } from '../../common/get-friends'; import { pack } from '../../../../models/note'; import { ILocalUser } from '../../../../models/user'; +import getParams from '../../get-params'; + +export const meta = { + name: 'notes/timeline', + + desc: { + ja: 'タイムラインを取得します。' + }, + + params: { + limit: $.num.optional.range(1, 100).note({ + default: 10, + desc: { + ja: '最大数' + } + }), + + sinceId: $.type(ID).optional.note({ + desc: { + ja: '指定すると、この投稿を基点としてより新しい投稿を取得します' + } + }), + + untilId: $.type(ID).optional.note({ + desc: { + ja: '指定すると、この投稿を基点としてより古い投稿を取得します' + } + }), + + sinceDate: $.num.optional.note({ + desc: { + ja: '指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。' + } + }), + + untilDate: $.num.optional.note({ + desc: { + ja: '指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。' + } + }), + + includeMyRenotes: $.bool.optional.note({ + default: true, + desc: { + ja: '自分の行ったRenoteを含めるかどうか' + } + }), + + includeRenotedMyNotes: $.bool.optional.note({ + default: true, + desc: { + ja: 'Renoteされた自分の投稿を含めるかどうか' + } + }), + + mediaOnly: $.bool.optional.note({ + desc: { + ja: 'true にすると、メディアが添付された投稿だけ取得します' + } + }), + } +}; /** * Get timeline of myself */ export default async (params: any, user: ILocalUser) => { - // Get 'limit' parameter - const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit); - if (limitErr) throw 'invalid limit param'; - - // Get 'sinceId' parameter - const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId); - if (sinceIdErr) throw 'invalid sinceId param'; - - // Get 'untilId' parameter - const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId); - if (untilIdErr) throw 'invalid untilId param'; - - // Get 'sinceDate' parameter - const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate); - if (sinceDateErr) throw 'invalid sinceDate param'; - - // Get 'untilDate' parameter - const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate); - if (untilDateErr) throw 'invalid untilDate param'; + const [ps, psErr] = getParams(meta, params); + if (psErr) throw psErr; // Check if only one of sinceId, untilId, sinceDate, untilDate specified - if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) { + if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) { throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified'; } - // Get 'includeMyRenotes' parameter - const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes); - if (includeMyRenotesErr) throw 'invalid includeMyRenotes param'; - - // Get 'includeRenotedMyNotes' parameter - const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes); - if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param'; - - // Get 'mediaOnly' parameter - const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly); - if (mediaOnlyErr) throw 'invalid mediaOnly param'; - const [followings, mutedUserIds] = await Promise.all([ // フォローを取得 // Fetch following @@ -107,7 +140,7 @@ export default async (params: any, user: ILocalUser) => { // つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。 // for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws - if (includeMyRenotes === false) { + if (ps.includeMyRenotes === false) { query.$and.push({ $or: [{ userId: { $ne: user._id } @@ -123,7 +156,7 @@ export default async (params: any, user: ILocalUser) => { }); } - if (includeRenotedMyNotes === false) { + if (ps.includeRenotedMyNotes === false) { query.$and.push({ $or: [{ '_renote.userId': { $ne: user._id } @@ -139,29 +172,29 @@ export default async (params: any, user: ILocalUser) => { }); } - if (mediaOnly) { + if (ps.mediaOnly) { query.$and.push({ mediaIds: { $exists: true, $ne: [] } }); } - if (sinceId) { + if (ps.sinceId) { sort._id = 1; query._id = { - $gt: sinceId + $gt: ps.sinceId }; - } else if (untilId) { + } else if (ps.untilId) { query._id = { - $lt: untilId + $lt: ps.untilId }; - } else if (sinceDate) { + } else if (ps.sinceDate) { sort._id = 1; query.createdAt = { - $gt: new Date(sinceDate) + $gt: new Date(ps.sinceDate) }; - } else if (untilDate) { + } else if (ps.untilDate) { query.createdAt = { - $lt: new Date(untilDate) + $lt: new Date(ps.untilDate) }; } //#endregion @@ -169,7 +202,7 @@ export default async (params: any, user: ILocalUser) => { // Issue query const timeline = await Note .find(query, { - limit: limit, + limit: ps.limit, sort: sort }); From 4179685bb6e48503307159edc2a510e949839249 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 23:19:41 +0900 Subject: [PATCH 11/13] :v: --- src/server/api/endpoints/notes/timeline.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/api/endpoints/notes/timeline.ts b/src/server/api/endpoints/notes/timeline.ts index eb491bc8e..43194c78c 100644 --- a/src/server/api/endpoints/notes/timeline.ts +++ b/src/server/api/endpoints/notes/timeline.ts @@ -35,13 +35,13 @@ export const meta = { sinceDate: $.num.optional.note({ desc: { - ja: '指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。' + ja: '指定した時間を基点としてより新しい投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。' } }), untilDate: $.num.optional.note({ desc: { - ja: '指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。' + ja: '指定した時間を基点としてより古い投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。' } }), From 42d4e6610f2b0fdc5a4b384757756700dbb68454 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 23:19:47 +0900 Subject: [PATCH 12/13] =?UTF-8?q?=E7=A7=BB=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/notes/reactions/create.ts | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts index 709b47ab5..8b22e5322 100644 --- a/src/server/api/endpoints/notes/reactions/create.ts +++ b/src/server/api/endpoints/notes/reactions/create.ts @@ -3,22 +3,40 @@ import Note from '../../../../../models/note'; import create from '../../../../../services/note/reaction/create'; import { validateReaction } from '../../../../../models/note-reaction'; import { ILocalUser } from '../../../../../models/user'; +import getParams from '../../../get-params'; + +export const meta = { + name: 'notes/reactions/create', + + desc: { + ja: '投稿にリアクションします。' + }, + + params: { + noteId: $.type(ID).note({ + desc: { + ja: '対象の投稿' + } + }), + + reaction: $.str.pipe(validateReaction.ok).note({ + desc: { + ja: 'リアクションの種類' + } + }) + } +}; /** * React to a note */ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { - // Get 'noteId' parameter - const [noteId, noteIdErr] = $.type(ID).get(params.noteId); - if (noteIdErr) return rej('invalid noteId param'); - - // Get 'reaction' parameter - const [reaction, reactionErr] = $.str.pipe(validateReaction.ok).get(params.reaction); - if (reactionErr) return rej('invalid reaction param'); + const [ps, psErr] = getParams(meta, params); + if (psErr) return rej(psErr); // Fetch reactee const note = await Note.findOne({ - _id: noteId + _id: ps.noteId }); if (note === null) { @@ -26,7 +44,7 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) = } try { - await create(user, note, reaction); + await create(user, note, ps.reaction); } catch (e) { rej(e); } From e74c1f2ac64be957cb43cc836d299710fd4537c5 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 23:52:47 +0900 Subject: [PATCH 13/13] w --- src/server/api/call.ts | 2 +- src/server/api/endpoints/meta.ts | 2 +- src/server/web/docs.ts | 7 +++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/server/api/call.ts b/src/server/api/call.ts index fd3cea774..b1e166876 100644 --- a/src/server/api/call.ts +++ b/src/server/api/call.ts @@ -31,7 +31,7 @@ export default (endpoint: string | Endpoint, user: IUser, app: IApp, data: any, } } - let exec = require(`${__dirname}/endpoints/${ep.name}`); + let exec = require(`${__dirname}/endpoints/${ep.name}`).default; if (ep.withFile && file) { exec = exec.bind(null, file); diff --git a/src/server/api/endpoints/meta.ts b/src/server/api/endpoints/meta.ts index 836123a3a..64cf9db55 100644 --- a/src/server/api/endpoints/meta.ts +++ b/src/server/api/endpoints/meta.ts @@ -38,7 +38,7 @@ const client = require('../../../../built/client/meta.json'); /** * Show core info */ -export default (params: any) => new Promise(async (res, rej) => { +export default () => new Promise(async (res, rej) => { const meta: any = (await Meta.findOne()) || {}; res({ diff --git a/src/server/web/docs.ts b/src/server/web/docs.ts index c7430e073..e67070963 100644 --- a/src/server/web/docs.ts +++ b/src/server/web/docs.ts @@ -205,4 +205,11 @@ router.get('/*/api/entities/*', async ctx => { })); }); +router.get('/*/*', async ctx => { + const lang = ctx.params[0]; + const doc = ctx.params[1]; + + await ctx.render('../../../../src/client/docs/' + doc + '.' + lang, await genVars(lang)); +}); + export default router;