This commit is contained in:
syuilo 2018-11-02 13:47:44 +09:00
parent ddc3c5ba68
commit 174f8022eb
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
131 changed files with 512 additions and 917 deletions

View file

@ -42,18 +42,12 @@ export default (endpoint: string, user: IUser, app: IApp, data: any, file?: any)
} }
} }
let exec = ep.exec;
if (ep.meta.requireFile && file) {
exec = exec.bind(null, file);
}
let res; let res;
// API invoking // API invoking
try { try {
const before = performance.now(); const before = performance.now();
res = await exec(data, user, app); res = await ep.exec(data, user, app, file);
const after = performance.now(); const after = performance.now();
const time = after - before; const time = after - before;

51
src/server/api/define.ts Normal file
View file

@ -0,0 +1,51 @@
import * as fs from 'fs';
import { ILocalUser } from '../../models/user';
import { IApp } from '../../models/app';
import { IEndpointMeta } from './endpoints';
type Params<T extends IEndpointMeta> = {
[P in keyof T['params']]: T['params'][P]['transform'] extends Function
? ReturnType<T['params'][P]['transform']>
: ReturnType<T['params'][P]['validator']['get']>[0];
};
export default function <T extends IEndpointMeta>(meta: T, cb: (params: Params<T>, user: ILocalUser, app: IApp, file?: any, cleanup?: Function) => Promise<any>): (params: any, user: ILocalUser, app: IApp, file?: any) => Promise<any> {
return (params: any, user: ILocalUser, app: IApp, file?: any) => {
function cleanup() {
fs.unlink(file.path, () => {});
}
if (meta.requireFile && file == null) return Promise.reject('file required');
const [ps, pserr] = getParams(meta, params);
if (pserr) {
if (file) cleanup();
return Promise.reject(pserr);
}
return cb(ps, user, app, file, cleanup);
};
}
function getParams<T extends IEndpointMeta>(defs: T, params: any): [Params<T>, Error] {
const x: any = {};
let err: Error = null;
Object.entries(defs.params).some(([k, def]) => {
const [v, e] = def.validator.get(params[k]);
if (e) {
err = new Error(e.message);
err.name = 'INVALID_PARAM';
(err as any).param = k;
return true;
} else {
if (v === undefined && def.default) {
x[k] = def.default;
} else {
x[k] = v;
}
if (def.transform) x[k] = def.transform(x[k]);
return false;
}
});
return [x, err];
}

View file

@ -1,5 +1,6 @@
import rndstr from 'rndstr'; import rndstr from 'rndstr';
import RegistrationTicket from '../../../../models/registration-tickets'; import RegistrationTicket from '../../../../models/registration-tickets';
import define from '../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -12,7 +13,7 @@ export const meta = {
params: {} params: {}
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const code = rndstr({ length: 5, chars: '0-9' }); const code = rndstr({ length: 5, chars: '0-9' });
await RegistrationTicket.insert({ await RegistrationTicket.insert({
@ -23,4 +24,4 @@ export default (params: any) => new Promise(async (res, rej) => {
res({ res({
code: code code: code
}); });
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id'; import ID, { transform } from '../../../../misc/cafy-id';
import getParams from '../../get-params'; import define from '../../define';
import User from '../../../../models/user'; import User from '../../../../models/user';
export const meta = { export const meta = {
@ -24,10 +24,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const user = await User.findOne({ const user = await User.findOne({
_id: ps.userId _id: ps.userId
}); });
@ -49,4 +46,4 @@ export default (params: any) => new Promise(async (res, rej) => {
}); });
res(); res();
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id'; import ID, { transform } from '../../../../misc/cafy-id';
import getParams from '../../get-params'; import define from '../../define';
import User from '../../../../models/user'; import User from '../../../../models/user';
export const meta = { export const meta = {
@ -24,10 +24,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const user = await User.findOne({ const user = await User.findOne({
_id: ps.userId _id: ps.userId
}); });
@ -45,4 +42,4 @@ export default (params: any) => new Promise(async (res, rej) => {
}); });
res(); res();
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id'; import ID, { transform } from '../../../../misc/cafy-id';
import getParams from '../../get-params'; import define from '../../define';
import User from '../../../../models/user'; import User from '../../../../models/user';
export const meta = { export const meta = {
@ -24,10 +24,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const user = await User.findOne({ const user = await User.findOne({
_id: ps.userId _id: ps.userId
}); });
@ -45,4 +42,4 @@ export default (params: any) => new Promise(async (res, rej) => {
}); });
res(); res();
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import Meta from '../../../../models/meta'; import Meta from '../../../../models/meta';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -55,10 +55,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const set = {} as any; const set = {} as any;
if (ps.broadcasts) { if (ps.broadcasts) {
@ -90,4 +87,4 @@ export default (params: any) => new Promise(async (res, rej) => {
}, { upsert: true }); }, { upsert: true });
res(); res();
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id'; import ID, { transform } from '../../../../misc/cafy-id';
import getParams from '../../get-params'; import define from '../../define';
import User from '../../../../models/user'; import User from '../../../../models/user';
export const meta = { export const meta = {
@ -24,10 +24,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const user = await User.findOne({ const user = await User.findOne({
_id: ps.userId _id: ps.userId
}); });
@ -45,4 +42,4 @@ export default (params: any) => new Promise(async (res, rej) => {
}); });
res(); res();
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import config from '../../../../config'; import config from '../../../../config';
import * as mongo from 'mongodb'; import * as mongo from 'mongodb';
import User, { pack as packUser, IUser } from '../../../../models/user'; import User, { pack as packUser, IUser } from '../../../../models/user';
@ -25,15 +25,12 @@ export const meta = {
}, },
}; };
export default async (params: any) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
const object = await fetchAny(ps.uri); const object = await fetchAny(ps.uri);
if (object !== null) return object; if (object == null) return rej('object not found');
throw new Error('object not found'); res(object);
}; }));
/*** /***
* URIからUserかNoteを解決する * URIからUserかNoteを解決する

View file

@ -1,8 +1,7 @@
import rndstr from 'rndstr'; import rndstr from 'rndstr';
import $ from 'cafy'; import $ from 'cafy';
import App, { pack } from '../../../../models/app'; import App, { pack } from '../../../../models/app';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
requireCredential: false, requireCredential: false,
@ -28,10 +27,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Generate secret // Generate secret
const secret = rndstr('a-zA-Z0-9', 32); const secret = rndstr('a-zA-Z0-9', 32);
@ -51,4 +47,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
detail: true, detail: true,
includeSecret: true includeSecret: true
})); }));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import App, { pack, IApp } from '../../../../models/app'; import App, { pack } from '../../../../models/app';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
params: { params: {
@ -12,10 +11,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const isSecure = user != null && app == null; const isSecure = user != null && app == null;
// Lookup app // Lookup app
@ -30,4 +26,4 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
detail: true, detail: true,
includeSecret: isSecure && ap.userId.equals(user._id) includeSecret: isSecure && ap.userId.equals(user._id)
})); }));
}); }));

View file

@ -4,8 +4,7 @@ import $ from 'cafy';
import App from '../../../../models/app'; import App from '../../../../models/app';
import AuthSess from '../../../../models/auth-session'; import AuthSess from '../../../../models/auth-session';
import AccessToken from '../../../../models/access-token'; import AccessToken from '../../../../models/access-token';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -19,10 +18,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch token // Fetch token
const session = await AuthSess const session = await AuthSess
.findOne({ token: ps.token }); .findOne({ token: ps.token });
@ -70,4 +66,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Response // Response
res(); res();
}); }));

View file

@ -3,7 +3,7 @@ import $ from 'cafy';
import App from '../../../../../models/app'; import App from '../../../../../models/app';
import AuthSess from '../../../../../models/auth-session'; import AuthSess from '../../../../../models/auth-session';
import config from '../../../../../config'; import config from '../../../../../config';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: false, requireCredential: false,
@ -15,10 +15,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Lookup app // Lookup app
const app = await App.findOne({ const app = await App.findOne({
secret: ps.appSecret secret: ps.appSecret
@ -43,4 +40,4 @@ export default (params: any) => new Promise(async (res, rej) => {
token: doc.token, token: doc.token,
url: `${config.auth_url}/${doc.token}` url: `${config.auth_url}/${doc.token}`
}); });
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import AuthSess, { pack } from '../../../../../models/auth-session'; import AuthSess, { pack } from '../../../../../models/auth-session';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
requireCredential: false, requireCredential: false,
@ -13,10 +12,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Lookup session // Lookup session
const session = await AuthSess.findOne({ const session = await AuthSess.findOne({
token: ps.token token: ps.token
@ -28,4 +24,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Response // Response
res(await pack(session, user)); res(await pack(session, user));
}); }));

View file

@ -3,7 +3,7 @@ import App from '../../../../../models/app';
import AuthSess from '../../../../../models/auth-session'; import AuthSess from '../../../../../models/auth-session';
import AccessToken from '../../../../../models/access-token'; import AccessToken from '../../../../../models/access-token';
import { pack } from '../../../../../models/user'; import { pack } from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: false, requireCredential: false,
@ -19,10 +19,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Lookup app // Lookup app
const app = await App.findOne({ const app = await App.findOne({
secret: ps.appSecret secret: ps.appSecret
@ -71,4 +68,4 @@ export default (params: any) => new Promise(async (res, rej) => {
detail: true detail: true
}) })
}); });
}); }));

View file

@ -1,9 +1,9 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
const ms = require('ms'); const ms = require('ms');
import User, { pack, ILocalUser } from '../../../../models/user'; import User, { pack } from '../../../../models/user';
import Blocking from '../../../../models/blocking'; import Blocking from '../../../../models/blocking';
import create from '../../../../services/blocking/create'; import create from '../../../../services/blocking/create';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -34,10 +34,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const blocker = user; const blocker = user;
// 自分自身 // 自分自身
@ -76,4 +73,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await pack(blockee._id, user, { res(await pack(blockee._id, user, {
detail: true detail: true
})); }));
}); }));

View file

@ -1,9 +1,9 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
const ms = require('ms'); const ms = require('ms');
import User, { pack, ILocalUser } from '../../../../models/user'; import User, { pack } from '../../../../models/user';
import Blocking from '../../../../models/blocking'; import Blocking from '../../../../models/blocking';
import deleteBlocking from '../../../../services/blocking/delete'; import deleteBlocking from '../../../../services/blocking/delete';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -34,10 +34,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const blocker = user; const blocker = user;
// Check if the blockee is yourself // Check if the blockee is yourself
@ -76,4 +73,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await pack(blockee._id, user, { res(await pack(blockee._id, user, {
detail: true detail: true
})); }));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Blocking, { packMany } from '../../../../models/blocking'; import Blocking, { packMany } from '../../../../models/blocking';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -31,10 +30,7 @@ export const meta = {
} }
}; };
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -66,4 +62,4 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
}); });
res(await packMany(blockings, me)); res(await packMany(blockings, me));
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import driveChart from '../../../../chart/drive'; import driveChart from '../../../../chart/drive';
export const meta = { export const meta = {
@ -25,11 +25,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await driveChart.getChart(ps.span as any, ps.limit); const stats = await driveChart.getChart(ps.span as any, ps.limit);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import federationChart from '../../../../chart/federation'; import federationChart from '../../../../chart/federation';
export const meta = { export const meta = {
@ -25,11 +25,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await federationChart.getChart(ps.span as any, ps.limit); const stats = await federationChart.getChart(ps.span as any, ps.limit);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import hashtagChart from '../../../../chart/hashtag'; import hashtagChart from '../../../../chart/hashtag';
export const meta = { export const meta = {
@ -32,11 +32,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await hashtagChart.getChart(ps.span as any, ps.limit, ps.tag); const stats = await hashtagChart.getChart(ps.span as any, ps.limit, ps.tag);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import networkChart from '../../../../chart/network'; import networkChart from '../../../../chart/network';
export const meta = { export const meta = {
@ -25,11 +25,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await networkChart.getChart(ps.span as any, ps.limit); const stats = await networkChart.getChart(ps.span as any, ps.limit);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import notesChart from '../../../../chart/notes'; import notesChart from '../../../../chart/notes';
export const meta = { export const meta = {
@ -25,11 +25,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await notesChart.getChart(ps.span as any, ps.limit); const stats = await notesChart.getChart(ps.span as any, ps.limit);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../../get-params'; import define from '../../../define';
import perUserDriveChart from '../../../../../chart/per-user-drive'; import perUserDriveChart from '../../../../../chart/per-user-drive';
import ID, { transform } from '../../../../../misc/cafy-id'; import ID, { transform } from '../../../../../misc/cafy-id';
@ -35,11 +35,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await perUserDriveChart.getChart(ps.span as any, ps.limit, ps.userId); const stats = await perUserDriveChart.getChart(ps.span as any, ps.limit, ps.userId);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../../get-params'; import define from '../../../define';
import perUserFollowingChart from '../../../../../chart/per-user-following'; import perUserFollowingChart from '../../../../../chart/per-user-following';
import ID, { transform } from '../../../../../misc/cafy-id'; import ID, { transform } from '../../../../../misc/cafy-id';
@ -35,11 +35,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await perUserFollowingChart.getChart(ps.span as any, ps.limit, ps.userId); const stats = await perUserFollowingChart.getChart(ps.span as any, ps.limit, ps.userId);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../../get-params'; import define from '../../../define';
import perUserNotesChart from '../../../../../chart/per-user-notes'; import perUserNotesChart from '../../../../../chart/per-user-notes';
import ID, { transform } from '../../../../../misc/cafy-id'; import ID, { transform } from '../../../../../misc/cafy-id';
@ -35,11 +35,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await perUserNotesChart.getChart(ps.span as any, ps.limit, ps.userId); const stats = await perUserNotesChart.getChart(ps.span as any, ps.limit, ps.userId);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../../get-params'; import define from '../../../define';
import perUserReactionsChart from '../../../../../chart/per-user-reactions'; import perUserReactionsChart from '../../../../../chart/per-user-reactions';
import ID, { transform } from '../../../../../misc/cafy-id'; import ID, { transform } from '../../../../../misc/cafy-id';
@ -35,11 +35,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await perUserReactionsChart.getChart(ps.span as any, ps.limit, ps.userId); const stats = await perUserReactionsChart.getChart(ps.span as any, ps.limit, ps.userId);
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import $ from 'cafy'; import $ from 'cafy';
import getParams from '../../get-params'; import define from '../../define';
import usersChart from '../../../../chart/users'; import usersChart from '../../../../chart/users';
export const meta = { export const meta = {
@ -25,11 +25,8 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const stats = await usersChart.getChart(ps.span as any, ps.limit); const stats = await usersChart.getChart(ps.span as any, ps.limit);
res(stats); res(stats);
}); }));

View file

@ -1,6 +1,6 @@
import DriveFile from '../../../models/drive-file'; import DriveFile from '../../../models/drive-file';
import { ILocalUser } from '../../../models/user';
import config from '../../../config'; import config from '../../../config';
import define from '../define';
export const meta = { export const meta = {
desc: { desc: {
@ -13,7 +13,7 @@ export const meta = {
kind: 'drive-read' kind: 'drive-read'
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// Calculate drive usage // Calculate drive usage
const usage = await DriveFile const usage = await DriveFile
.aggregate([{ .aggregate([{
@ -42,4 +42,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
capacity: 1024 * 1024 * config.localDriveCapacityMb, capacity: 1024 * 1024 * config.localDriveCapacityMb,
usage: usage usage: usage
}); });
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import DriveFile, { packMany } from '../../../../models/drive-file'; import DriveFile, { packMany } from '../../../../models/drive-file';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -41,13 +40,10 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
throw 'cannot set sinceId and untilId'; return rej('cannot set sinceId and untilId');
} }
const sort = { const sort = {
@ -81,5 +77,5 @@ export default async (params: any, user: ILocalUser) => {
sort: sort sort: sort
}); });
return await packMany(files); res(await packMany(files));
}; }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFile from '../../../../../models/drive-file'; import DriveFile from '../../../../../models/drive-file';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
import { packMany } from '../../../../../models/note'; import { packMany } from '../../../../../models/note';
export const meta = { export const meta = {
@ -28,10 +27,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch file // Fetch file
const file = await DriveFile const file = await DriveFile
.findOne({ .findOne({
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await packMany(file.metadata.attachedNoteIds || [], user, { res(await packMany(file.metadata.attachedNoteIds || [], user, {
detail: true detail: true
})); }));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import DriveFile, { pack } from '../../../../../models/drive-file'; import DriveFile, { pack } from '../../../../../models/drive-file';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -23,10 +22,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const file = await DriveFile.findOne({ const file = await DriveFile.findOne({
md5: ps.md5, md5: ps.md5,
'metadata.userId': user._id, 'metadata.userId': user._id,
@ -38,4 +34,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
} else { } else {
res({ file: await pack(file) }); res({ file: await pack(file) });
} }
}); }));

View file

@ -1,10 +1,8 @@
import * as fs from 'fs';
const ms = require('ms'); const ms = require('ms');
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import { validateFileName, pack } from '../../../../../models/drive-file'; import { validateFileName, pack } from '../../../../../models/drive-file';
import create from '../../../../../services/drive/add-file'; import create from '../../../../../services/drive/add-file';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -52,11 +50,7 @@ export const meta = {
} }
}; };
export default async (file: any, params: any, user: ILocalUser): Promise<any> => { export default define(meta, (ps, user, app, file, cleanup) => new Promise(async (res, rej) => {
if (file == null) {
throw 'file is required';
}
// Get 'name' parameter // Get 'name' parameter
let name = file.originalname; let name = file.originalname;
if (name !== undefined && name !== null) { if (name !== undefined && name !== null) {
@ -66,35 +60,24 @@ export default async (file: any, params: any, user: ILocalUser): Promise<any> =>
} else if (name === 'blob') { } else if (name === 'blob') {
name = null; name = null;
} else if (!validateFileName(name)) { } else if (!validateFileName(name)) {
throw 'invalid name'; return rej('invalid name');
} }
} else { } else {
name = null; name = null;
} }
function cleanup() {
fs.unlink(file.path, () => {});
}
const [ps, psErr] = getParams(meta, params);
if (psErr) {
cleanup();
throw psErr;
}
try { try {
// Create file // Create file
const driveFile = await create(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive); const driveFile = await create(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive);
cleanup(); cleanup();
// Serialize res(pack(driveFile));
return pack(driveFile);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
cleanup(); cleanup();
throw e; rej(e);
} }
}; }));

View file

@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id
import DriveFile from '../../../../../models/drive-file'; import DriveFile from '../../../../../models/drive-file';
import del from '../../../../../services/drive/delete-file'; import del from '../../../../../services/drive/delete-file';
import { publishDriveStream } from '../../../../../stream'; import { publishDriveStream } from '../../../../../stream';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -29,10 +28,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch file // Fetch file
const file = await DriveFile const file = await DriveFile
.findOne({ .findOne({
@ -51,4 +47,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
publishDriveStream(user._id, 'fileDeleted', file._id); publishDriveStream(user._id, 'fileDeleted', file._id);
res(); res();
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFile, { pack } from '../../../../../models/drive-file'; import DriveFile, { pack } from '../../../../../models/drive-file';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -24,10 +23,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const files = await DriveFile const files = await DriveFile
.find({ .find({
filename: name, filename: name,
@ -36,4 +32,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(await Promise.all(files.map(file => pack(file)))); res(await Promise.all(files.map(file => pack(file))));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFile, { pack } from '../../../../../models/drive-file'; import DriveFile, { pack } from '../../../../../models/drive-file';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -27,10 +26,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch file // Fetch file
const file = await DriveFile const file = await DriveFile
.findOne({ .findOne({
@ -49,4 +45,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(_file); res(_file);
}); }));

View file

@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id
import DriveFolder from '../../../../../models/drive-folder'; import DriveFolder from '../../../../../models/drive-folder';
import DriveFile, { validateFileName, pack } from '../../../../../models/drive-file'; import DriveFile, { validateFileName, pack } from '../../../../../models/drive-file';
import { publishDriveStream } from '../../../../../stream'; import { publishDriveStream } from '../../../../../stream';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
import Note from '../../../../../models/note'; import Note from '../../../../../models/note';
export const meta = { export const meta = {
@ -54,10 +53,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch file // Fetch file
const file = await DriveFile const file = await DriveFile
.findOne({ .findOne({
@ -122,4 +118,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Publish fileUpdated event // Publish fileUpdated event
publishDriveStream(user._id, 'fileUpdated', fileObj); publishDriveStream(user._id, 'fileUpdated', fileObj);
}); }));

View file

@ -3,7 +3,7 @@ const ms = require('ms');
import { pack } from '../../../../../models/drive-file'; import { pack } from '../../../../../models/drive-file';
import uploadFromUrl from '../../../../../services/drive/upload-from-url'; import uploadFromUrl from '../../../../../services/drive/upload-from-url';
import { ILocalUser } from '../../../../../models/user'; import { ILocalUser } from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -33,9 +33,6 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser): Promise<any> => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params); res(pack(await uploadFromUrl(ps.url, user, ps.folderId)));
if (psErr) throw psErr; }));
return pack(await uploadFromUrl(ps.url, user, ps.folderId));
};

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import DriveFolder, { pack } from '../../../../models/drive-folder'; import DriveFolder, { pack } from '../../../../models/drive-folder';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -37,10 +36,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -71,4 +67,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(await Promise.all(folders.map(folder => pack(folder)))); res(await Promise.all(folders.map(folder => pack(folder))));
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder'; import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder';
import { publishDriveStream } from '../../../../../stream'; import { publishDriveStream } from '../../../../../stream';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -37,10 +36,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// If the parent folder is specified // If the parent folder is specified
let parent = null; let parent = null;
if (ps.parentId) { if (ps.parentId) {
@ -72,4 +68,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Publish folderCreated event // Publish folderCreated event
publishDriveStream(user._id, 'folderCreated', folderObj); publishDriveStream(user._id, 'folderCreated', folderObj);
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder from '../../../../../models/drive-folder'; import DriveFolder from '../../../../../models/drive-folder';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
import { publishDriveStream } from '../../../../../stream'; import { publishDriveStream } from '../../../../../stream';
import DriveFile from '../../../../../models/drive-file'; import DriveFile from '../../../../../models/drive-file';
@ -29,10 +28,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get folder // Get folder
const folder = await DriveFolder const folder = await DriveFolder
.findOne({ .findOne({
@ -59,4 +55,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
publishDriveStream(user._id, 'folderDeleted', folder._id); publishDriveStream(user._id, 'folderDeleted', folder._id);
res(); res();
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder, { pack } from '../../../../../models/drive-folder'; import DriveFolder, { pack } from '../../../../../models/drive-folder';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -24,10 +23,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const folders = await DriveFolder const folders = await DriveFolder
.find({ .find({
name: name, name: name,
@ -36,4 +32,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(await Promise.all(folders.map(folder => pack(folder)))); res(await Promise.all(folders.map(folder => pack(folder))));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder, { pack } from '../../../../../models/drive-folder'; import DriveFolder, { pack } from '../../../../../models/drive-folder';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -27,10 +26,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get folder // Get folder
const folder = await DriveFolder const folder = await DriveFolder
.findOne({ .findOne({
@ -46,4 +42,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await pack(folder, { res(await pack(folder, {
detail: true detail: true
})); }));
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder'; import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder';
import { publishDriveStream } from '../../../../../stream'; import { publishDriveStream } from '../../../../../stream';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -45,10 +44,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch folder // Fetch folder
const folder = await DriveFolder const folder = await DriveFolder
.findOne({ .findOne({
@ -122,4 +118,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Publish folderUpdated event // Publish folderUpdated event
publishDriveStream(user._id, 'folderUpdated', folderObj); publishDriveStream(user._id, 'folderUpdated', folderObj);
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import DriveFile, { packMany } from '../../../../models/drive-file'; import DriveFile, { packMany } from '../../../../models/drive-file';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -30,10 +29,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -70,4 +66,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(await packMany(files)); res(await packMany(files));
}); }));

View file

@ -1,9 +1,9 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
const ms = require('ms'); const ms = require('ms');
import User, { pack, ILocalUser } from '../../../../models/user'; import User, { pack } from '../../../../models/user';
import Following from '../../../../models/following'; import Following from '../../../../models/following';
import create from '../../../../services/following/create'; import create from '../../../../services/following/create';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -34,10 +34,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const follower = user; const follower = user;
// 自分自身 // 自分自身
@ -78,4 +75,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Send response // Send response
res(await pack(followee._id, user)); res(await pack(followee._id, user));
}); }));

View file

@ -1,9 +1,9 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
const ms = require('ms'); const ms = require('ms');
import User, { pack, ILocalUser } from '../../../../models/user'; import User, { pack } from '../../../../models/user';
import Following from '../../../../models/following'; import Following from '../../../../models/following';
import deleteFollowing from '../../../../services/following/delete'; import deleteFollowing from '../../../../services/following/delete';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -34,10 +34,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const follower = user; const follower = user;
// Check if the followee is yourself // Check if the followee is yourself
@ -74,4 +71,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Send response // Send response
res(await pack(followee._id, user)); res(await pack(followee._id, user));
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import acceptFollowRequest from '../../../../../services/following/requests/accept'; import acceptFollowRequest from '../../../../../services/following/requests/accept';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +21,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch follower // Fetch follower
const follower = await User.findOne({ const follower = await User.findOne({
_id: ps.userId _id: ps.userId
@ -37,4 +34,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
await acceptFollowRequest(user, follower); await acceptFollowRequest(user, follower);
res(); res();
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import cancelFollowRequest from '../../../../../services/following/requests/cancel'; import cancelFollowRequest from '../../../../../services/following/requests/cancel';
import User, { pack, ILocalUser } from '../../../../../models/user'; import User, { pack } from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +21,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch followee // Fetch followee
const followee = await User.findOne({ const followee = await User.findOne({
_id: ps.userId _id: ps.userId
@ -41,4 +38,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
} }
res(await pack(followee._id, user)); res(await pack(followee._id, user));
}); }));

View file

@ -1,6 +1,6 @@
//import $ from 'cafy'; import ID, { transform } from '../../../../../cafy-id'; //import $ from 'cafy'; import ID, { transform } from '../../../../../cafy-id';
import FollowRequest, { pack } from '../../../../../models/follow-request'; import FollowRequest, { pack } from '../../../../../models/follow-request';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -13,11 +13,11 @@ export const meta = {
kind: 'following-read' kind: 'following-read'
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const reqs = await FollowRequest.find({ const reqs = await FollowRequest.find({
followeeId: user._id followeeId: user._id
}); });
// Send response // Send response
res(await Promise.all(reqs.map(req => pack(req)))); res(await Promise.all(reqs.map(req => pack(req))));
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import rejectFollowRequest from '../../../../../services/following/requests/reject'; import rejectFollowRequest from '../../../../../services/following/requests/reject';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +21,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch follower // Fetch follower
const follower = await User.findOne({ const follower = await User.findOne({
_id: ps.userId _id: ps.userId
@ -37,4 +34,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
await rejectFollowRequest(user, follower); await rejectFollowRequest(user, follower);
res(); res();
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Following from '../../../../models/following'; import Following from '../../../../models/following';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +20,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const follower = user; const follower = user;
// Fetch following // Fetch following
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(); res();
// TODO: イベント // TODO: イベント
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Following from '../../../../models/following'; import Following from '../../../../models/following';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +20,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const follower = user; const follower = user;
// Fetch following // Fetch following
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(); res();
// TODO: イベント // TODO: イベント
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import ReversiGame, { pack } from '../../../../../models/games/reversi/game'; import ReversiGame, { pack } from '../../../../../models/games/reversi/game';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
params: { params: {
@ -27,10 +26,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -72,4 +68,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(Promise.all(games.map(async (g) => await pack(g, user, { res(Promise.all(games.map(async (g) => await pack(g, user, {
detail: false detail: false
})))); }))));
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../../misc/cafy-id';
import ReversiGame, { pack } from '../../../../../../models/games/reversi/game'; import ReversiGame, { pack } from '../../../../../../models/games/reversi/game';
import Reversi from '../../../../../../games/reversi/core'; import Reversi from '../../../../../../games/reversi/core';
import { ILocalUser } from '../../../../../../models/user'; import define from '../../../../define';
import getParams from '../../../../get-params';
export const meta = { export const meta = {
params: { params: {
@ -13,10 +12,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const game = await ReversiGame.findOne({ _id: ps.gameId }); const game = await ReversiGame.findOne({ _id: ps.gameId });
if (game == null) { if (game == null) {
@ -39,4 +35,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
board: o.board, board: o.board,
turn: o.turn turn: o.turn
}, packed)); }, packed));
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../../misc/cafy-id';
import ReversiGame, { pack } from '../../../../../../models/games/reversi/game'; import ReversiGame, { pack } from '../../../../../../models/games/reversi/game';
import { ILocalUser } from '../../../../../../models/user';
import getParams from '../../../../get-params';
import { publishReversiGameStream } from '../../../../../../stream'; import { publishReversiGameStream } from '../../../../../../stream';
import define from '../../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -22,10 +21,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const game = await ReversiGame.findOne({ _id: ps.gameId }); const game = await ReversiGame.findOne({ _id: ps.gameId });
if (game == null) { if (game == null) {
@ -58,4 +54,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(); res();
}); }));

View file

@ -1,11 +1,11 @@
import Matching, { pack as packMatching } from '../../../../../models/games/reversi/matching'; import Matching, { pack as packMatching } from '../../../../../models/games/reversi/matching';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: true requireCredential: true
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// Find session // Find session
const invitations = await Matching.find({ const invitations = await Matching.find({
childId: user._id childId: user._id
@ -17,4 +17,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Reponse // Reponse
res(Promise.all(invitations.map(async (i) => await packMatching(i, user)))); res(Promise.all(invitations.map(async (i) => await packMatching(i, user))));
}); }));

View file

@ -1,10 +1,10 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import Matching, { pack as packMatching } from '../../../../../models/games/reversi/matching'; import Matching, { pack as packMatching } from '../../../../../models/games/reversi/matching';
import ReversiGame, { pack as packGame } from '../../../../../models/games/reversi/game'; import ReversiGame, { pack as packGame } from '../../../../../models/games/reversi/game';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import { publishMainStream, publishReversiStream } from '../../../../../stream'; import { publishMainStream, publishReversiStream } from '../../../../../stream';
import { eighteight } from '../../../../../games/reversi/maps'; import { eighteight } from '../../../../../games/reversi/maps';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -17,10 +17,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Myself // Myself
if (ps.userId.equals(user._id)) { if (ps.userId.equals(user._id)) {
return rej('invalid userId param'); return rej('invalid userId param');
@ -103,4 +100,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
publishMainStream(child._id, 'reversiInvited', packed); publishMainStream(child._id, 'reversiInvited', packed);
} }
}); }));

View file

@ -1,14 +1,14 @@
import Matching from '../../../../../../models/games/reversi/matching'; import Matching from '../../../../../../models/games/reversi/matching';
import { ILocalUser } from '../../../../../../models/user'; import define from '../../../../define';
export const meta = { export const meta = {
requireCredential: true requireCredential: true
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
await Matching.remove({ await Matching.remove({
parentId: user._id parentId: user._id
}); });
res(); res();
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import Hashtag from '../../../../models/hashtag'; import Hashtag from '../../../../models/hashtag';
import getParams from '../../get-params'; import define from '../../define';
const escapeRegexp = require('escape-regexp'); const escapeRegexp = require('escape-regexp');
export const meta = { export const meta = {
@ -36,10 +36,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const hashtags = await Hashtag const hashtags = await Hashtag
.find({ .find({
tag: new RegExp('^' + escapeRegexp(ps.query.toLowerCase())) tag: new RegExp('^' + escapeRegexp(ps.query.toLowerCase()))
@ -52,4 +49,4 @@ export default (params: any) => new Promise(async (res, rej) => {
}); });
res(hashtags.map(tag => tag.tag)); res(hashtags.map(tag => tag.tag));
}); }));

View file

@ -1,6 +1,7 @@
import Note from '../../../../models/note'; import Note from '../../../../models/note';
import { erase } from '../../../../prelude/array'; import { erase } from '../../../../prelude/array';
import Meta from '../../../../models/meta'; import Meta from '../../../../models/meta';
import define from '../../define';
/* /*
a分間のユニーク投稿数が今からa分前b分前の間のユニーク投稿数のn倍以上5 a分間のユニーク投稿数が今からa分前b分前の間のユニーク投稿数のn倍以上5
@ -14,10 +15,11 @@ const requiredUsers = 3; // 最低何人がそのタグを投稿している必
const max = 5; const max = 5;
/** export const meta = {
* Get trends of hashtags requireCredential: false,
*/ };
export default () => new Promise(async (res, rej) => {
export default define(meta, () => new Promise(async (res, rej) => {
const meta = await Meta.findOne({}); const meta = await Meta.findOne({});
const hidedTags = meta ? (meta.hidedTags || []).map(t => t.toLowerCase()) : []; const hidedTags = meta ? (meta.hidedTags || []).map(t => t.toLowerCase()) : [];
@ -143,4 +145,4 @@ export default () => new Promise(async (res, rej) => {
})); }));
res(stats); res(stats);
}); }));

View file

@ -1,5 +1,5 @@
import User, { pack, ILocalUser } from '../../../models/user'; import User, { pack } from '../../../models/user';
import { IApp } from '../../../models/app'; import define from '../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -18,7 +18,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
const isSecure = user != null && app == null; const isSecure = user != null && app == null;
// Serialize // Serialize
@ -34,4 +34,4 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
lastUsedAt: new Date() lastUsedAt: new Date()
} }
}); });
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import * as speakeasy from 'speakeasy'; import * as speakeasy from 'speakeasy';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -15,10 +15,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const _token = ps.token.replace(/\s/g, ''); const _token = ps.token.replace(/\s/g, '');
if (user.twoFactorTempSecret == null) { if (user.twoFactorTempSecret == null) {
@ -43,4 +40,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
}); });
res(); res();
}); }));

View file

@ -2,9 +2,9 @@ import $ from 'cafy';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import * as speakeasy from 'speakeasy'; import * as speakeasy from 'speakeasy';
import * as QRCode from 'qrcode'; import * as QRCode from 'qrcode';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import config from '../../../../../config'; import config from '../../../../../config';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -18,10 +18,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Compare password // Compare password
const same = await bcrypt.compare(ps.password, user.password); const same = await bcrypt.compare(ps.password, user.password);
@ -54,4 +51,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
issuer: config.host issuer: config.host
}); });
}); });
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -15,10 +15,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Compare password // Compare password
const same = await bcrypt.compare(ps.password, user.password); const same = await bcrypt.compare(ps.password, user.password);
@ -34,4 +31,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
}); });
res(); res();
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import AccessToken from '../../../../models/access-token'; import AccessToken from '../../../../models/access-token';
import { pack } from '../../../../models/app'; import { pack } from '../../../../models/app';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -27,10 +26,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get tokens // Get tokens
const tokens = await AccessToken const tokens = await AccessToken
.find({ .find({
@ -46,4 +42,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await Promise.all(tokens.map(token => pack(token.appId, user, { res(await Promise.all(tokens.map(token => pack(token.appId, user, {
detail: true detail: true
})))); }))));
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -19,10 +19,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Compare password // Compare password
const same = await bcrypt.compare(ps.currentPassword, user.password); const same = await bcrypt.compare(ps.currentPassword, user.password);
@ -41,4 +38,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
}); });
res(); res();
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Favorite, { packMany } from '../../../../models/favorite'; import Favorite, { packMany } from '../../../../models/favorite';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -31,10 +30,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -67,4 +63,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(await packMany(favorites, user)); res(await packMany(favorites, user));
}); }));

View file

@ -4,8 +4,7 @@ import Mute from '../../../../models/mute';
import { packMany } from '../../../../models/notification'; import { packMany } from '../../../../models/notification';
import { getFriendIds } from '../../common/get-friends'; import { getFriendIds } from '../../common/get-friends';
import read from '../../common/read-notification'; import read from '../../common/read-notification';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -45,10 +44,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -105,4 +101,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
if (notifications.length > 0 && ps.markAsRead) { if (notifications.length > 0 && ps.markAsRead) {
read(user._id, notifications); read(user._id, notifications);
} }
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import { ILocalUser } from '../../../../models/user';
import { pack } from '../../../../models/user'; import { pack } from '../../../../models/user';
import { addPinned } from '../../../../services/i/pin'; import { addPinned } from '../../../../services/i/pin';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -27,10 +26,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Processing // Processing
try { try {
await addPinned(user, ps.noteId); await addPinned(user, ps.noteId);
@ -45,4 +41,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
// Send response // Send response
res(iObj); res(iObj);
}); }));

View file

@ -1,6 +1,7 @@
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream'; import { publishMainStream } from '../../../../stream';
import NoteUnread from '../../../../models/note-unread'; import NoteUnread from '../../../../models/note-unread';
import define from '../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -16,7 +17,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
// Remove documents // Remove documents
await NoteUnread.remove({ await NoteUnread.remove({
userId: user._id userId: user._id
@ -34,4 +35,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
publishMainStream(user._id, 'readAllUnreadSpecifiedNotes'); publishMainStream(user._id, 'readAllUnreadSpecifiedNotes');
res(); res();
}); }));

View file

@ -1,9 +1,9 @@
import $ from 'cafy'; import $ from 'cafy';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream'; import { publishMainStream } from '../../../../stream';
import generateUserToken from '../../common/generate-native-user-token'; import generateUserToken from '../../common/generate-native-user-token';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -17,10 +17,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Compare password // Compare password
const same = await bcrypt.compare(ps.password, user.password); const same = await bcrypt.compare(ps.password, user.password);
@ -41,4 +38,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
// Publish event // Publish event
publishMainStream(user._id, 'myTokenRegenerated'); publishMainStream(user._id, 'myTokenRegenerated');
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Signin, { pack } from '../../../../models/signin'; import Signin, { pack } from '../../../../models/signin';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -26,10 +25,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -62,4 +58,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Serialize // Serialize
res(await Promise.all(history.map(record => pack(record)))); res(await Promise.all(history.map(record => pack(record))));
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import { ILocalUser } from '../../../../models/user';
import { pack } from '../../../../models/user'; import { pack } from '../../../../models/user';
import { removePinned } from '../../../../services/i/pin'; import { removePinned } from '../../../../services/i/pin';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -27,10 +26,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Processing // Processing
try { try {
await removePinned(user, ps.noteId); await removePinned(user, ps.noteId);
@ -45,4 +41,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
// Send response // Send response
res(iObj); res(iObj);
}); }));

View file

@ -5,7 +5,7 @@ import DriveFile from '../../../../models/drive-file';
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all'; import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
import { IApp } from '../../../../models/app'; import { IApp } from '../../../../models/app';
import { publishToFollowers } from '../../../../services/i/update'; import { publishToFollowers } from '../../../../services/i/update';
import getParams from '../../get-params'; import define from '../../define';
import getDriveFileUrl from '../../../../misc/get-drive-file-url'; import getDriveFileUrl from '../../../../misc/get-drive-file-url';
export const meta = { export const meta = {
@ -115,10 +115,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const isSecure = user != null && app == null; const isSecure = user != null && app == null;
const updates = {} as any; const updates = {} as any;
@ -209,4 +206,4 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
// フォロワーにUpdateを配信 // フォロワーにUpdateを配信
publishToFollowers(user._id); publishToFollowers(user._id);
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream'; import { publishMainStream } from '../../../../stream';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -19,10 +19,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const x: any = {}; const x: any = {};
x[`clientSettings.${name}`] = ps.value; x[`clientSettings.${name}`] = ps.value;
@ -37,4 +34,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
key: name, key: name,
value: ps.value value: ps.value
}); });
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream'; import { publishMainStream } from '../../../../stream';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -20,10 +20,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
await User.update(user._id, { await User.update(user._id, {
$set: { $set: {
'clientSettings.home': ps.home 'clientSettings.home': ps.home
@ -33,4 +30,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
res(); res();
publishMainStream(user._id, 'homeUpdated', ps.home); publishMainStream(user._id, 'homeUpdated', ps.home);
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream'; import { publishMainStream } from '../../../../stream';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -19,10 +19,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
await User.update(user._id, { await User.update(user._id, {
$set: { $set: {
'clientSettings.mobileHome': ps.home 'clientSettings.mobileHome': ps.home
@ -32,4 +29,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
res(); res();
publishMainStream(user._id, 'mobileHomeUpdated', ps.home); publishMainStream(user._id, 'mobileHomeUpdated', ps.home);
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { publishMainStream } from '../../../../stream'; import { publishMainStream } from '../../../../stream';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -19,10 +19,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
if (ps.id == null && ps.data == null) return rej('you need to set id and data params if home param unset'); if (ps.id == null && ps.data == null) return rej('you need to set id and data params if home param unset');
let widget; let widget;
@ -88,4 +85,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
} else { } else {
rej('widget not found'); rej('widget not found');
} }
}); }));

View file

@ -2,8 +2,7 @@ import $ from 'cafy';
import History from '../../../../models/messaging-history'; import History from '../../../../models/messaging-history';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import { pack } from '../../../../models/messaging-message'; import { pack } from '../../../../models/messaging-message';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -23,10 +22,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const mute = await Mute.find({ const mute = await Mute.find({
muterId: user._id, muterId: user._id,
deletedAt: { $exists: false } deletedAt: { $exists: false }
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(await Promise.all(history.map(h => pack(h.messageId, user)))); res(await Promise.all(history.map(h => pack(h.messageId, user))));
}); }));

View file

@ -1,9 +1,9 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Message from '../../../../models/messaging-message'; import Message from '../../../../models/messaging-message';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import { pack } from '../../../../models/messaging-message'; import { pack } from '../../../../models/messaging-message';
import read from '../../common/read-messaging-message'; import read from '../../common/read-messaging-message';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -43,10 +43,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -108,4 +105,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
if (ps.markAsRead) { if (ps.markAsRead) {
read(user._id, recipient._id, messages); read(user._id, recipient._id, messages);
} }
}); }));

View file

@ -2,14 +2,14 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id
import Message from '../../../../../models/messaging-message'; import Message from '../../../../../models/messaging-message';
import { isValidText } from '../../../../../models/messaging-message'; import { isValidText } from '../../../../../models/messaging-message';
import History from '../../../../../models/messaging-history'; import History from '../../../../../models/messaging-history';
import User, { ILocalUser } from '../../../../../models/user'; import User from '../../../../../models/user';
import Mute from '../../../../../models/mute'; import Mute from '../../../../../models/mute';
import DriveFile from '../../../../../models/drive-file'; import DriveFile from '../../../../../models/drive-file';
import { pack } from '../../../../../models/messaging-message'; import { pack } from '../../../../../models/messaging-message';
import { publishMainStream } from '../../../../../stream'; import { publishMainStream } from '../../../../../stream';
import { publishMessagingStream, publishMessagingIndexStream } from '../../../../../stream'; import { publishMessagingStream, publishMessagingIndexStream } from '../../../../../stream';
import pushSw from '../../../../../push-sw'; import pushSw from '../../../../../push-sw';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -38,10 +38,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Myself // Myself
if (ps.userId.equals(user._id)) { if (ps.userId.equals(user._id)) {
return rej('cannot send message to myself'); return rej('cannot send message to myself');
@ -155,4 +152,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}, { }, {
upsert: true upsert: true
}); });
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import Message from '../../../../../models/messaging-message'; import Message from '../../../../../models/messaging-message';
import { ILocalUser } from '../../../../../models/user';
import read from '../../../common/read-messaging-message'; import read from '../../../common/read-messaging-message';
import getParams from '../../../get-params'; import define from '../../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -26,10 +25,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const message = await Message.findOne({ const message = await Message.findOne({
_id: ps.messageId, _id: ps.messageId,
recipientId: user._id recipientId: user._id
@ -42,4 +38,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
read(user._id, message.userId, message); read(user._id, message.userId, message);
res(); res();
}); }));

View file

@ -2,9 +2,8 @@ import $ from 'cafy';
import * as os from 'os'; import * as os from 'os';
import config from '../../../config'; import config from '../../../config';
import Meta from '../../../models/meta'; import Meta from '../../../models/meta';
import { ILocalUser } from '../../../models/user';
import Emoji from '../../../models/emoji'; import Emoji from '../../../models/emoji';
import getParams from '../get-params'; import define from '../define';
const pkg = require('../../../../package.json'); const pkg = require('../../../../package.json');
const client = require('../../../../built/client/meta.json'); const client = require('../../../../built/client/meta.json');
@ -27,10 +26,7 @@ export const meta = {
}, },
}; };
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const met: any = (await Meta.findOne()) || {}; const met: any = (await Meta.findOne()) || {};
const emojis = await Emoji.find({ host: null }); const emojis = await Emoji.find({ host: null });
@ -76,4 +72,4 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
userRecommendation: config.user_recommendation ? config.user_recommendation : {} userRecommendation: config.user_recommendation ? config.user_recommendation : {}
} : undefined } : undefined
}); });
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +21,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const muter = user; const muter = user;
// 自分自身 // 自分自身
@ -64,4 +61,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(); res();
}); }));

View file

@ -1,7 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
desc: { desc: {
@ -21,10 +21,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const muter = user; const muter = user;
// Check if the mutee is yourself // Check if the mutee is yourself
@ -62,4 +59,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
}); });
res(); res();
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Mute, { packMany } from '../../../../models/mute'; import Mute, { packMany } from '../../../../models/mute';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -31,10 +30,7 @@ export const meta = {
} }
}; };
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, me) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -66,4 +62,4 @@ export default (params: any, me: ILocalUser) => new Promise(async (res, rej) =>
}); });
res(await packMany(mutes, me)); res(await packMany(mutes, me));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import $ from 'cafy';
import App, { pack } from '../../../../models/app'; import App, { pack } from '../../../../models/app';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -24,10 +23,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
const query = { const query = {
userId: user._id userId: user._id
}; };
@ -46,4 +42,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await Promise.all(apps.map(app => pack(app, user, { res(await Promise.all(apps.map(app => pack(app, user, {
detail: true detail: true
})))); }))));
}); }));

View file

@ -1,6 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../misc/cafy-id';
import Note, { packMany } from '../../../models/note'; import Note, { packMany } from '../../../models/note';
import getParams from '../get-params'; import define from '../define';
export const meta = { export const meta = {
desc: { desc: {
@ -67,10 +67,7 @@ export const meta = {
} }
}; };
export default (params: any) => new Promise(async (res, rej) => { export default define(meta, (ps) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -130,4 +127,4 @@ export default (params: any) => new Promise(async (res, rej) => {
// Serialize // Serialize
res(await packMany(notes)); res(await packMany(notes));
}); }));

View file

@ -1,7 +1,6 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Note, { packMany, INote } from '../../../../models/note'; import Note, { packMany, INote } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -29,10 +28,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Lookup note // Lookup note
const note = await Note.findOne({ const note = await Note.findOne({
_id: ps.noteId _id: ps.noteId
@ -67,4 +63,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
} }
res(await packMany(conversation, user)); res(await packMany(conversation, user));
}); }));

View file

@ -1,11 +1,10 @@
import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id';
const ms = require('ms'); const ms = require('ms');
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note'; import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
import User, { ILocalUser, IUser } from '../../../../models/user'; import User, { IUser } from '../../../../models/user';
import DriveFile, { IDriveFile } from '../../../../models/drive-file'; import DriveFile, { IDriveFile } from '../../../../models/drive-file';
import create from '../../../../services/note/create'; import create from '../../../../services/note/create';
import { IApp } from '../../../../models/app'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -139,10 +138,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => { export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
let visibleUsers: IUser[] = []; let visibleUsers: IUser[] = [];
if (ps.visibleUserIds) { if (ps.visibleUserIds) {
visibleUsers = await Promise.all(ps.visibleUserIds.map(id => User.findOne({ visibleUsers = await Promise.all(ps.visibleUserIds.map(id => User.findOne({
@ -229,4 +225,4 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
res({ res({
createdNote: noteObj createdNote: noteObj
}); });
}); }));

View file

@ -1,8 +1,8 @@
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Note from '../../../../models/note'; import Note from '../../../../models/note';
import deleteNote from '../../../../services/note/delete'; import deleteNote from '../../../../services/note/delete';
import User, { ILocalUser } from '../../../../models/user'; import User from '../../../../models/user';
import getParams from '../../get-params'; import define from '../../define';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -28,10 +28,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Fetch note // Fetch note
const note = await Note.findOne({ const note = await Note.findOne({
_id: ps.noteId _id: ps.noteId
@ -48,4 +45,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
await deleteNote(await User.findOne({ _id: note.userId }), note); await deleteNote(await User.findOne({ _id: note.userId }), note);
res(); res();
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import Favorite from '../../../../../models/favorite'; import Favorite from '../../../../../models/favorite';
import Note from '../../../../../models/note'; import Note from '../../../../../models/note';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -28,10 +27,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get favoritee // Get favoritee
const note = await Note.findOne({ const note = await Note.findOne({
_id: ps.noteId _id: ps.noteId
@ -60,4 +56,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Send response // Send response
res(); res();
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id'; import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import Favorite from '../../../../../models/favorite'; import Favorite from '../../../../../models/favorite';
import Note from '../../../../../models/note'; import Note from '../../../../../models/note';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
stability: 'stable', stability: 'stable',
@ -28,10 +27,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get favoritee // Get favoritee
const note = await Note.findOne({ const note = await Note.findOne({
_id: ps.noteId _id: ps.noteId
@ -58,4 +54,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
// Send response // Send response
res(); res();
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import Note from '../../../../models/note'; import Note from '../../../../models/note';
import { packMany } from '../../../../models/note'; import { packMany } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -23,10 +22,7 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
const day = 1000 * 60 * 60 * 24; const day = 1000 * 60 * 60 * 24;
const notes = await Note const notes = await Note
@ -46,5 +42,5 @@ export default async (params: any, user: ILocalUser) => {
} }
}); });
return await packMany(notes, user); res(await packMany(notes, user));
}; }));

View file

@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Note from '../../../../models/note'; import Note from '../../../../models/note';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import { packMany } from '../../../../models/note'; import { packMany } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
import { countIf } from '../../../../prelude/array'; import { countIf } from '../../../../prelude/array';
export const meta = { export const meta = {
@ -51,13 +50,10 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified // Check if only one of sinceId, untilId, sinceDate, untilDate specified
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) { if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified'; return rej('only one of sinceId, untilId, sinceDate, untilDate can be specified');
} }
// ミュートしているユーザーを取得 // ミュートしているユーザーを取得
@ -120,13 +116,11 @@ export default async (params: any, user: ILocalUser) => {
} }
//#endregion //#endregion
// Issue query
const timeline = await Note const timeline = await Note
.find(query, { .find(query, {
limit: ps.limit, limit: ps.limit,
sort: sort sort: sort
}); });
// Serialize res(await packMany(timeline, user));
return await packMany(timeline, user); }));
};

View file

@ -3,8 +3,7 @@ import Note from '../../../../models/note';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import { getFriends } from '../../common/get-friends'; import { getFriends } from '../../common/get-friends';
import { packMany } from '../../../../models/note'; import { packMany } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
import { countIf } from '../../../../prelude/array'; import { countIf } from '../../../../prelude/array';
export const meta = { export const meta = {
@ -91,13 +90,10 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified // Check if only one of sinceId, untilId, sinceDate, untilDate specified
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) { if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified'; return rej('only one of sinceId, untilId, sinceDate, untilDate can be specified');
} }
const [followings, mutedUserIds] = await Promise.all([ const [followings, mutedUserIds] = await Promise.all([
@ -246,13 +242,11 @@ export default async (params: any, user: ILocalUser) => {
} }
//#endregion //#endregion
// Issue query
const timeline = await Note const timeline = await Note
.find(query, { .find(query, {
limit: ps.limit, limit: ps.limit,
sort: sort sort: sort
}); });
// Serialize res(await packMany(timeline, user));
return await packMany(timeline, user); }));
};

View file

@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Note from '../../../../models/note'; import Note from '../../../../models/note';
import Mute from '../../../../models/mute'; import Mute from '../../../../models/mute';
import { packMany } from '../../../../models/note'; import { packMany } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
import { countIf } from '../../../../prelude/array'; import { countIf } from '../../../../prelude/array';
export const meta = { export const meta = {
@ -66,13 +65,10 @@ export const meta = {
} }
}; };
export default async (params: any, user: ILocalUser) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified // Check if only one of sinceId, untilId, sinceDate, untilDate specified
if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) { if (countIf(x => x != null, [ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate]) > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified'; return rej('only one of sinceId, untilId, sinceDate, untilDate can be specified');
} }
// ミュートしているユーザーを取得 // ミュートしているユーザーを取得
@ -150,13 +146,11 @@ export default async (params: any, user: ILocalUser) => {
} }
//#endregion //#endregion
// Issue query
const timeline = await Note const timeline = await Note
.find(query, { .find(query, {
limit: ps.limit, limit: ps.limit,
sort: sort sort: sort
}); });
// Serialize res(await packMany(timeline, user));
return await packMany(timeline, user); }));
};

View file

@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
import Note from '../../../../models/note'; import Note from '../../../../models/note';
import { getFriendIds } from '../../common/get-friends'; import { getFriendIds } from '../../common/get-friends';
import { packMany } from '../../../../models/note'; import { packMany } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user'; import define from '../../define';
import getParams from '../../get-params';
import read from '../../../../services/note/read'; import read from '../../../../services/note/read';
export const meta = { export const meta = {
@ -41,10 +40,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Check if both of sinceId and untilId is specified // Check if both of sinceId and untilId is specified
if (ps.sinceId && ps.untilId) { if (ps.sinceId && ps.untilId) {
return rej('cannot set sinceId and untilId'); return rej('cannot set sinceId and untilId');
@ -96,4 +92,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await packMany(mentions, user)); res(await packMany(mentions, user));
mentions.forEach(note => read(user._id, note._id)); mentions.forEach(note => read(user._id, note._id));
}); }));

View file

@ -1,8 +1,7 @@
import $ from 'cafy'; import $ from 'cafy';
import Vote from '../../../../../models/poll-vote'; import Vote from '../../../../../models/poll-vote';
import Note, { pack } from '../../../../../models/note'; import Note, { pack } from '../../../../../models/note';
import { ILocalUser } from '../../../../../models/user'; import define from '../../../define';
import getParams from '../../../get-params';
export const meta = { export const meta = {
desc: { desc: {
@ -25,10 +24,7 @@ export const meta = {
} }
}; };
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => { export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const [ps, psErr] = getParams(meta, params);
if (psErr) return rej(psErr);
// Get votes // Get votes
const votes = await Vote.find({ const votes = await Vote.find({
userId: user._id userId: user._id
@ -64,4 +60,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
res(await Promise.all(notes.map(note => pack(note, user, { res(await Promise.all(notes.map(note => pack(note, user, {
detail: true detail: true
})))); }))));
}); }));

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