From 8e3d56fdb9ef4fd67a60f03e10d8deb84a4b70f4 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 6 Jul 2018 02:58:29 +0900 Subject: [PATCH] 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