mirror of
https://github.com/kokonect-link/cherrypick
synced 2024-11-01 15:45:58 +09:00
Refactor
This commit is contained in:
parent
ddc3c5ba68
commit
174f8022eb
@ -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;
|
||||
|
||||
// API invoking
|
||||
try {
|
||||
const before = performance.now();
|
||||
res = await exec(data, user, app);
|
||||
res = await ep.exec(data, user, app, file);
|
||||
const after = performance.now();
|
||||
|
||||
const time = after - before;
|
||||
|
51
src/server/api/define.ts
Normal file
51
src/server/api/define.ts
Normal 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];
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import rndstr from 'rndstr';
|
||||
import RegistrationTicket from '../../../../models/registration-tickets';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -12,7 +13,7 @@ export const meta = {
|
||||
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' });
|
||||
|
||||
await RegistrationTicket.insert({
|
||||
@ -23,4 +24,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
res({
|
||||
code: code
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import User from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
@ -24,10 +24,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const user = await User.findOne({
|
||||
_id: ps.userId
|
||||
});
|
||||
@ -49,4 +46,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import User from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
@ -24,10 +24,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const user = await User.findOne({
|
||||
_id: ps.userId
|
||||
});
|
||||
@ -45,4 +42,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import User from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
@ -24,10 +24,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const user = await User.findOne({
|
||||
_id: ps.userId
|
||||
});
|
||||
@ -45,4 +42,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import Meta from '../../../../models/meta';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -55,10 +55,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const set = {} as any;
|
||||
|
||||
if (ps.broadcasts) {
|
||||
@ -90,4 +87,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
}, { upsert: true });
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import User from '../../../../models/user';
|
||||
|
||||
export const meta = {
|
||||
@ -24,10 +24,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const user = await User.findOne({
|
||||
_id: ps.userId
|
||||
});
|
||||
@ -45,4 +42,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import config from '../../../../config';
|
||||
import * as mongo from 'mongodb';
|
||||
import User, { pack as packUser, IUser } from '../../../../models/user';
|
||||
@ -25,15 +25,12 @@ export const meta = {
|
||||
},
|
||||
};
|
||||
|
||||
export default async (params: any) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
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を解決する
|
||||
|
@ -1,8 +1,7 @@
|
||||
import rndstr from 'rndstr';
|
||||
import $ from 'cafy';
|
||||
import App, { pack } from '../../../../models/app';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
@ -28,10 +27,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Generate secret
|
||||
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,
|
||||
includeSecret: true
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import App, { pack, IApp } from '../../../../models/app';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import App, { pack } from '../../../../models/app';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
params: {
|
||||
@ -12,10 +11,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
||||
const isSecure = user != null && app == null;
|
||||
|
||||
// Lookup app
|
||||
@ -30,4 +26,4 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
|
||||
detail: true,
|
||||
includeSecret: isSecure && ap.userId.equals(user._id)
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
@ -4,8 +4,7 @@ import $ from 'cafy';
|
||||
import App from '../../../../models/app';
|
||||
import AuthSess from '../../../../models/auth-session';
|
||||
import AccessToken from '../../../../models/access-token';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -19,10 +18,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch token
|
||||
const session = await AuthSess
|
||||
.findOne({ token: ps.token });
|
||||
@ -70,4 +66,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Response
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -3,7 +3,7 @@ import $ from 'cafy';
|
||||
import App from '../../../../../models/app';
|
||||
import AuthSess from '../../../../../models/auth-session';
|
||||
import config from '../../../../../config';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
@ -15,10 +15,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
// Lookup app
|
||||
const app = await App.findOne({
|
||||
secret: ps.appSecret
|
||||
@ -43,4 +40,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
token: doc.token,
|
||||
url: `${config.auth_url}/${doc.token}`
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import AuthSess, { pack } from '../../../../../models/auth-session';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
@ -13,10 +12,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Lookup session
|
||||
const session = await AuthSess.findOne({
|
||||
token: ps.token
|
||||
@ -28,4 +24,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Response
|
||||
res(await pack(session, user));
|
||||
});
|
||||
}));
|
||||
|
@ -3,7 +3,7 @@ import App from '../../../../../models/app';
|
||||
import AuthSess from '../../../../../models/auth-session';
|
||||
import AccessToken from '../../../../../models/access-token';
|
||||
import { pack } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
@ -19,10 +19,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
// Lookup app
|
||||
const app = await App.findOne({
|
||||
secret: ps.appSecret
|
||||
@ -71,4 +68,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
detail: true
|
||||
})
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,9 +1,9 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
const ms = require('ms');
|
||||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import Blocking from '../../../../models/blocking';
|
||||
import create from '../../../../services/blocking/create';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -34,10 +34,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const blocker = user;
|
||||
|
||||
// 自分自身
|
||||
@ -76,4 +73,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
res(await pack(blockee._id, user, {
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
@ -1,9 +1,9 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
const ms = require('ms');
|
||||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import Blocking from '../../../../models/blocking';
|
||||
import deleteBlocking from '../../../../services/blocking/delete';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -34,10 +34,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const blocker = user;
|
||||
|
||||
// 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, {
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Blocking, { packMany } from '../../../../models/blocking';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -31,10 +30,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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));
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import driveChart from '../../../../chart/drive';
|
||||
|
||||
export const meta = {
|
||||
@ -25,11 +25,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await driveChart.getChart(ps.span as any, ps.limit);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import federationChart from '../../../../chart/federation';
|
||||
|
||||
export const meta = {
|
||||
@ -25,11 +25,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await federationChart.getChart(ps.span as any, ps.limit);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import hashtagChart from '../../../../chart/hashtag';
|
||||
|
||||
export const meta = {
|
||||
@ -32,11 +32,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await hashtagChart.getChart(ps.span as any, ps.limit, ps.tag);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import networkChart from '../../../../chart/network';
|
||||
|
||||
export const meta = {
|
||||
@ -25,11 +25,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await networkChart.getChart(ps.span as any, ps.limit);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import notesChart from '../../../../chart/notes';
|
||||
|
||||
export const meta = {
|
||||
@ -25,11 +25,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await notesChart.getChart(ps.span as any, ps.limit);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import perUserDriveChart from '../../../../../chart/per-user-drive';
|
||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
|
||||
@ -35,11 +35,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await perUserDriveChart.getChart(ps.span as any, ps.limit, ps.userId);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import perUserFollowingChart from '../../../../../chart/per-user-following';
|
||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
|
||||
@ -35,11 +35,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await perUserFollowingChart.getChart(ps.span as any, ps.limit, ps.userId);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import perUserNotesChart from '../../../../../chart/per-user-notes';
|
||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
|
||||
@ -35,11 +35,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await perUserNotesChart.getChart(ps.span as any, ps.limit, ps.userId);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import perUserReactionsChart from '../../../../../chart/per-user-reactions';
|
||||
import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
|
||||
@ -35,11 +35,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await perUserReactionsChart.getChart(ps.span as any, ps.limit, ps.userId);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import $ from 'cafy';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import usersChart from '../../../../chart/users';
|
||||
|
||||
export const meta = {
|
||||
@ -25,11 +25,8 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const stats = await usersChart.getChart(ps.span as any, ps.limit);
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import DriveFile from '../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../models/user';
|
||||
import config from '../../../config';
|
||||
import define from '../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -13,7 +13,7 @@ export const meta = {
|
||||
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
|
||||
const usage = await DriveFile
|
||||
.aggregate([{
|
||||
@ -42,4 +42,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
capacity: 1024 * 1024 * config.localDriveCapacityMb,
|
||||
usage: usage
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import DriveFile, { packMany } from '../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -41,13 +40,10 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.untilId) {
|
||||
throw 'cannot set sinceId and untilId';
|
||||
return rej('cannot set sinceId and untilId');
|
||||
}
|
||||
|
||||
const sort = {
|
||||
@ -81,5 +77,5 @@ export default async (params: any, user: ILocalUser) => {
|
||||
sort: sort
|
||||
});
|
||||
|
||||
return await packMany(files);
|
||||
};
|
||||
res(await packMany(files));
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFile from '../../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import { packMany } from '../../../../../models/note';
|
||||
|
||||
export const meta = {
|
||||
@ -28,10 +27,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
res(await packMany(file.metadata.attachedNoteIds || [], user, {
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -23,10 +22,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const file = await DriveFile.findOne({
|
||||
md5: ps.md5,
|
||||
'metadata.userId': user._id,
|
||||
@ -38,4 +34,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
} else {
|
||||
res({ file: await pack(file) });
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
@ -1,10 +1,8 @@
|
||||
import * as fs from 'fs';
|
||||
const ms = require('ms');
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import { validateFileName, pack } from '../../../../../models/drive-file';
|
||||
import create from '../../../../../services/drive/add-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -52,11 +50,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (file: any, params: any, user: ILocalUser): Promise<any> => {
|
||||
if (file == null) {
|
||||
throw 'file is required';
|
||||
}
|
||||
|
||||
export default define(meta, (ps, user, app, file, cleanup) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
let name = file.originalname;
|
||||
if (name !== undefined && name !== null) {
|
||||
@ -66,35 +60,24 @@ export default async (file: any, params: any, user: ILocalUser): Promise<any> =>
|
||||
} else if (name === 'blob') {
|
||||
name = null;
|
||||
} else if (!validateFileName(name)) {
|
||||
throw 'invalid name';
|
||||
return rej('invalid name');
|
||||
}
|
||||
} else {
|
||||
name = null;
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
fs.unlink(file.path, () => {});
|
||||
}
|
||||
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) {
|
||||
cleanup();
|
||||
throw psErr;
|
||||
}
|
||||
|
||||
try {
|
||||
// Create file
|
||||
const driveFile = await create(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive);
|
||||
|
||||
cleanup();
|
||||
|
||||
// Serialize
|
||||
return pack(driveFile);
|
||||
res(pack(driveFile));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
||||
cleanup();
|
||||
|
||||
throw e;
|
||||
rej(e);
|
||||
}
|
||||
};
|
||||
}));
|
||||
|
@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id
|
||||
import DriveFile from '../../../../../models/drive-file';
|
||||
import del from '../../../../../services/drive/delete-file';
|
||||
import { publishDriveStream } from '../../../../../stream';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -29,10 +28,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
@ -51,4 +47,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
publishDriveStream(user._id, 'fileDeleted', file._id);
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -24,10 +23,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const files = await DriveFile
|
||||
.find({
|
||||
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))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -27,10 +26,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
@ -49,4 +45,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
});
|
||||
|
||||
res(_file);
|
||||
});
|
||||
}));
|
||||
|
@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id
|
||||
import DriveFolder from '../../../../../models/drive-folder';
|
||||
import DriveFile, { validateFileName, pack } from '../../../../../models/drive-file';
|
||||
import { publishDriveStream } from '../../../../../stream';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
export const meta = {
|
||||
@ -54,10 +53,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
@ -122,4 +118,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Publish fileUpdated event
|
||||
publishDriveStream(user._id, 'fileUpdated', fileObj);
|
||||
});
|
||||
}));
|
||||
|
@ -3,7 +3,7 @@ const ms = require('ms');
|
||||
import { pack } from '../../../../../models/drive-file';
|
||||
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -33,9 +33,6 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser): Promise<any> => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
return pack(await uploadFromUrl(ps.url, user, ps.folderId));
|
||||
};
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
res(pack(await uploadFromUrl(ps.url, user, ps.folderId)));
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import DriveFolder, { pack } from '../../../../models/drive-folder';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -37,10 +36,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder';
|
||||
import { publishDriveStream } from '../../../../../stream';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -37,10 +36,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// If the parent folder is specified
|
||||
let parent = null;
|
||||
if (ps.parentId) {
|
||||
@ -72,4 +68,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Publish folderCreated event
|
||||
publishDriveStream(user._id, 'folderCreated', folderObj);
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFolder from '../../../../../models/drive-folder';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
import { publishDriveStream } from '../../../../../stream';
|
||||
import DriveFile from '../../../../../models/drive-file';
|
||||
|
||||
@ -29,10 +28,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get folder
|
||||
const folder = await DriveFolder
|
||||
.findOne({
|
||||
@ -59,4 +55,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
publishDriveStream(user._id, 'folderDeleted', folder._id);
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFolder, { pack } from '../../../../../models/drive-folder';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -24,10 +23,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const folders = await DriveFolder
|
||||
.find({
|
||||
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))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFolder, { pack } from '../../../../../models/drive-folder';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -27,10 +26,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get folder
|
||||
const folder = await DriveFolder
|
||||
.findOne({
|
||||
@ -46,4 +42,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
res(await pack(folder, {
|
||||
detail: true
|
||||
}));
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder';
|
||||
import { publishDriveStream } from '../../../../../stream';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -45,10 +44,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch folder
|
||||
const folder = await DriveFolder
|
||||
.findOne({
|
||||
@ -122,4 +118,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Publish folderUpdated event
|
||||
publishDriveStream(user._id, 'folderUpdated', folderObj);
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import DriveFile, { packMany } from '../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -30,10 +29,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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));
|
||||
});
|
||||
}));
|
||||
|
@ -1,9 +1,9 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
const ms = require('ms');
|
||||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import create from '../../../../services/following/create';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -34,10 +34,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// 自分自身
|
||||
@ -78,4 +75,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Send response
|
||||
res(await pack(followee._id, user));
|
||||
});
|
||||
}));
|
||||
|
@ -1,9 +1,9 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
const ms = require('ms');
|
||||
import User, { pack, ILocalUser } from '../../../../models/user';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import deleteFollowing from '../../../../services/following/delete';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -34,10 +34,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Check if the followee is yourself
|
||||
@ -74,4 +71,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Send response
|
||||
res(await pack(followee._id, user));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import acceptFollowRequest from '../../../../../services/following/requests/accept';
|
||||
import User, { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import User from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch follower
|
||||
const follower = await User.findOne({
|
||||
_id: ps.userId
|
||||
@ -37,4 +34,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
await acceptFollowRequest(user, follower);
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import cancelFollowRequest from '../../../../../services/following/requests/cancel';
|
||||
import User, { pack, ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import User, { pack } from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch followee
|
||||
const followee = await User.findOne({
|
||||
_id: ps.userId
|
||||
@ -41,4 +38,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
}
|
||||
|
||||
res(await pack(followee._id, user));
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
//import $ from 'cafy'; import ID, { transform } from '../../../../../cafy-id';
|
||||
import FollowRequest, { pack } from '../../../../../models/follow-request';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -13,11 +13,11 @@ export const meta = {
|
||||
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({
|
||||
followeeId: user._id
|
||||
});
|
||||
|
||||
// Send response
|
||||
res(await Promise.all(reqs.map(req => pack(req))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import rejectFollowRequest from '../../../../../services/following/requests/reject';
|
||||
import User, { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import User from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch follower
|
||||
const follower = await User.findOne({
|
||||
_id: ps.userId
|
||||
@ -37,4 +34,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
await rejectFollowRequest(user, follower);
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Following from '../../../../models/following';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +20,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Fetch following
|
||||
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
res();
|
||||
|
||||
// TODO: イベント
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Following from '../../../../models/following';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +20,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Fetch following
|
||||
@ -47,4 +43,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
res();
|
||||
|
||||
// TODO: イベント
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import ReversiGame, { pack } from '../../../../../models/games/reversi/game';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
params: {
|
||||
@ -27,10 +26,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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, {
|
||||
detail: false
|
||||
}))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../../misc/cafy-id';
|
||||
import ReversiGame, { pack } from '../../../../../../models/games/reversi/game';
|
||||
import Reversi from '../../../../../../games/reversi/core';
|
||||
import { ILocalUser } from '../../../../../../models/user';
|
||||
import getParams from '../../../../get-params';
|
||||
import define from '../../../../define';
|
||||
|
||||
export const meta = {
|
||||
params: {
|
||||
@ -13,10 +12,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const game = await ReversiGame.findOne({ _id: ps.gameId });
|
||||
|
||||
if (game == null) {
|
||||
@ -39,4 +35,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
board: o.board,
|
||||
turn: o.turn
|
||||
}, packed));
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../../misc/cafy-id';
|
||||
import ReversiGame, { pack } from '../../../../../../models/games/reversi/game';
|
||||
import { ILocalUser } from '../../../../../../models/user';
|
||||
import getParams from '../../../../get-params';
|
||||
import { publishReversiGameStream } from '../../../../../../stream';
|
||||
import define from '../../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -22,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const game = await ReversiGame.findOne({ _id: ps.gameId });
|
||||
|
||||
if (game == null) {
|
||||
@ -58,4 +54,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,11 +1,11 @@
|
||||
import Matching, { pack as packMatching } from '../../../../../models/games/reversi/matching';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
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
|
||||
const invitations = await Matching.find({
|
||||
childId: user._id
|
||||
@ -17,4 +17,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Reponse
|
||||
res(Promise.all(invitations.map(async (i) => await packMatching(i, user))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,10 +1,10 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import Matching, { pack as packMatching } from '../../../../../models/games/reversi/matching';
|
||||
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 { eighteight } from '../../../../../games/reversi/maps';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -17,10 +17,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Myself
|
||||
if (ps.userId.equals(user._id)) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
@ -1,14 +1,14 @@
|
||||
import Matching from '../../../../../../models/games/reversi/matching';
|
||||
import { ILocalUser } from '../../../../../../models/user';
|
||||
import define from '../../../../define';
|
||||
|
||||
export const meta = {
|
||||
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({
|
||||
parentId: user._id
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import Hashtag from '../../../../models/hashtag';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
const escapeRegexp = require('escape-regexp');
|
||||
|
||||
export const meta = {
|
||||
@ -36,10 +36,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
const hashtags = await Hashtag
|
||||
.find({
|
||||
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));
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,7 @@
|
||||
import Note from '../../../../models/note';
|
||||
import { erase } from '../../../../prelude/array';
|
||||
import Meta from '../../../../models/meta';
|
||||
import define from '../../define';
|
||||
|
||||
/*
|
||||
トレンドに載るためには「『直近a分間のユニーク投稿数が今からa分前~今からb分前の間のユニーク投稿数のn倍以上』のハッシュタグの上位5位以内に入る」ことが必要
|
||||
@ -14,10 +15,11 @@ const requiredUsers = 3; // 最低何人がそのタグを投稿している必
|
||||
|
||||
const max = 5;
|
||||
|
||||
/**
|
||||
* Get trends of hashtags
|
||||
*/
|
||||
export default () => new Promise(async (res, rej) => {
|
||||
export const meta = {
|
||||
requireCredential: false,
|
||||
};
|
||||
|
||||
export default define(meta, () => new Promise(async (res, rej) => {
|
||||
const meta = await Meta.findOne({});
|
||||
const hidedTags = meta ? (meta.hidedTags || []).map(t => t.toLowerCase()) : [];
|
||||
|
||||
@ -143,4 +145,4 @@ export default () => new Promise(async (res, rej) => {
|
||||
}));
|
||||
|
||||
res(stats);
|
||||
});
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import User, { pack, ILocalUser } from '../../../models/user';
|
||||
import { IApp } from '../../../models/app';
|
||||
import User, { pack } from '../../../models/user';
|
||||
import define from '../define';
|
||||
|
||||
export const meta = {
|
||||
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;
|
||||
|
||||
// Serialize
|
||||
@ -34,4 +34,4 @@ export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (
|
||||
lastUsedAt: new Date()
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as speakeasy from 'speakeasy';
|
||||
import User, { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import User from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -15,10 +15,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const _token = ps.token.replace(/\s/g, '');
|
||||
|
||||
if (user.twoFactorTempSecret == null) {
|
||||
@ -43,4 +40,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -2,9 +2,9 @@ import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import * as speakeasy from 'speakeasy';
|
||||
import * as QRCode from 'qrcode';
|
||||
import User, { ILocalUser } from '../../../../../models/user';
|
||||
import User from '../../../../../models/user';
|
||||
import config from '../../../../../config';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -18,10 +18,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Compare 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
|
||||
});
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import User, { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import User from '../../../../../models/user';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -15,10 +15,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Compare 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();
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import AccessToken from '../../../../models/access-token';
|
||||
import { pack } from '../../../../models/app';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -27,10 +26,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get tokens
|
||||
const tokens = await AccessToken
|
||||
.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, {
|
||||
detail: true
|
||||
}))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import User from '../../../../models/user';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -19,10 +19,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Compare 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();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Favorite, { packMany } from '../../../../models/favorite';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -31,10 +30,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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));
|
||||
});
|
||||
}));
|
||||
|
@ -4,8 +4,7 @@ import Mute from '../../../../models/mute';
|
||||
import { packMany } from '../../../../models/notification';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import read from '../../common/read-notification';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -45,10 +44,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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) {
|
||||
read(user._id, notifications);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import { pack } from '../../../../models/user';
|
||||
import { addPinned } from '../../../../services/i/pin';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -27,10 +26,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Processing
|
||||
try {
|
||||
await addPinned(user, ps.noteId);
|
||||
@ -45,4 +41,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
|
||||
// Send response
|
||||
res(iObj);
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,7 @@
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { publishMainStream } from '../../../../stream';
|
||||
import NoteUnread from '../../../../models/note-unread';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
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
|
||||
await NoteUnread.remove({
|
||||
userId: user._id
|
||||
@ -34,4 +35,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
publishMainStream(user._id, 'readAllUnreadSpecifiedNotes');
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,9 +1,9 @@
|
||||
import $ from 'cafy';
|
||||
import * as bcrypt from 'bcryptjs';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { publishMainStream } from '../../../../stream';
|
||||
import generateUserToken from '../../common/generate-native-user-token';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -17,10 +17,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Compare 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
|
||||
publishMainStream(user._id, 'myTokenRegenerated');
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Signin, { pack } from '../../../../models/signin';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -26,10 +25,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.untilId) {
|
||||
return rej('cannot set sinceId and untilId');
|
||||
@ -62,4 +58,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(history.map(record => pack(record))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import { pack } from '../../../../models/user';
|
||||
import { removePinned } from '../../../../services/i/pin';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -27,10 +26,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Processing
|
||||
try {
|
||||
await removePinned(user, ps.noteId);
|
||||
@ -45,4 +41,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
|
||||
// Send response
|
||||
res(iObj);
|
||||
});
|
||||
}));
|
||||
|
@ -5,7 +5,7 @@ import DriveFile from '../../../../models/drive-file';
|
||||
import acceptAllFollowRequests from '../../../../services/following/requests/accept-all';
|
||||
import { IApp } from '../../../../models/app';
|
||||
import { publishToFollowers } from '../../../../services/i/update';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import getDriveFileUrl from '../../../../misc/get-drive-file-url';
|
||||
|
||||
export const meta = {
|
||||
@ -115,10 +115,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
||||
const isSecure = user != null && app == null;
|
||||
|
||||
const updates = {} as any;
|
||||
@ -209,4 +206,4 @@ export default async (params: any, user: ILocalUser, app: IApp) => new Promise(a
|
||||
|
||||
// フォロワーにUpdateを配信
|
||||
publishToFollowers(user._id);
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { publishMainStream } from '../../../../stream';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -19,10 +19,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const x: any = {};
|
||||
x[`clientSettings.${name}`] = ps.value;
|
||||
|
||||
@ -37,4 +34,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
key: name,
|
||||
value: ps.value
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { publishMainStream } from '../../../../stream';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -20,10 +20,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'clientSettings.home': ps.home
|
||||
@ -33,4 +30,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
res();
|
||||
|
||||
publishMainStream(user._id, 'homeUpdated', ps.home);
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { publishMainStream } from '../../../../stream';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -19,10 +19,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'clientSettings.mobileHome': ps.home
|
||||
@ -32,4 +29,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
res();
|
||||
|
||||
publishMainStream(user._id, 'mobileHomeUpdated', ps.home);
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { publishMainStream } from '../../../../stream';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
requireCredential: true,
|
||||
@ -19,10 +19,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
if (ps.id == null && ps.data == null) return rej('you need to set id and data params if home param unset');
|
||||
|
||||
let widget;
|
||||
@ -88,4 +85,4 @@ export default async (params: any, user: ILocalUser) => new Promise(async (res,
|
||||
} else {
|
||||
rej('widget not found');
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
@ -2,8 +2,7 @@ import $ from 'cafy';
|
||||
import History from '../../../../models/messaging-history';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { pack } from '../../../../models/messaging-message';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -23,10 +22,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const mute = await Mute.find({
|
||||
muterId: user._id,
|
||||
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))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,9 +1,9 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Message from '../../../../models/messaging-message';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import User from '../../../../models/user';
|
||||
import { pack } from '../../../../models/messaging-message';
|
||||
import read from '../../common/read-messaging-message';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -43,10 +43,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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) {
|
||||
read(user._id, recipient._id, messages);
|
||||
}
|
||||
});
|
||||
}));
|
||||
|
@ -2,14 +2,14 @@ import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id
|
||||
import Message from '../../../../../models/messaging-message';
|
||||
import { isValidText } from '../../../../../models/messaging-message';
|
||||
import History from '../../../../../models/messaging-history';
|
||||
import User, { ILocalUser } from '../../../../../models/user';
|
||||
import User from '../../../../../models/user';
|
||||
import Mute from '../../../../../models/mute';
|
||||
import DriveFile from '../../../../../models/drive-file';
|
||||
import { pack } from '../../../../../models/messaging-message';
|
||||
import { publishMainStream } from '../../../../../stream';
|
||||
import { publishMessagingStream, publishMessagingIndexStream } from '../../../../../stream';
|
||||
import pushSw from '../../../../../push-sw';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -38,10 +38,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Myself
|
||||
if (ps.userId.equals(user._id)) {
|
||||
return rej('cannot send message to myself');
|
||||
@ -155,4 +152,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
}, {
|
||||
upsert: true
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import Message from '../../../../../models/messaging-message';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import read from '../../../common/read-messaging-message';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -26,10 +25,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const message = await Message.findOne({
|
||||
_id: ps.messageId,
|
||||
recipientId: user._id
|
||||
@ -42,4 +38,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
read(user._id, message.userId, message);
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -2,9 +2,8 @@ import $ from 'cafy';
|
||||
import * as os from 'os';
|
||||
import config from '../../../config';
|
||||
import Meta from '../../../models/meta';
|
||||
import { ILocalUser } from '../../../models/user';
|
||||
import Emoji from '../../../models/emoji';
|
||||
import getParams from '../get-params';
|
||||
import define from '../define';
|
||||
|
||||
const pkg = require('../../../../package.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) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
const met: any = (await Meta.findOne()) || {};
|
||||
|
||||
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 : {}
|
||||
} : undefined
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
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 getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// 自分自身
|
||||
@ -64,4 +61,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,7 @@
|
||||
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 getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -21,10 +21,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// Check if the mutee is yourself
|
||||
@ -62,4 +59,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
});
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Mute, { packMany } from '../../../../models/mute';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -31,10 +30,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, me) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy';
|
||||
import App, { pack } from '../../../../models/app';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -24,10 +23,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const query = {
|
||||
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, {
|
||||
detail: true
|
||||
}))));
|
||||
});
|
||||
}));
|
||||
|
@ -1,6 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../misc/cafy-id';
|
||||
import Note, { packMany } from '../../../models/note';
|
||||
import getParams from '../get-params';
|
||||
import define from '../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -67,10 +67,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.untilId) {
|
||||
return rej('cannot set sinceId and untilId');
|
||||
@ -130,4 +127,4 @@ export default (params: any) => new Promise(async (res, rej) => {
|
||||
|
||||
// Serialize
|
||||
res(await packMany(notes));
|
||||
});
|
||||
}));
|
||||
|
@ -1,7 +1,6 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Note, { packMany, INote } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -29,10 +28,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Lookup note
|
||||
const note = await Note.findOne({
|
||||
_id: ps.noteId
|
||||
@ -67,4 +63,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
}
|
||||
|
||||
res(await packMany(conversation, user));
|
||||
});
|
||||
}));
|
||||
|
@ -1,11 +1,10 @@
|
||||
import $ from 'cafy'; import ID, { transform, transformMany } from '../../../../misc/cafy-id';
|
||||
const ms = require('ms');
|
||||
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 create from '../../../../services/note/create';
|
||||
import { IApp } from '../../../../models/app';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -139,10 +138,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user, app) => new Promise(async (res, rej) => {
|
||||
let visibleUsers: IUser[] = [];
|
||||
if (ps.visibleUserIds) {
|
||||
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({
|
||||
createdNote: noteObj
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,8 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import deleteNote from '../../../../services/note/delete';
|
||||
import User, { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import User from '../../../../models/user';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -28,10 +28,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Fetch note
|
||||
const note = await Note.findOne({
|
||||
_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);
|
||||
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import Favorite from '../../../../../models/favorite';
|
||||
import Note from '../../../../../models/note';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -28,10 +27,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get favoritee
|
||||
const note = await Note.findOne({
|
||||
_id: ps.noteId
|
||||
@ -60,4 +56,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Send response
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
|
||||
import Favorite from '../../../../../models/favorite';
|
||||
import Note from '../../../../../models/note';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
@ -28,10 +27,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get favoritee
|
||||
const note = await Note.findOne({
|
||||
_id: ps.noteId
|
||||
@ -58,4 +54,4 @@ export default (params: any, user: ILocalUser) => new Promise(async (res, rej) =
|
||||
|
||||
// Send response
|
||||
res();
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import Note from '../../../../models/note';
|
||||
import { packMany } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -23,10 +22,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
const day = 1000 * 60 * 60 * 24;
|
||||
|
||||
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));
|
||||
}));
|
||||
|
@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { packMany } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
@ -51,13 +50,10 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
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
|
||||
|
||||
// Issue query
|
||||
const timeline = await Note
|
||||
.find(query, {
|
||||
limit: ps.limit,
|
||||
sort: sort
|
||||
});
|
||||
|
||||
// Serialize
|
||||
return await packMany(timeline, user);
|
||||
};
|
||||
res(await packMany(timeline, user));
|
||||
}));
|
||||
|
@ -3,8 +3,7 @@ import Note from '../../../../models/note';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { getFriends } from '../../common/get-friends';
|
||||
import { packMany } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
@ -91,13 +90,10 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
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([
|
||||
@ -246,13 +242,11 @@ export default async (params: any, user: ILocalUser) => {
|
||||
}
|
||||
//#endregion
|
||||
|
||||
// Issue query
|
||||
const timeline = await Note
|
||||
.find(query, {
|
||||
limit: ps.limit,
|
||||
sort: sort
|
||||
});
|
||||
|
||||
// Serialize
|
||||
return await packMany(timeline, user);
|
||||
};
|
||||
res(await packMany(timeline, user));
|
||||
}));
|
||||
|
@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { packMany } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import { countIf } from '../../../../prelude/array';
|
||||
|
||||
export const meta = {
|
||||
@ -66,13 +65,10 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) throw psErr;
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||
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
|
||||
|
||||
// Issue query
|
||||
const timeline = await Note
|
||||
.find(query, {
|
||||
limit: ps.limit,
|
||||
sort: sort
|
||||
});
|
||||
|
||||
// Serialize
|
||||
return await packMany(timeline, user);
|
||||
};
|
||||
res(await packMany(timeline, user));
|
||||
}));
|
||||
|
@ -2,8 +2,7 @@ import $ from 'cafy'; import ID, { transform } from '../../../../misc/cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import { packMany } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import getParams from '../../get-params';
|
||||
import define from '../../define';
|
||||
import read from '../../../../services/note/read';
|
||||
|
||||
export const meta = {
|
||||
@ -41,10 +40,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Check if both of sinceId and untilId is specified
|
||||
if (ps.sinceId && ps.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));
|
||||
|
||||
mentions.forEach(note => read(user._id, note._id));
|
||||
});
|
||||
}));
|
||||
|
@ -1,8 +1,7 @@
|
||||
import $ from 'cafy';
|
||||
import Vote from '../../../../../models/poll-vote';
|
||||
import Note, { pack } from '../../../../../models/note';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
import define from '../../../define';
|
||||
|
||||
export const meta = {
|
||||
desc: {
|
||||
@ -25,10 +24,7 @@ export const meta = {
|
||||
}
|
||||
};
|
||||
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
|
||||
// Get votes
|
||||
const votes = await Vote.find({
|
||||
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, {
|
||||
detail: true
|
||||
}))));
|
||||
});
|
||||
}));
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user