commit
d5bad25c63
@ -20,7 +20,7 @@ import * as replace from 'gulp-replace';
|
|||||||
import * as htmlmin from 'gulp-htmlmin';
|
import * as htmlmin from 'gulp-htmlmin';
|
||||||
const uglifyes = require('uglify-es');
|
const uglifyes = require('uglify-es');
|
||||||
|
|
||||||
import locales from './locales';
|
const locales = require('./locales');
|
||||||
import { fa } from './src/build/fa';
|
import { fa } from './src/build/fa';
|
||||||
const client = require('./built/client/meta.json');
|
const client = require('./built/client/meta.json');
|
||||||
import config from './src/config';
|
import config from './src/config';
|
||||||
|
27
locales/index.js
Normal file
27
locales/index.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Languages Loader
|
||||||
|
*/
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
|
||||||
|
const loadLang = lang => yaml.safeLoad(
|
||||||
|
fs.readFileSync(`./locales/${lang}.yml`, 'utf-8'));
|
||||||
|
|
||||||
|
const native = loadLang('ja');
|
||||||
|
|
||||||
|
const langs = {
|
||||||
|
'de': loadLang('de'),
|
||||||
|
'en': loadLang('en'),
|
||||||
|
'fr': loadLang('fr'),
|
||||||
|
'ja': native,
|
||||||
|
'pl': loadLang('pl'),
|
||||||
|
'es': loadLang('es')
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.entries(langs).map(([, locale]) => {
|
||||||
|
// Extend native language (Japanese)
|
||||||
|
locale = Object.assign({}, native, locale);
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = langs;
|
@ -1,34 +0,0 @@
|
|||||||
/**
|
|
||||||
* Languages Loader
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as yaml from 'js-yaml';
|
|
||||||
|
|
||||||
export type LangKey = 'de' | 'en' | 'fr' | 'ja' | 'pl' | 'es';
|
|
||||||
export type LocaleObject = { [key: string]: any };
|
|
||||||
|
|
||||||
const loadLang = (lang: LangKey) => yaml.safeLoad(
|
|
||||||
fs.readFileSync(`./locales/${lang}.yml`, 'utf-8')) as LocaleObject;
|
|
||||||
|
|
||||||
const native = loadLang('ja');
|
|
||||||
|
|
||||||
const langs: { [key: string]: LocaleObject } = {
|
|
||||||
'de': loadLang('de'),
|
|
||||||
'en': loadLang('en'),
|
|
||||||
'fr': loadLang('fr'),
|
|
||||||
'ja': native,
|
|
||||||
'pl': loadLang('pl'),
|
|
||||||
'es': loadLang('es')
|
|
||||||
};
|
|
||||||
|
|
||||||
Object.entries(langs).map(([, locale]) => {
|
|
||||||
// Extend native language (Japanese)
|
|
||||||
locale = Object.assign({}, native, locale);
|
|
||||||
});
|
|
||||||
|
|
||||||
export function isAvailableLanguage(lang: string): lang is LangKey {
|
|
||||||
return lang in langs;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default langs;
|
|
@ -1092,7 +1092,4 @@ docs:
|
|||||||
props:
|
props:
|
||||||
name: "名前"
|
name: "名前"
|
||||||
type: "型"
|
type: "型"
|
||||||
optional: "オプション"
|
|
||||||
description: "説明"
|
description: "説明"
|
||||||
yes: "はい"
|
|
||||||
no: "いいえ"
|
|
||||||
|
@ -89,7 +89,7 @@
|
|||||||
"autwh": "0.1.0",
|
"autwh": "0.1.0",
|
||||||
"bcryptjs": "2.4.3",
|
"bcryptjs": "2.4.3",
|
||||||
"bootstrap-vue": "2.0.0-rc.11",
|
"bootstrap-vue": "2.0.0-rc.11",
|
||||||
"cafy": "8.0.0",
|
"cafy": "11.2.0",
|
||||||
"chalk": "2.4.1",
|
"chalk": "2.4.1",
|
||||||
"crc-32": "1.2.0",
|
"crc-32": "1.2.0",
|
||||||
"css-loader": "0.28.11",
|
"css-loader": "0.28.11",
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* Replace i18n texts
|
* Replace i18n texts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import locale, { isAvailableLanguage, LocaleObject } from '../../locales';
|
const locale = require('../../locales');
|
||||||
|
|
||||||
export default class Replacer {
|
export default class Replacer {
|
||||||
private lang: string;
|
private lang: string;
|
||||||
@ -16,8 +16,8 @@ export default class Replacer {
|
|||||||
this.replacement = this.replacement.bind(this);
|
this.replacement = this.replacement.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private get(path: string, key: string): string {
|
public get(path: string, key: string): string {
|
||||||
if (!isAvailableLanguage(this.lang)) {
|
if (!(this.lang in locale)) {
|
||||||
console.warn(`lang '${this.lang}' is not supported`);
|
console.warn(`lang '${this.lang}' is not supported`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ export default class Replacer {
|
|||||||
|
|
||||||
if (path) {
|
if (path) {
|
||||||
if (text.hasOwnProperty(path)) {
|
if (text.hasOwnProperty(path)) {
|
||||||
text = text[path] as LocaleObject;
|
text = text[path];
|
||||||
} else {
|
} else {
|
||||||
console.warn(`path '${path}' not found in '${this.lang}'`);
|
console.warn(`path '${path}' not found in '${this.lang}'`);
|
||||||
return key; // Fallback
|
return key; // Fallback
|
||||||
@ -38,7 +38,7 @@ export default class Replacer {
|
|||||||
// Check the key existance
|
// Check the key existance
|
||||||
const error = key.split('.').some(k => {
|
const error = key.split('.').some(k => {
|
||||||
if (text.hasOwnProperty(k)) {
|
if (text.hasOwnProperty(k)) {
|
||||||
text = (text as LocaleObject)[k];
|
text = text[k];
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import * as mongo from 'mongodb';
|
import * as mongo from 'mongodb';
|
||||||
import { Query } from 'cafy';
|
import { Context } from 'cafy';
|
||||||
|
|
||||||
export const isAnId = (x: any) => mongo.ObjectID.isValid(x);
|
export const isAnId = (x: any) => mongo.ObjectID.isValid(x);
|
||||||
export const isNotAnId = (x: any) => !isAnId(x);
|
export const isNotAnId = (x: any) => !isAnId(x);
|
||||||
@ -7,7 +7,7 @@ export const isNotAnId = (x: any) => !isAnId(x);
|
|||||||
/**
|
/**
|
||||||
* ID
|
* ID
|
||||||
*/
|
*/
|
||||||
export default class ID extends Query<mongo.ObjectID> {
|
export default class ID extends Context<mongo.ObjectID> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -26,4 +26,8 @@ export default class ID extends Query<mongo.ObjectID> {
|
|||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getType() {
|
||||||
|
return super.getType('string');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
endpoint: "notes/create"
|
|
||||||
|
|
||||||
desc:
|
|
||||||
ja: "投稿します。"
|
|
||||||
en: "Compose new note."
|
|
||||||
|
|
||||||
params:
|
|
||||||
- name: "text"
|
|
||||||
type: "string"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "投稿の本文"
|
|
||||||
en: "The text of your note"
|
|
||||||
- name: "cw"
|
|
||||||
type: "string"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。"
|
|
||||||
en: "Content Warning"
|
|
||||||
- name: "mediaIds"
|
|
||||||
type: "id(DriveFile)[]"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "添付するメディア(1~4つ)"
|
|
||||||
en: "Media you want to attach (1~4)"
|
|
||||||
- name: "replyId"
|
|
||||||
type: "id(Note)"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "返信する投稿"
|
|
||||||
en: "The note you want to reply"
|
|
||||||
- name: "renoteId"
|
|
||||||
type: "id(Note)"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "引用する投稿"
|
|
||||||
en: "The note you want to quote"
|
|
||||||
- name: "poll"
|
|
||||||
type: "object"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "投票"
|
|
||||||
en: "The poll"
|
|
||||||
defName: "poll"
|
|
||||||
def:
|
|
||||||
- name: "choices"
|
|
||||||
type: "string[]"
|
|
||||||
optional: false
|
|
||||||
desc:
|
|
||||||
ja: "投票の選択肢"
|
|
||||||
en: "Choices of a poll"
|
|
||||||
|
|
||||||
res:
|
|
||||||
- name: "createdNote"
|
|
||||||
type: "entity(Note)"
|
|
||||||
optional: false
|
|
||||||
desc:
|
|
||||||
ja: "作成した投稿"
|
|
||||||
en: "A note that created"
|
|
@ -1,32 +0,0 @@
|
|||||||
endpoint: "notes/timeline"
|
|
||||||
|
|
||||||
desc:
|
|
||||||
ja: "タイムラインを取得します。"
|
|
||||||
en: "Get your timeline."
|
|
||||||
|
|
||||||
params:
|
|
||||||
- name: "limit"
|
|
||||||
type: "number"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "取得する最大の数"
|
|
||||||
- name: "sinceId"
|
|
||||||
type: "id(Note)"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "指定すると、この投稿を基点としてより新しい投稿を取得します"
|
|
||||||
- name: "untilId"
|
|
||||||
type: "id(Note)"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "指定すると、この投稿を基点としてより古い投稿を取得します"
|
|
||||||
- name: "sinceDate"
|
|
||||||
type: "number"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "指定した時間を基点としてより新しい投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。"
|
|
||||||
- name: "untilDate"
|
|
||||||
type: "number"
|
|
||||||
optional: true
|
|
||||||
desc:
|
|
||||||
ja: "指定した時間を基点としてより古い投稿を取得します。数値は、1970 年 1 月 1 日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。"
|
|
@ -17,7 +17,7 @@ block main
|
|||||||
p#desc= desc[lang] || desc['ja']
|
p#desc= desc[lang] || desc['ja']
|
||||||
|
|
||||||
section
|
section
|
||||||
h2 %i18n:docs.api.endpoints.params%
|
h2= i18n('docs.api.endpoints.params')
|
||||||
+propTable(params)
|
+propTable(params)
|
||||||
|
|
||||||
if paramDefs
|
if paramDefs
|
||||||
@ -28,5 +28,5 @@ block main
|
|||||||
|
|
||||||
if res
|
if res
|
||||||
section
|
section
|
||||||
h2 %i18n:docs.api.endpoints.res%
|
h2= i18n('docs.api.endpoints.res')
|
||||||
+propTable(res)
|
+propTable(res)
|
||||||
|
@ -27,8 +27,8 @@ props:
|
|||||||
type: "string"
|
type: "string"
|
||||||
optional: true
|
optional: true
|
||||||
desc:
|
desc:
|
||||||
ja: "投稿の本文 (ローカルの場合Markdown風のフォーマット)"
|
ja: "投稿の本文"
|
||||||
en: "The text of this note (in Markdown like format if local)"
|
en: "The text of this note"
|
||||||
- name: "mediaIds"
|
- name: "mediaIds"
|
||||||
type: "id(DriveFile)[]"
|
type: "id(DriveFile)[]"
|
||||||
optional: true
|
optional: true
|
||||||
|
@ -10,7 +10,7 @@ block main
|
|||||||
p#desc= desc[lang] || desc['ja']
|
p#desc= desc[lang] || desc['ja']
|
||||||
|
|
||||||
section
|
section
|
||||||
h2 %i18n:docs.api.entities.properties%
|
h2= i18n('docs.api.entities.properties')
|
||||||
+propTable(props)
|
+propTable(props)
|
||||||
|
|
||||||
if propDefs
|
if propDefs
|
||||||
|
@ -1,193 +0,0 @@
|
|||||||
/**
|
|
||||||
* Gulp tasks
|
|
||||||
*/
|
|
||||||
|
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as glob from 'glob';
|
|
||||||
import * as gulp from 'gulp';
|
|
||||||
import * as pug from 'pug';
|
|
||||||
import * as yaml from 'js-yaml';
|
|
||||||
import * as mkdirp from 'mkdirp';
|
|
||||||
|
|
||||||
import locales from '../../../../locales';
|
|
||||||
import I18nReplacer from '../../../build/i18n';
|
|
||||||
import fa from '../../../build/fa';
|
|
||||||
import config from './../../../config';
|
|
||||||
|
|
||||||
import generateVars from '../vars';
|
|
||||||
|
|
||||||
const langs = Object.keys(locales);
|
|
||||||
|
|
||||||
const kebab = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
|
|
||||||
|
|
||||||
// WIP type
|
|
||||||
const parseParam = (param: any) => {
|
|
||||||
const id = param.type.match(/^id\((.+?)\)|^id/);
|
|
||||||
const entity = param.type.match(/^entity\((.+?)\)/);
|
|
||||||
const isObject = /^object/.test(param.type);
|
|
||||||
const isDate = /^date/.test(param.type);
|
|
||||||
const isArray = /\[\]$/.test(param.type);
|
|
||||||
if (id) {
|
|
||||||
param.kind = 'id';
|
|
||||||
param.type = 'string';
|
|
||||||
param.entity = id[1];
|
|
||||||
if (isArray) {
|
|
||||||
param.type += '[]';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (entity) {
|
|
||||||
param.kind = 'entity';
|
|
||||||
param.type = 'object';
|
|
||||||
param.entity = entity[1];
|
|
||||||
if (isArray) {
|
|
||||||
param.type += '[]';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isObject) {
|
|
||||||
param.kind = 'object';
|
|
||||||
}
|
|
||||||
if (isDate) {
|
|
||||||
param.kind = 'date';
|
|
||||||
param.type = 'string';
|
|
||||||
if (isArray) {
|
|
||||||
param.type += '[]';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return param;
|
|
||||||
};
|
|
||||||
|
|
||||||
const sortParams = (params: Array<{name: string}>) => {
|
|
||||||
params.sort((a, b) => {
|
|
||||||
if (a.name < b.name)
|
|
||||||
return -1;
|
|
||||||
if (a.name > b.name)
|
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
});
|
|
||||||
return params;
|
|
||||||
};
|
|
||||||
|
|
||||||
// WIP type
|
|
||||||
const extractDefs = (params: any[]) => {
|
|
||||||
let defs: any[] = [];
|
|
||||||
|
|
||||||
params.forEach(param => {
|
|
||||||
if (param.def) {
|
|
||||||
defs.push({
|
|
||||||
name: param.defName,
|
|
||||||
params: sortParams(param.def.map((p: any) => parseParam(p)))
|
|
||||||
});
|
|
||||||
|
|
||||||
const childDefs = extractDefs(param.def);
|
|
||||||
|
|
||||||
defs = defs.concat(childDefs);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return sortParams(defs);
|
|
||||||
};
|
|
||||||
|
|
||||||
gulp.task('doc:api', [
|
|
||||||
'doc:api:endpoints',
|
|
||||||
'doc:api:entities'
|
|
||||||
]);
|
|
||||||
|
|
||||||
gulp.task('doc:api:endpoints', async () => {
|
|
||||||
const commonVars = await generateVars();
|
|
||||||
glob('./src/client/docs/api/endpoints/**/*.yaml', (globErr, files) => {
|
|
||||||
if (globErr) {
|
|
||||||
console.error(globErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//console.log(files);
|
|
||||||
files.forEach(file => {
|
|
||||||
const ep: any = yaml.safeLoad(fs.readFileSync(file, 'utf-8'));
|
|
||||||
const vars = {
|
|
||||||
endpoint: ep.endpoint,
|
|
||||||
url: {
|
|
||||||
host: config.api_url,
|
|
||||||
path: ep.endpoint
|
|
||||||
},
|
|
||||||
desc: ep.desc,
|
|
||||||
// @ts-ignore
|
|
||||||
params: sortParams(ep.params.map(p => parseParam(p))),
|
|
||||||
paramDefs: extractDefs(ep.params),
|
|
||||||
// @ts-ignore
|
|
||||||
res: ep.res ? sortParams(ep.res.map(p => parseParam(p))) : null,
|
|
||||||
resDefs: ep.res ? extractDefs(ep.res) : null,
|
|
||||||
};
|
|
||||||
langs.forEach(lang => {
|
|
||||||
pug.renderFile('./src/client/docs/api/endpoints/view.pug', Object.assign({}, vars, {
|
|
||||||
lang,
|
|
||||||
title: ep.endpoint,
|
|
||||||
src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/api/endpoints/${ep.endpoint}.yaml`,
|
|
||||||
kebab,
|
|
||||||
common: commonVars
|
|
||||||
}), (renderErr, html) => {
|
|
||||||
if (renderErr) {
|
|
||||||
console.error(renderErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const i18n = new I18nReplacer(lang);
|
|
||||||
html = html.replace(i18n.pattern, i18n.replacement);
|
|
||||||
html = fa(html);
|
|
||||||
const htmlPath = `./built/client/docs/${lang}/api/endpoints/${ep.endpoint}.html`;
|
|
||||||
mkdirp(path.dirname(htmlPath), (mkdirErr) => {
|
|
||||||
if (mkdirErr) {
|
|
||||||
console.error(mkdirErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fs.writeFileSync(htmlPath, html, 'utf-8');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('doc:api:entities', async () => {
|
|
||||||
const commonVars = await generateVars();
|
|
||||||
glob('./src/client/docs/api/entities/**/*.yaml', (globErr, files) => {
|
|
||||||
if (globErr) {
|
|
||||||
console.error(globErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
files.forEach(file => {
|
|
||||||
const entity = yaml.safeLoad(fs.readFileSync(file, 'utf-8')) as any;
|
|
||||||
const vars = {
|
|
||||||
name: entity.name,
|
|
||||||
desc: entity.desc,
|
|
||||||
// WIP type
|
|
||||||
props: sortParams(entity.props.map((p: any) => parseParam(p))),
|
|
||||||
propDefs: extractDefs(entity.props),
|
|
||||||
};
|
|
||||||
langs.forEach(lang => {
|
|
||||||
pug.renderFile('./src/client/docs/api/entities/view.pug', Object.assign({}, vars, {
|
|
||||||
lang,
|
|
||||||
title: entity.name,
|
|
||||||
src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/api/entities/${kebab(entity.name)}.yaml`,
|
|
||||||
kebab,
|
|
||||||
common: commonVars
|
|
||||||
}), (renderErr, html) => {
|
|
||||||
if (renderErr) {
|
|
||||||
console.error(renderErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const i18n = new I18nReplacer(lang);
|
|
||||||
html = html.replace(i18n.pattern, i18n.replacement);
|
|
||||||
html = fa(html);
|
|
||||||
const htmlPath = `./built/client/docs/${lang}/api/entities/${kebab(entity.name)}.html`;
|
|
||||||
mkdirp(path.dirname(htmlPath), (mkdirErr) => {
|
|
||||||
if (mkdirErr) {
|
|
||||||
console.error(mkdirErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fs.writeFileSync(htmlPath, html, 'utf-8');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
@ -1,10 +1,9 @@
|
|||||||
mixin propTable(props)
|
mixin propTable(props)
|
||||||
table.props
|
table.props
|
||||||
thead: tr
|
thead: tr
|
||||||
th %i18n:docs.api.props.name%
|
th= i18n('docs.api.props.name')
|
||||||
th %i18n:docs.api.props.type%
|
th= i18n('docs.api.props.type')
|
||||||
th %i18n:docs.api.props.optional%
|
th= i18n('docs.api.props.description')
|
||||||
th %i18n:docs.api.props.description%
|
|
||||||
tbody
|
tbody
|
||||||
each prop in props
|
each prop in props
|
||||||
tr
|
tr
|
||||||
@ -29,9 +28,4 @@ mixin propTable(props)
|
|||||||
| )
|
| )
|
||||||
else if prop.kind == 'date'
|
else if prop.kind == 'date'
|
||||||
| (Date)
|
| (Date)
|
||||||
td.optional
|
td.desc!= prop.desc ? prop.desc[lang] || prop.desc['ja'] : null
|
||||||
if prop.optional
|
|
||||||
| %i18n:docs.api.props.yes%
|
|
||||||
else
|
|
||||||
| %i18n:docs.api.props.no%
|
|
||||||
td.desc!= prop.desc[lang] || prop.desc['ja']
|
|
||||||
|
@ -2,73 +2,14 @@
|
|||||||
* Gulp tasks
|
* Gulp tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs';
|
|
||||||
import * as path from 'path';
|
|
||||||
import * as glob from 'glob';
|
|
||||||
import * as gulp from 'gulp';
|
import * as gulp from 'gulp';
|
||||||
import * as pug from 'pug';
|
|
||||||
import * as mkdirp from 'mkdirp';
|
|
||||||
const stylus = require('gulp-stylus');
|
const stylus = require('gulp-stylus');
|
||||||
const cssnano = require('gulp-cssnano');
|
const cssnano = require('gulp-cssnano');
|
||||||
|
|
||||||
import I18nReplacer from '../../build/i18n';
|
|
||||||
import fa from '../../build/fa';
|
|
||||||
import generateVars from './vars';
|
|
||||||
|
|
||||||
require('./api/gulpfile.ts');
|
|
||||||
|
|
||||||
gulp.task('doc', [
|
gulp.task('doc', [
|
||||||
'doc:docs',
|
|
||||||
'doc:api',
|
|
||||||
'doc:styles'
|
'doc:styles'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
gulp.task('doc:docs', async () => {
|
|
||||||
const commonVars = await generateVars();
|
|
||||||
|
|
||||||
glob('./src/client/docs/**/*.*.pug', (globErr, files) => {
|
|
||||||
if (globErr) {
|
|
||||||
console.error(globErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
files.forEach(file => {
|
|
||||||
const [, name, lang] = file.match(/docs\/(.+?)\.(.+?)\.pug$/);
|
|
||||||
const vars = {
|
|
||||||
common: commonVars,
|
|
||||||
lang: lang,
|
|
||||||
title: fs.readFileSync(file, 'utf-8').match(/^h1 (.+?)\r?\n/)[1],
|
|
||||||
src: `https://github.com/syuilo/misskey/tree/master/src/client/docs/${name}.${lang}.pug`,
|
|
||||||
};
|
|
||||||
pug.renderFile(file, vars, (renderErr, content) => {
|
|
||||||
if (renderErr) {
|
|
||||||
console.error(renderErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pug.renderFile('./src/client/docs/layout.pug', Object.assign({}, vars, {
|
|
||||||
content
|
|
||||||
}), (renderErr2, html) => {
|
|
||||||
if (renderErr2) {
|
|
||||||
console.error(renderErr2);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const i18n = new I18nReplacer(lang);
|
|
||||||
html = html.replace(i18n.pattern, i18n.replacement);
|
|
||||||
html = fa(html);
|
|
||||||
const htmlPath = `./built/client/docs/${lang}/${name}.html`;
|
|
||||||
mkdirp(path.dirname(htmlPath), (mkdirErr) => {
|
|
||||||
if (mkdirErr) {
|
|
||||||
console.error(mkdirErr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
fs.writeFileSync(htmlPath, html, 'utf-8');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('doc:styles', () =>
|
gulp.task('doc:styles', () =>
|
||||||
gulp.src('./src/client/docs/**/*.styl')
|
gulp.src('./src/client/docs/**/*.styl')
|
||||||
.pipe(stylus())
|
.pipe(stylus())
|
||||||
|
@ -10,24 +10,24 @@ html(lang= lang)
|
|||||||
block meta
|
block meta
|
||||||
|
|
||||||
//- FontAwesome style
|
//- FontAwesome style
|
||||||
style #{common.facss}
|
style #{facss}
|
||||||
|
|
||||||
body
|
body
|
||||||
nav
|
nav
|
||||||
ul
|
ul
|
||||||
each doc in common.docs
|
each doc in docs
|
||||||
li: a(href=`/docs/${lang}/${doc.name}`)= doc.title[lang] || doc.title['ja']
|
li: a(href=`/docs/${lang}/${doc.name}`)= doc.title[lang] || doc.title['ja']
|
||||||
section
|
section
|
||||||
h2 API
|
h2 API
|
||||||
ul
|
ul
|
||||||
li Entities
|
li Entities
|
||||||
ul
|
ul
|
||||||
each entity in common.entities
|
each entity in entities
|
||||||
li: a(href=`/docs/${lang}/api/entities/${common.kebab(entity)}`)= entity
|
li: a(href=`/docs/${lang}/api/entities/${kebab(entity)}`)= entity
|
||||||
li Endpoints
|
li Endpoints
|
||||||
ul
|
ul
|
||||||
each endpoint in common.endpoints
|
each endpoint in endpoints
|
||||||
li: a(href=`/docs/${lang}/api/endpoints/${common.kebab(endpoint)}`)= endpoint
|
li: a(href=`/docs/${lang}/api/endpoints/${kebab(endpoint)}`)= endpoint
|
||||||
main
|
main
|
||||||
article
|
article
|
||||||
block main
|
block main
|
||||||
@ -38,4 +38,4 @@ html(lang= lang)
|
|||||||
p
|
p
|
||||||
| %i18n:docs.edit-this-page-on-github%
|
| %i18n:docs.edit-this-page-on-github%
|
||||||
a(href=src target="_blank") %i18n:docs.edit-this-page-on-github-link%
|
a(href=src target="_blank") %i18n:docs.edit-this-page-on-github-link%
|
||||||
small= common.copyright
|
small= copyright
|
||||||
|
@ -10,7 +10,7 @@ main
|
|||||||
margin 0 0 0 256px
|
margin 0 0 0 256px
|
||||||
padding 64px
|
padding 64px
|
||||||
width 100%
|
width 100%
|
||||||
max-width 768px
|
max-width 800px
|
||||||
|
|
||||||
section
|
section
|
||||||
margin 32px 0
|
margin 32px 0
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
import * as fs from 'fs';
|
|
||||||
import * as util from 'util';
|
|
||||||
import * as glob from 'glob';
|
|
||||||
import * as yaml from 'js-yaml';
|
|
||||||
import * as licenseChecker from 'license-checker';
|
|
||||||
import * as tmp from 'tmp';
|
|
||||||
|
|
||||||
import { fa } from '../../build/fa';
|
|
||||||
import config from '../../config';
|
|
||||||
import { licenseHtml } from '../../build/license';
|
|
||||||
const constants = require('../../const.json');
|
|
||||||
|
|
||||||
export default async function(): Promise<{ [key: string]: any }> {
|
|
||||||
const vars = {} as { [key: string]: any };
|
|
||||||
|
|
||||||
const endpoints = glob.sync('./src/client/docs/api/endpoints/**/*.yaml');
|
|
||||||
vars['endpoints'] = endpoints.map(ep => {
|
|
||||||
const _ep = yaml.safeLoad(fs.readFileSync(ep, 'utf-8')) as any;
|
|
||||||
return _ep.endpoint;
|
|
||||||
});
|
|
||||||
|
|
||||||
const entities = glob.sync('./src/client/docs/api/entities/**/*.yaml');
|
|
||||||
vars['entities'] = entities.map(x => {
|
|
||||||
const _x = yaml.safeLoad(fs.readFileSync(x, 'utf-8')) as any;
|
|
||||||
return _x.name;
|
|
||||||
});
|
|
||||||
|
|
||||||
const docs = glob.sync('./src/client/docs/**/*.*.pug');
|
|
||||||
vars['docs'] = {};
|
|
||||||
docs.forEach(x => {
|
|
||||||
const [, name, lang] = x.match(/docs\/(.+?)\.(.+?)\.pug$/);
|
|
||||||
if (vars['docs'][name] == null) {
|
|
||||||
vars['docs'][name] = {
|
|
||||||
name,
|
|
||||||
title: {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
vars['docs'][name]['title'][lang] = fs.readFileSync(x, 'utf-8').match(/^h1 (.+?)\r?\n/)[1];
|
|
||||||
});
|
|
||||||
|
|
||||||
vars['kebab'] = (string: string) => string.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
|
|
||||||
|
|
||||||
vars['config'] = config;
|
|
||||||
|
|
||||||
vars['copyright'] = constants.copyright;
|
|
||||||
|
|
||||||
vars['facss'] = fa.dom.css();
|
|
||||||
|
|
||||||
vars['license'] = licenseHtml;
|
|
||||||
|
|
||||||
const tmpObj = tmp.fileSync();
|
|
||||||
fs.writeFileSync(tmpObj.name, JSON.stringify({
|
|
||||||
licenseText: ''
|
|
||||||
}), 'utf-8');
|
|
||||||
const dependencies = await util.promisify(licenseChecker.init).bind(licenseChecker)({
|
|
||||||
start: __dirname + '/../../../',
|
|
||||||
customPath: tmpObj.name
|
|
||||||
});
|
|
||||||
tmpObj.removeCallback();
|
|
||||||
|
|
||||||
vars['dependencies'] = dependencies;
|
|
||||||
|
|
||||||
return vars;
|
|
||||||
}
|
|
@ -31,7 +31,7 @@ export default (endpoint: string | Endpoint, user: IUser, app: IApp, data: any,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let exec = require(`${__dirname}/endpoints/${ep.name}`);
|
let exec = require(`${__dirname}/endpoints/${ep.name}`).default;
|
||||||
|
|
||||||
if (ep.withFile && file) {
|
if (ep.withFile && file) {
|
||||||
exec = exec.bind(null, file);
|
exec = exec.bind(null, file);
|
||||||
|
@ -4,9 +4,9 @@ import Note from '../../../../models/note';
|
|||||||
/**
|
/**
|
||||||
* Aggregate notes
|
* Aggregate notes
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
|
const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
const datas = await Note
|
const datas = await Note
|
||||||
|
@ -4,9 +4,9 @@ import User from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Aggregate users
|
* Aggregate users
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
|
const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
const users = await User
|
const users = await User
|
||||||
|
@ -7,9 +7,9 @@ import Note from '../../../../../models/note';
|
|||||||
/**
|
/**
|
||||||
* Aggregate activity of a user
|
* Aggregate activity of a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 365, limitErr] = $.num.optional().range(1, 365).get(params.limit);
|
const [limit = 365, limitErr] = $.num.optional.range(1, 365).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -8,7 +8,7 @@ import FollowedLog from '../../../../../models/followed-log';
|
|||||||
/**
|
/**
|
||||||
* Aggregate followers of a user
|
* Aggregate followers of a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||||
if (userIdErr) return rej('invalid userId param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
@ -8,7 +8,7 @@ import FollowingLog from '../../../../../models/following-log';
|
|||||||
/**
|
/**
|
||||||
* Aggregate following of a user
|
* Aggregate following of a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||||
if (userIdErr) return rej('invalid userId param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
@ -5,7 +5,7 @@ import Note from '../../../../../models/note';
|
|||||||
/**
|
/**
|
||||||
* Aggregate note of a user
|
* Aggregate note of a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||||
if (userIdErr) return rej('invalid userId param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
@ -5,7 +5,7 @@ import Reaction from '../../../../../models/note-reaction';
|
|||||||
/**
|
/**
|
||||||
* Aggregate reaction of a user
|
* Aggregate reaction of a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
const [userId, userIdErr] = $.type(ID).get(params.userId);
|
||||||
if (userIdErr) return rej('invalid userId param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
@ -59,7 +59,7 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Create an app
|
* Create an app
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'nameId' parameter
|
// Get 'nameId' parameter
|
||||||
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
||||||
if (nameIdErr) return rej('invalid nameId param');
|
if (nameIdErr) return rej('invalid nameId param');
|
||||||
@ -78,7 +78,7 @@ module.exports = async (params: any, user: ILocalUser) => new Promise(async (res
|
|||||||
|
|
||||||
// Get 'callbackUrl' parameter
|
// Get 'callbackUrl' parameter
|
||||||
// TODO: Check it is valid url
|
// TODO: Check it is valid url
|
||||||
const [callbackUrl = null, callbackUrlErr] = $.str.optional().nullable().get(params.callbackUrl);
|
const [callbackUrl = null, callbackUrlErr] = $.str.optional.nullable.get(params.callbackUrl);
|
||||||
if (callbackUrlErr) return rej('invalid callbackUrl param');
|
if (callbackUrlErr) return rej('invalid callbackUrl param');
|
||||||
|
|
||||||
// Generate secret
|
// Generate secret
|
||||||
|
@ -40,7 +40,7 @@ import { isValidNameId } from '../../../../../models/app';
|
|||||||
* @param {any} params
|
* @param {any} params
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any) => new Promise(async (res, rej) => {
|
export default async (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'nameId' parameter
|
// Get 'nameId' parameter
|
||||||
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
const [nameId, nameIdErr] = $.str.pipe(isValidNameId).get(params.nameId);
|
||||||
if (nameIdErr) return rej('invalid nameId param');
|
if (nameIdErr) return rej('invalid nameId param');
|
||||||
|
@ -35,15 +35,15 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show an app
|
* Show an app
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||||
const isSecure = user != null && app == null;
|
const isSecure = user != null && app == null;
|
||||||
|
|
||||||
// Get 'appId' parameter
|
// Get 'appId' parameter
|
||||||
const [appId, appIdErr] = $.type(ID).optional().get(params.appId);
|
const [appId, appIdErr] = $.type(ID).optional.get(params.appId);
|
||||||
if (appIdErr) return rej('invalid appId param');
|
if (appIdErr) return rej('invalid appId param');
|
||||||
|
|
||||||
// Get 'nameId' parameter
|
// Get 'nameId' parameter
|
||||||
const [nameId, nameIdErr] = $.str.optional().get(params.nameId);
|
const [nameId, nameIdErr] = $.str.optional.get(params.nameId);
|
||||||
if (nameIdErr) return rej('invalid nameId param');
|
if (nameIdErr) return rej('invalid nameId param');
|
||||||
|
|
||||||
if (appId === undefined && nameId === undefined) {
|
if (appId === undefined && nameId === undefined) {
|
||||||
|
@ -32,7 +32,7 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Accept
|
* Accept
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'token' parameter
|
// Get 'token' parameter
|
||||||
const [token, tokenErr] = $.str.get(params.token);
|
const [token, tokenErr] = $.str.get(params.token);
|
||||||
if (tokenErr) return rej('invalid token param');
|
if (tokenErr) return rej('invalid token param');
|
||||||
|
@ -44,7 +44,7 @@ import config from '../../../../../config';
|
|||||||
* @param {any} params
|
* @param {any} params
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'appSecret' parameter
|
// Get 'appSecret' parameter
|
||||||
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
|
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
|
||||||
if (appSecretErr) return rej('invalid appSecret param');
|
if (appSecretErr) return rej('invalid appSecret param');
|
||||||
|
@ -45,7 +45,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show a session
|
* Show a session
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'token' parameter
|
// Get 'token' parameter
|
||||||
const [token, tokenErr] = $.str.get(params.token);
|
const [token, tokenErr] = $.str.get(params.token);
|
||||||
if (tokenErr) return rej('invalid token param');
|
if (tokenErr) return rej('invalid token param');
|
||||||
|
@ -49,7 +49,7 @@ import { pack } from '../../../../../models/user';
|
|||||||
* @param {any} params
|
* @param {any} params
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'appSecret' parameter
|
// Get 'appSecret' parameter
|
||||||
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
|
const [appSecret, appSecretErr] = $.str.get(params.appSecret);
|
||||||
if (appSecretErr) return rej('invalid appSecret param');
|
if (appSecretErr) return rej('invalid appSecret param');
|
||||||
|
@ -4,7 +4,7 @@ import { ILocalUser } from '../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get drive information
|
* Get drive information
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Calculate drive usage
|
// Calculate drive usage
|
||||||
const usage = await DriveFile
|
const usage = await DriveFile
|
||||||
.aggregate([{
|
.aggregate([{
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get drive files
|
* Get drive files
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => {
|
export default async (params: any, user: ILocalUser) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) throw 'invalid limit param';
|
if (limitErr) throw 'invalid limit param';
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) throw 'invalid sinceId param';
|
if (sinceIdErr) throw 'invalid sinceId param';
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) throw 'invalid untilId param';
|
if (untilIdErr) throw 'invalid untilId param';
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
@ -24,11 +24,11 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||||
if (folderIdErr) throw 'invalid folderId param';
|
if (folderIdErr) throw 'invalid folderId param';
|
||||||
|
|
||||||
// Get 'type' parameter
|
// Get 'type' parameter
|
||||||
const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
|
const [type, typeErr] = $.str.optional.match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
|
||||||
if (typeErr) throw 'invalid type param';
|
if (typeErr) throw 'invalid type param';
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Create a file
|
* Create a file
|
||||||
*/
|
*/
|
||||||
module.exports = async (file: any, params: any, user: ILocalUser): Promise<any> => {
|
export default async (file: any, params: any, user: ILocalUser): Promise<any> => {
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
throw 'file is required';
|
throw 'file is required';
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ module.exports = async (file: any, params: any, user: ILocalUser): Promise<any>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||||
if (folderIdErr) throw 'invalid folderId param';
|
if (folderIdErr) throw 'invalid folderId param';
|
||||||
|
|
||||||
function cleanup() {
|
function cleanup() {
|
||||||
|
@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Delete a file
|
* Delete a file
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => {
|
export default async (params: any, user: ILocalUser) => {
|
||||||
// Get 'fileId' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||||
if (fileIdErr) throw 'invalid fileId param';
|
if (fileIdErr) throw 'invalid fileId param';
|
||||||
|
@ -5,13 +5,13 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Find a file(s)
|
* Find a file(s)
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $.str.get(params.name);
|
const [name, nameErr] = $.str.get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||||
if (folderIdErr) return rej('invalid folderId param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
// Issue query
|
// Issue query
|
||||||
|
@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show a file
|
* Show a file
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => {
|
export default async (params: any, user: ILocalUser) => {
|
||||||
// Get 'fileId' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||||
if (fileIdErr) throw 'invalid fileId param';
|
if (fileIdErr) throw 'invalid fileId param';
|
||||||
|
@ -7,7 +7,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Update a file
|
* Update a file
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'fileId' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||||
if (fileIdErr) return rej('invalid fileId param');
|
if (fileIdErr) return rej('invalid fileId param');
|
||||||
@ -24,12 +24,12 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $.str.optional().pipe(validateFileName).get(params.name);
|
const [name, nameErr] = $.str.optional.pipe(validateFileName).get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
if (name) file.filename = name;
|
if (name) file.filename = name;
|
||||||
|
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
const [folderId, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||||
if (folderIdErr) return rej('invalid folderId param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
if (folderId !== undefined) {
|
if (folderId !== undefined) {
|
||||||
|
@ -9,14 +9,14 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Create a file from a URL
|
* Create a file from a URL
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser): Promise<any> => {
|
export default async (params: any, user: ILocalUser): Promise<any> => {
|
||||||
// Get 'url' parameter
|
// Get 'url' parameter
|
||||||
// TODO: Validate this url
|
// TODO: Validate this url
|
||||||
const [url, urlErr] = $.str.get(params.url);
|
const [url, urlErr] = $.str.get(params.url);
|
||||||
if (urlErr) throw 'invalid url param';
|
if (urlErr) throw 'invalid url param';
|
||||||
|
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||||
if (folderIdErr) throw 'invalid folderId param';
|
if (folderIdErr) throw 'invalid folderId param';
|
||||||
|
|
||||||
return pack(await uploadFromUrl(url, user, folderId));
|
return pack(await uploadFromUrl(url, user, folderId));
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get drive folders
|
* Get drive folders
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
@ -24,7 +24,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $.type(ID).optional().nullable().get(params.folderId);
|
const [folderId = null, folderIdErr] = $.type(ID).optional.nullable.get(params.folderId);
|
||||||
if (folderIdErr) return rej('invalid folderId param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
@ -6,13 +6,13 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Create drive folder
|
* Create drive folder
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name = '無題のフォルダー', nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name);
|
const [name = '無題のフォルダー', nameErr] = $.str.optional.pipe(isValidFolderName).get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'parentId' parameter
|
// Get 'parentId' parameter
|
||||||
const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
|
const [parentId = null, parentIdErr] = $.type(ID).optional.nullable.get(params.parentId);
|
||||||
if (parentIdErr) return rej('invalid parentId param');
|
if (parentIdErr) return rej('invalid parentId param');
|
||||||
|
|
||||||
// If the parent folder is specified
|
// If the parent folder is specified
|
||||||
|
@ -5,13 +5,13 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Find a folder(s)
|
* Find a folder(s)
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $.str.get(params.name);
|
const [name, nameErr] = $.str.get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'parentId' parameter
|
// Get 'parentId' parameter
|
||||||
const [parentId = null, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
|
const [parentId = null, parentIdErr] = $.type(ID).optional.nullable.get(params.parentId);
|
||||||
if (parentIdErr) return rej('invalid parentId param');
|
if (parentIdErr) return rej('invalid parentId param');
|
||||||
|
|
||||||
// Issue query
|
// Issue query
|
||||||
|
@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show a folder
|
* Show a folder
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
|
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
|
||||||
if (folderIdErr) return rej('invalid folderId param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Update a folder
|
* Update a folder
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'folderId' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
|
const [folderId, folderIdErr] = $.type(ID).get(params.folderId);
|
||||||
if (folderIdErr) return rej('invalid folderId param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
@ -23,12 +23,12 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $.str.optional().pipe(isValidFolderName).get(params.name);
|
const [name, nameErr] = $.str.optional.pipe(isValidFolderName).get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
if (name) folder.name = name;
|
if (name) folder.name = name;
|
||||||
|
|
||||||
// Get 'parentId' parameter
|
// Get 'parentId' parameter
|
||||||
const [parentId, parentIdErr] = $.type(ID).optional().nullable().get(params.parentId);
|
const [parentId, parentIdErr] = $.type(ID).optional.nullable.get(params.parentId);
|
||||||
if (parentIdErr) return rej('invalid parentId param');
|
if (parentIdErr) return rej('invalid parentId param');
|
||||||
if (parentId !== undefined) {
|
if (parentId !== undefined) {
|
||||||
if (parentId === null) {
|
if (parentId === null) {
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get drive stream
|
* Get drive stream
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
@ -24,7 +24,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'type' parameter
|
// Get 'type' parameter
|
||||||
const [type, typeErr] = $.str.optional().match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
|
const [type, typeErr] = $.str.optional.match(/^[a-zA-Z\/\-\*]+$/).get(params.type);
|
||||||
if (typeErr) return rej('invalid type param');
|
if (typeErr) return rej('invalid type param');
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
@ -6,7 +6,7 @@ import create from '../../../../services/following/create';
|
|||||||
/**
|
/**
|
||||||
* Follow a user
|
* Follow a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const follower = user;
|
const follower = user;
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -6,7 +6,7 @@ import deleteFollowing from '../../../../services/following/delete';
|
|||||||
/**
|
/**
|
||||||
* Unfollow a user
|
* Unfollow a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const follower = user;
|
const follower = user;
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Accept a follow request
|
* Accept a follow request
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
|
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
|
||||||
if (followerIdErr) return rej('invalid userId param');
|
if (followerIdErr) return rej('invalid userId param');
|
||||||
|
@ -5,7 +5,7 @@ import User, { pack, ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Cancel a follow request
|
* Cancel a follow request
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [followeeId, followeeIdErr] = $.type(ID).get(params.userId);
|
const [followeeId, followeeIdErr] = $.type(ID).get(params.userId);
|
||||||
if (followeeIdErr) return rej('invalid userId param');
|
if (followeeIdErr) return rej('invalid userId param');
|
||||||
|
@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get all pending received follow requests
|
* Get all pending received follow requests
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const reqs = await FollowRequest.find({
|
const reqs = await FollowRequest.find({
|
||||||
followeeId: user._id
|
followeeId: user._id
|
||||||
});
|
});
|
||||||
|
@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Reject a follow request
|
* Reject a follow request
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
|
const [followerId, followerIdErr] = $.type(ID).get(params.userId);
|
||||||
if (followerIdErr) return rej('invalid userId param');
|
if (followerIdErr) return rej('invalid userId param');
|
||||||
|
@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Stalk a user
|
* Stalk a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const follower = user;
|
const follower = user;
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Unstalk a user
|
* Unstalk a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const follower = user;
|
const follower = user;
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -15,7 +15,7 @@ const max = 5;
|
|||||||
/**
|
/**
|
||||||
* Get trends of hashtags
|
* Get trends of hashtags
|
||||||
*/
|
*/
|
||||||
module.exports = () => new Promise(async (res, rej) => {
|
export default () => new Promise(async (res, rej) => {
|
||||||
//#region 1. 直近Aの内に投稿されたハッシュタグ(とユーザーのペア)を集計
|
//#region 1. 直近Aの内に投稿されたハッシュタグ(とユーザーのペア)を集計
|
||||||
const data = await Note.aggregate([{
|
const data = await Note.aggregate([{
|
||||||
$match: {
|
$match: {
|
||||||
|
@ -4,7 +4,7 @@ import { IApp } from '../../../models/app';
|
|||||||
/**
|
/**
|
||||||
* Show myself
|
* Show myself
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||||
const isSecure = user != null && app == null;
|
const isSecure = user != null && app == null;
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
|||||||
import * as speakeasy from 'speakeasy';
|
import * as speakeasy from 'speakeasy';
|
||||||
import User, { ILocalUser } from '../../../../../models/user';
|
import User, { ILocalUser } from '../../../../../models/user';
|
||||||
|
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'token' parameter
|
// Get 'token' parameter
|
||||||
const [token, tokenErr] = $.str.get(params.token);
|
const [token, tokenErr] = $.str.get(params.token);
|
||||||
if (tokenErr) return rej('invalid token param');
|
if (tokenErr) return rej('invalid token param');
|
||||||
|
@ -5,7 +5,7 @@ import * as QRCode from 'qrcode';
|
|||||||
import User, { ILocalUser } from '../../../../../models/user';
|
import User, { ILocalUser } from '../../../../../models/user';
|
||||||
import config from '../../../../../config';
|
import config from '../../../../../config';
|
||||||
|
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'password' parameter
|
// Get 'password' parameter
|
||||||
const [password, passwordErr] = $.str.get(params.password);
|
const [password, passwordErr] = $.str.get(params.password);
|
||||||
if (passwordErr) return rej('invalid password param');
|
if (passwordErr) return rej('invalid password param');
|
||||||
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
|||||||
import * as bcrypt from 'bcryptjs';
|
import * as bcrypt from 'bcryptjs';
|
||||||
import User, { ILocalUser } from '../../../../../models/user';
|
import User, { ILocalUser } from '../../../../../models/user';
|
||||||
|
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'password' parameter
|
// Get 'password' parameter
|
||||||
const [password, passwordErr] = $.str.get(params.password);
|
const [password, passwordErr] = $.str.get(params.password);
|
||||||
if (passwordErr) return rej('invalid password param');
|
if (passwordErr) return rej('invalid password param');
|
||||||
|
@ -6,17 +6,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get authorized apps of my account
|
* Get authorized apps of my account
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Get 'sort' parameter
|
// Get 'sort' parameter
|
||||||
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
|
const [sort = 'desc', sortError] = $.str.optional.or('desc asc').get(params.sort);
|
||||||
if (sortError) return rej('invalid sort param');
|
if (sortError) return rej('invalid sort param');
|
||||||
|
|
||||||
// Get tokens
|
// Get tokens
|
||||||
|
@ -5,7 +5,7 @@ import User, { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Change password
|
* Change password
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'currentPasword' parameter
|
// Get 'currentPasword' parameter
|
||||||
const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
|
const [currentPassword, currentPasswordErr] = $.str.get(params.currentPasword);
|
||||||
if (currentPasswordErr) return rej('invalid currentPasword param');
|
if (currentPasswordErr) return rej('invalid currentPasword param');
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get favorited notes
|
* Get favorited notes
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -9,30 +9,30 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get notifications
|
* Get notifications
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'following' parameter
|
// Get 'following' parameter
|
||||||
const [following = false, followingError] =
|
const [following = false, followingError] =
|
||||||
$.bool.optional().get(params.following);
|
$.bool.optional.get(params.following);
|
||||||
if (followingError) return rej('invalid following param');
|
if (followingError) return rej('invalid following param');
|
||||||
|
|
||||||
// Get 'markAsRead' parameter
|
// Get 'markAsRead' parameter
|
||||||
const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead);
|
const [markAsRead = true, markAsReadErr] = $.bool.optional.get(params.markAsRead);
|
||||||
if (markAsReadErr) return rej('invalid markAsRead param');
|
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||||
|
|
||||||
// Get 'type' parameter
|
// Get 'type' parameter
|
||||||
const [type, typeErr] = $.arr($.str).optional().unique().get(params.type);
|
const [type, typeErr] = $.arr($.str).optional.unique().get(params.type);
|
||||||
if (typeErr) return rej('invalid type param');
|
if (typeErr) return rej('invalid type param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -6,7 +6,7 @@ import { pack } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Pin note
|
* Pin note
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -7,7 +7,7 @@ import generateUserToken from '../../common/generate-native-user-token';
|
|||||||
/**
|
/**
|
||||||
* Regenerate native token
|
* Regenerate native token
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'password' parameter
|
// Get 'password' parameter
|
||||||
const [password, passwordErr] = $.str.get(params.password);
|
const [password, passwordErr] = $.str.get(params.password);
|
||||||
if (passwordErr) return rej('invalid password param');
|
if (passwordErr) return rej('invalid password param');
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get signin history of my account
|
* Get signin history of my account
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -8,63 +8,63 @@ import { IApp } from '../../../../models/app';
|
|||||||
/**
|
/**
|
||||||
* Update myself
|
* Update myself
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||||
const isSecure = user != null && app == null;
|
const isSecure = user != null && app == null;
|
||||||
|
|
||||||
const updates = {} as any;
|
const updates = {} as any;
|
||||||
|
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $.str.optional().nullable().pipe(isValidName).get(params.name);
|
const [name, nameErr] = $.str.optional.nullable.pipe(isValidName).get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
if (name) updates.name = name;
|
if (name) updates.name = name;
|
||||||
|
|
||||||
// Get 'description' parameter
|
// Get 'description' parameter
|
||||||
const [description, descriptionErr] = $.str.optional().nullable().pipe(isValidDescription).get(params.description);
|
const [description, descriptionErr] = $.str.optional.nullable.pipe(isValidDescription).get(params.description);
|
||||||
if (descriptionErr) return rej('invalid description param');
|
if (descriptionErr) return rej('invalid description param');
|
||||||
if (description !== undefined) updates.description = description;
|
if (description !== undefined) updates.description = description;
|
||||||
|
|
||||||
// Get 'location' parameter
|
// Get 'location' parameter
|
||||||
const [location, locationErr] = $.str.optional().nullable().pipe(isValidLocation).get(params.location);
|
const [location, locationErr] = $.str.optional.nullable.pipe(isValidLocation).get(params.location);
|
||||||
if (locationErr) return rej('invalid location param');
|
if (locationErr) return rej('invalid location param');
|
||||||
if (location !== undefined) updates['profile.location'] = location;
|
if (location !== undefined) updates['profile.location'] = location;
|
||||||
|
|
||||||
// Get 'birthday' parameter
|
// Get 'birthday' parameter
|
||||||
const [birthday, birthdayErr] = $.str.optional().nullable().pipe(isValidBirthday).get(params.birthday);
|
const [birthday, birthdayErr] = $.str.optional.nullable.pipe(isValidBirthday).get(params.birthday);
|
||||||
if (birthdayErr) return rej('invalid birthday param');
|
if (birthdayErr) return rej('invalid birthday param');
|
||||||
if (birthday !== undefined) updates['profile.birthday'] = birthday;
|
if (birthday !== undefined) updates['profile.birthday'] = birthday;
|
||||||
|
|
||||||
// Get 'avatarId' parameter
|
// Get 'avatarId' parameter
|
||||||
const [avatarId, avatarIdErr] = $.type(ID).optional().nullable().get(params.avatarId);
|
const [avatarId, avatarIdErr] = $.type(ID).optional.nullable.get(params.avatarId);
|
||||||
if (avatarIdErr) return rej('invalid avatarId param');
|
if (avatarIdErr) return rej('invalid avatarId param');
|
||||||
if (avatarId !== undefined) updates.avatarId = avatarId;
|
if (avatarId !== undefined) updates.avatarId = avatarId;
|
||||||
|
|
||||||
// Get 'bannerId' parameter
|
// Get 'bannerId' parameter
|
||||||
const [bannerId, bannerIdErr] = $.type(ID).optional().nullable().get(params.bannerId);
|
const [bannerId, bannerIdErr] = $.type(ID).optional.nullable.get(params.bannerId);
|
||||||
if (bannerIdErr) return rej('invalid bannerId param');
|
if (bannerIdErr) return rej('invalid bannerId param');
|
||||||
if (bannerId !== undefined) updates.bannerId = bannerId;
|
if (bannerId !== undefined) updates.bannerId = bannerId;
|
||||||
|
|
||||||
// Get 'wallpaperId' parameter
|
// Get 'wallpaperId' parameter
|
||||||
const [wallpaperId, wallpaperIdErr] = $.type(ID).optional().nullable().get(params.wallpaperId);
|
const [wallpaperId, wallpaperIdErr] = $.type(ID).optional.nullable.get(params.wallpaperId);
|
||||||
if (wallpaperIdErr) return rej('invalid wallpaperId param');
|
if (wallpaperIdErr) return rej('invalid wallpaperId param');
|
||||||
if (wallpaperId !== undefined) updates.wallpaperId = wallpaperId;
|
if (wallpaperId !== undefined) updates.wallpaperId = wallpaperId;
|
||||||
|
|
||||||
// Get 'isLocked' parameter
|
// Get 'isLocked' parameter
|
||||||
const [isLocked, isLockedErr] = $.bool.optional().get(params.isLocked);
|
const [isLocked, isLockedErr] = $.bool.optional.get(params.isLocked);
|
||||||
if (isLockedErr) return rej('invalid isLocked param');
|
if (isLockedErr) return rej('invalid isLocked param');
|
||||||
if (isLocked != null) updates.isLocked = isLocked;
|
if (isLocked != null) updates.isLocked = isLocked;
|
||||||
|
|
||||||
// Get 'isBot' parameter
|
// Get 'isBot' parameter
|
||||||
const [isBot, isBotErr] = $.bool.optional().get(params.isBot);
|
const [isBot, isBotErr] = $.bool.optional.get(params.isBot);
|
||||||
if (isBotErr) return rej('invalid isBot param');
|
if (isBotErr) return rej('invalid isBot param');
|
||||||
if (isBot != null) updates.isBot = isBot;
|
if (isBot != null) updates.isBot = isBot;
|
||||||
|
|
||||||
// Get 'isCat' parameter
|
// Get 'isCat' parameter
|
||||||
const [isCat, isCatErr] = $.bool.optional().get(params.isCat);
|
const [isCat, isCatErr] = $.bool.optional.get(params.isCat);
|
||||||
if (isCatErr) return rej('invalid isCat param');
|
if (isCatErr) return rej('invalid isCat param');
|
||||||
if (isCat != null) updates.isCat = isCat;
|
if (isCat != null) updates.isCat = isCat;
|
||||||
|
|
||||||
// Get 'autoWatch' parameter
|
// Get 'autoWatch' parameter
|
||||||
const [autoWatch, autoWatchErr] = $.bool.optional().get(params.autoWatch);
|
const [autoWatch, autoWatchErr] = $.bool.optional.get(params.autoWatch);
|
||||||
if (autoWatchErr) return rej('invalid autoWatch param');
|
if (autoWatchErr) return rej('invalid autoWatch param');
|
||||||
if (autoWatch != null) updates['settings.autoWatch'] = autoWatch;
|
if (autoWatch != null) updates['settings.autoWatch'] = autoWatch;
|
||||||
|
|
||||||
|
@ -5,13 +5,13 @@ import event from '../../../../publishers/stream';
|
|||||||
/**
|
/**
|
||||||
* Update myself
|
* Update myself
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $.str.get(params.name);
|
const [name, nameErr] = $.str.get(params.name);
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'value' parameter
|
// Get 'value' parameter
|
||||||
const [value, valueErr] = $.any.nullable().get(params.value);
|
const [value, valueErr] = $.any.nullable.get(params.value);
|
||||||
if (valueErr) return rej('invalid value param');
|
if (valueErr) return rej('invalid value param');
|
||||||
|
|
||||||
const x: any = {};
|
const x: any = {};
|
||||||
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
|||||||
import User, { ILocalUser } from '../../../../models/user';
|
import User, { ILocalUser } from '../../../../models/user';
|
||||||
import event from '../../../../publishers/stream';
|
import event from '../../../../publishers/stream';
|
||||||
|
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'home' parameter
|
// Get 'home' parameter
|
||||||
const [home, homeErr] = $.arr(
|
const [home, homeErr] = $.arr(
|
||||||
$.obj.strict()
|
$.obj.strict()
|
||||||
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
|||||||
import User, { ILocalUser } from '../../../../models/user';
|
import User, { ILocalUser } from '../../../../models/user';
|
||||||
import event from '../../../../publishers/stream';
|
import event from '../../../../publishers/stream';
|
||||||
|
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'home' parameter
|
// Get 'home' parameter
|
||||||
const [home, homeErr] = $.arr(
|
const [home, homeErr] = $.arr(
|
||||||
$.obj.strict()
|
$.obj.strict()
|
||||||
|
@ -2,7 +2,7 @@ import $ from 'cafy';
|
|||||||
import User, { ILocalUser } from '../../../../models/user';
|
import User, { ILocalUser } from '../../../../models/user';
|
||||||
import event from '../../../../publishers/stream';
|
import event from '../../../../publishers/stream';
|
||||||
|
|
||||||
module.exports = async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default async (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'id' parameter
|
// Get 'id' parameter
|
||||||
const [id, idErr] = $.str.get(params.id);
|
const [id, idErr] = $.str.get(params.id);
|
||||||
if (idErr) return rej('invalid id param');
|
if (idErr) return rej('invalid id param');
|
||||||
|
@ -7,9 +7,9 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show messaging history
|
* Show messaging history
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
|
@ -7,7 +7,7 @@ import read from '../../common/read-messaging-message';
|
|||||||
/**
|
/**
|
||||||
* Get messages
|
* Get messages
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
|
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
|
||||||
if (recipientIdErr) return rej('invalid userId param');
|
if (recipientIdErr) return rej('invalid userId param');
|
||||||
@ -26,19 +26,19 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'markAsRead' parameter
|
// Get 'markAsRead' parameter
|
||||||
const [markAsRead = true, markAsReadErr] = $.bool.optional().get(params.markAsRead);
|
const [markAsRead = true, markAsReadErr] = $.bool.optional.get(params.markAsRead);
|
||||||
if (markAsReadErr) return rej('invalid markAsRead param');
|
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -14,7 +14,7 @@ import config from '../../../../../config';
|
|||||||
/**
|
/**
|
||||||
* Create a message
|
* Create a message
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
|
const [recipientId, recipientIdErr] = $.type(ID).get(params.userId);
|
||||||
if (recipientIdErr) return rej('invalid userId param');
|
if (recipientIdErr) return rej('invalid userId param');
|
||||||
@ -38,11 +38,11 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'text' parameter
|
// Get 'text' parameter
|
||||||
const [text, textErr] = $.str.optional().pipe(isValidText).get(params.text);
|
const [text, textErr] = $.str.optional.pipe(isValidText).get(params.text);
|
||||||
if (textErr) return rej('invalid text');
|
if (textErr) return rej('invalid text');
|
||||||
|
|
||||||
// Get 'fileId' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $.type(ID).optional().get(params.fileId);
|
const [fileId, fileIdErr] = $.type(ID).optional.get(params.fileId);
|
||||||
if (fileIdErr) return rej('invalid fileId param');
|
if (fileIdErr) return rej('invalid fileId param');
|
||||||
|
|
||||||
let file = null;
|
let file = null;
|
||||||
|
@ -38,7 +38,7 @@ const client = require('../../../../built/client/meta.json');
|
|||||||
/**
|
/**
|
||||||
* Show core info
|
* Show core info
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default () => new Promise(async (res, rej) => {
|
||||||
const meta: any = (await Meta.findOne()) || {};
|
const meta: any = (await Meta.findOne()) || {};
|
||||||
|
|
||||||
res({
|
res({
|
||||||
|
@ -5,7 +5,7 @@ import Mute from '../../../../models/mute';
|
|||||||
/**
|
/**
|
||||||
* Mute a user
|
* Mute a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const muter = user;
|
const muter = user;
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -5,7 +5,7 @@ import Mute from '../../../../models/mute';
|
|||||||
/**
|
/**
|
||||||
* Unmute a user
|
* Unmute a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
const muter = user;
|
const muter = user;
|
||||||
|
|
||||||
// Get 'userId' parameter
|
// Get 'userId' parameter
|
||||||
|
@ -6,17 +6,17 @@ import { getFriendIds } from '../../common/get-friends';
|
|||||||
/**
|
/**
|
||||||
* Get muted users of a user
|
* Get muted users of a user
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'iknow' parameter
|
// Get 'iknow' parameter
|
||||||
const [iknow = false, iknowErr] = $.bool.optional().get(params.iknow);
|
const [iknow = false, iknowErr] = $.bool.optional.get(params.iknow);
|
||||||
if (iknowErr) return rej('invalid iknow param');
|
if (iknowErr) return rej('invalid iknow param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 30, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 30, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'cursor' parameter
|
// Get 'cursor' parameter
|
||||||
const [cursor = null, cursorErr] = $.type(ID).optional().get(params.cursor);
|
const [cursor = null, cursorErr] = $.type(ID).optional.get(params.cursor);
|
||||||
if (cursorErr) return rej('invalid cursor param');
|
if (cursorErr) return rej('invalid cursor param');
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
@ -5,13 +5,13 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get my apps
|
* Get my apps
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
|
@ -7,41 +7,41 @@ import Note, { pack } from '../../../models/note';
|
|||||||
/**
|
/**
|
||||||
* Get all notes
|
* Get all notes
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any) => new Promise(async (res, rej) => {
|
export default (params: any) => new Promise(async (res, rej) => {
|
||||||
// Get 'local' parameter
|
// Get 'local' parameter
|
||||||
const [local, localErr] = $.bool.optional().get(params.local);
|
const [local, localErr] = $.bool.optional.get(params.local);
|
||||||
if (localErr) return rej('invalid local param');
|
if (localErr) return rej('invalid local param');
|
||||||
|
|
||||||
// Get 'reply' parameter
|
// Get 'reply' parameter
|
||||||
const [reply, replyErr] = $.bool.optional().get(params.reply);
|
const [reply, replyErr] = $.bool.optional.get(params.reply);
|
||||||
if (replyErr) return rej('invalid reply param');
|
if (replyErr) return rej('invalid reply param');
|
||||||
|
|
||||||
// Get 'renote' parameter
|
// Get 'renote' parameter
|
||||||
const [renote, renoteErr] = $.bool.optional().get(params.renote);
|
const [renote, renoteErr] = $.bool.optional.get(params.renote);
|
||||||
if (renoteErr) return rej('invalid renote param');
|
if (renoteErr) return rej('invalid renote param');
|
||||||
|
|
||||||
// Get 'media' parameter
|
// Get 'media' parameter
|
||||||
const [media, mediaErr] = $.bool.optional().get(params.media);
|
const [media, mediaErr] = $.bool.optional.get(params.media);
|
||||||
if (mediaErr) return rej('invalid media param');
|
if (mediaErr) return rej('invalid media param');
|
||||||
|
|
||||||
// Get 'poll' parameter
|
// Get 'poll' parameter
|
||||||
const [poll, pollErr] = $.bool.optional().get(params.poll);
|
const [poll, pollErr] = $.bool.optional.get(params.poll);
|
||||||
if (pollErr) return rej('invalid poll param');
|
if (pollErr) return rej('invalid poll param');
|
||||||
|
|
||||||
// Get 'bot' parameter
|
// Get 'bot' parameter
|
||||||
//const [bot, botErr] = $.bool.optional().get(params.bot);
|
//const [bot, botErr] = $.bool.optional.get(params.bot);
|
||||||
//if (botErr) return rej('invalid bot param');
|
//if (botErr) return rej('invalid bot param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show conversation of a note
|
* Show conversation of a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Lookup note
|
// Lookup note
|
||||||
|
@ -1,68 +1,126 @@
|
|||||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||||
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
|
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
|
||||||
import User, { ILocalUser, IUser } from '../../../../models/user';
|
import User, { ILocalUser, IUser } from '../../../../models/user';
|
||||||
import DriveFile from '../../../../models/drive-file';
|
import DriveFile, { IDriveFile } from '../../../../models/drive-file';
|
||||||
import create from '../../../../services/note/create';
|
import create from '../../../../services/note/create';
|
||||||
import { IApp } from '../../../../models/app';
|
import { IApp } from '../../../../models/app';
|
||||||
|
import getParams from '../../get-params';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
name: 'notes/create',
|
||||||
|
|
||||||
|
desc: {
|
||||||
|
ja: '投稿します。'
|
||||||
|
},
|
||||||
|
|
||||||
|
params: {
|
||||||
|
visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({
|
||||||
|
default: 'public',
|
||||||
|
desc: {
|
||||||
|
ja: '投稿の公開範囲'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
visibleUserIds: $.arr($.type(ID)).optional.unique().min(1).note({
|
||||||
|
desc: {
|
||||||
|
ja: '(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
text: $.str.optional.nullable.pipe(isValidText).note({
|
||||||
|
default: null,
|
||||||
|
desc: {
|
||||||
|
ja: '投稿内容'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
cw: $.str.optional.nullable.pipe(isValidCw).note({
|
||||||
|
desc: {
|
||||||
|
ja: 'コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
viaMobile: $.bool.optional.note({
|
||||||
|
default: false,
|
||||||
|
desc: {
|
||||||
|
ja: 'モバイルデバイスからの投稿か否か。'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
geo: $.obj({
|
||||||
|
coordinates: $.arr().length(2)
|
||||||
|
.item(0, $.num.range(-180, 180))
|
||||||
|
.item(1, $.num.range(-90, 90)),
|
||||||
|
altitude: $.num.nullable,
|
||||||
|
accuracy: $.num.nullable,
|
||||||
|
altitudeAccuracy: $.num.nullable,
|
||||||
|
heading: $.num.nullable.range(0, 360),
|
||||||
|
speed: $.num.nullable
|
||||||
|
}).optional.nullable.strict().note({
|
||||||
|
desc: {
|
||||||
|
ja: '位置情報'
|
||||||
|
},
|
||||||
|
ref: 'geo'
|
||||||
|
}),
|
||||||
|
|
||||||
|
mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({
|
||||||
|
desc: {
|
||||||
|
ja: '添付するメディア'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
renoteId: $.type(ID).optional.note({
|
||||||
|
desc: {
|
||||||
|
ja: 'Renote対象'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
poll: $.obj({
|
||||||
|
choices: $.arr($.str)
|
||||||
|
.unique()
|
||||||
|
.range(2, 10)
|
||||||
|
.each(c => c.length > 0 && c.length < 50)
|
||||||
|
}).optional.strict().note({
|
||||||
|
desc: {
|
||||||
|
ja: 'アンケート'
|
||||||
|
},
|
||||||
|
ref: 'poll'
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
res: {
|
||||||
|
type: 'object',
|
||||||
|
object: {
|
||||||
|
createdNote: {
|
||||||
|
type: 'entity(Note)',
|
||||||
|
desc: {
|
||||||
|
ja: '作成した投稿'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a note
|
* Create a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||||
// Get 'visibility' parameter
|
const [ps, psErr] = getParams(meta, params);
|
||||||
const [visibility = 'public', visibilityErr] = $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']).get(params.visibility);
|
if (psErr) return rej(psErr);
|
||||||
if (visibilityErr) return rej('invalid visibility');
|
|
||||||
|
|
||||||
// Get 'visibleUserIds' parameter
|
|
||||||
const [visibleUserIds, visibleUserIdsErr] = $.arr($.type(ID)).optional().unique().min(1).get(params.visibleUserIds);
|
|
||||||
if (visibleUserIdsErr) return rej('invalid visibleUserIds');
|
|
||||||
|
|
||||||
let visibleUsers: IUser[] = [];
|
let visibleUsers: IUser[] = [];
|
||||||
if (visibleUserIds !== undefined) {
|
if (ps.visibleUserIds !== undefined) {
|
||||||
visibleUsers = await Promise.all(visibleUserIds.map(id => User.findOne({
|
visibleUsers = await Promise.all(ps.visibleUserIds.map(id => User.findOne({
|
||||||
_id: id
|
_id: id
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'text' parameter
|
let files: IDriveFile[] = [];
|
||||||
const [text = null, textErr] = $.str.optional().nullable().pipe(isValidText).get(params.text);
|
if (ps.mediaIds !== undefined) {
|
||||||
if (textErr) return rej('invalid text');
|
|
||||||
|
|
||||||
// Get 'cw' parameter
|
|
||||||
const [cw, cwErr] = $.str.optional().nullable().pipe(isValidCw).get(params.cw);
|
|
||||||
if (cwErr) return rej('invalid cw');
|
|
||||||
|
|
||||||
// Get 'viaMobile' parameter
|
|
||||||
const [viaMobile = false, viaMobileErr] = $.bool.optional().get(params.viaMobile);
|
|
||||||
if (viaMobileErr) return rej('invalid viaMobile');
|
|
||||||
|
|
||||||
// Get 'tags' parameter
|
|
||||||
const [tags = [], tagsErr] = $.arr($.str.range(1, 32)).optional().unique().get(params.tags);
|
|
||||||
if (tagsErr) return rej('invalid tags');
|
|
||||||
|
|
||||||
// Get 'geo' parameter
|
|
||||||
const [geo, geoErr] = $.obj.optional().nullable().strict()
|
|
||||||
.have('coordinates', $.arr().length(2)
|
|
||||||
.item(0, $.num.range(-180, 180))
|
|
||||||
.item(1, $.num.range(-90, 90)))
|
|
||||||
.have('altitude', $.num.nullable())
|
|
||||||
.have('accuracy', $.num.nullable())
|
|
||||||
.have('altitudeAccuracy', $.num.nullable())
|
|
||||||
.have('heading', $.num.nullable().range(0, 360))
|
|
||||||
.have('speed', $.num.nullable())
|
|
||||||
.get(params.geo);
|
|
||||||
if (geoErr) return rej('invalid geo');
|
|
||||||
|
|
||||||
// Get 'mediaIds' parameter
|
|
||||||
const [mediaIds, mediaIdsErr] = $.arr($.type(ID)).optional().unique().range(1, 4).get(params.mediaIds);
|
|
||||||
if (mediaIdsErr) return rej('invalid mediaIds');
|
|
||||||
|
|
||||||
let files = [];
|
|
||||||
if (mediaIds !== undefined) {
|
|
||||||
// Fetch files
|
// Fetch files
|
||||||
// forEach だと途中でエラーなどがあっても return できないので
|
// forEach だと途中でエラーなどがあっても return できないので
|
||||||
// 敢えて for を使っています。
|
// 敢えて for を使っています。
|
||||||
for (const mediaId of mediaIds) {
|
for (const mediaId of ps.mediaIds) {
|
||||||
// Fetch file
|
// Fetch file
|
||||||
// SELECT _id
|
// SELECT _id
|
||||||
const entity = await DriveFile.findOne({
|
const entity = await DriveFile.findOne({
|
||||||
@ -80,15 +138,11 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
|
|||||||
files = null;
|
files = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'renoteId' parameter
|
|
||||||
const [renoteId, renoteIdErr] = $.type(ID).optional().get(params.renoteId);
|
|
||||||
if (renoteIdErr) return rej('invalid renoteId');
|
|
||||||
|
|
||||||
let renote: INote = null;
|
let renote: INote = null;
|
||||||
if (renoteId !== undefined) {
|
if (ps.renoteId !== undefined) {
|
||||||
// Fetch renote to note
|
// Fetch renote to note
|
||||||
renote = await Note.findOne({
|
renote = await Note.findOne({
|
||||||
_id: renoteId
|
_id: ps.renoteId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (renote == null) {
|
if (renote == null) {
|
||||||
@ -99,7 +153,7 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'replyId' parameter
|
// Get 'replyId' parameter
|
||||||
const [replyId, replyIdErr] = $.type(ID).optional().get(params.replyId);
|
const [replyId, replyIdErr] = $.type(ID).optional.get(params.replyId);
|
||||||
if (replyIdErr) return rej('invalid replyId');
|
if (replyIdErr) return rej('invalid replyId');
|
||||||
|
|
||||||
let reply: INote = null;
|
let reply: INote = null;
|
||||||
@ -119,17 +173,8 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'poll' parameter
|
if (ps.poll) {
|
||||||
const [poll, pollErr] = $.obj.optional().strict()
|
(ps.poll as any).choices = (ps.poll as any).choices.map((choice: string, i: number) => ({
|
||||||
.have('choices', $.arr($.str)
|
|
||||||
.unique()
|
|
||||||
.range(2, 10)
|
|
||||||
.each(c => c.length > 0 && c.length < 50))
|
|
||||||
.get(params.poll);
|
|
||||||
if (pollErr) return rej('invalid poll');
|
|
||||||
|
|
||||||
if (poll) {
|
|
||||||
(poll as any).choices = (poll as any).choices.map((choice: string, i: number) => ({
|
|
||||||
id: i, // IDを付与
|
id: i, // IDを付与
|
||||||
text: choice.trim(),
|
text: choice.trim(),
|
||||||
votes: 0
|
votes: 0
|
||||||
@ -137,7 +182,7 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
|
|||||||
}
|
}
|
||||||
|
|
||||||
// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
|
// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
|
||||||
if ((text === undefined || text === null) && files === null && renote === null && poll === undefined) {
|
if ((ps.text === undefined || ps.text === null) && files === null && renote === null && ps.poll === undefined) {
|
||||||
return rej('text, mediaIds, renoteId or poll is required');
|
return rej('text, mediaIds, renoteId or poll is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,17 +190,16 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
|
|||||||
const note = await create(user, {
|
const note = await create(user, {
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
media: files,
|
media: files,
|
||||||
poll,
|
poll: ps.poll,
|
||||||
text,
|
text: ps.text,
|
||||||
reply,
|
reply,
|
||||||
renote,
|
renote,
|
||||||
cw,
|
cw: ps.cw,
|
||||||
tags,
|
|
||||||
app,
|
app,
|
||||||
viaMobile,
|
viaMobile: ps.viaMobile,
|
||||||
visibility,
|
visibility: ps.visibility,
|
||||||
visibleUsers,
|
visibleUsers,
|
||||||
geo
|
geo: ps.geo
|
||||||
});
|
});
|
||||||
|
|
||||||
const noteObj = await pack(note, user);
|
const noteObj = await pack(note, user);
|
||||||
|
@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Delete a note
|
* Delete a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Favorite a note
|
* Favorite a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Unfavorite a note
|
* Unfavorite a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -7,25 +7,25 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get timeline of global
|
* Get timeline of global
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => {
|
export default async (params: any, user: ILocalUser) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) throw 'invalid limit param';
|
if (limitErr) throw 'invalid limit param';
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) throw 'invalid sinceId param';
|
if (sinceIdErr) throw 'invalid sinceId param';
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) throw 'invalid untilId param';
|
if (untilIdErr) throw 'invalid untilId param';
|
||||||
|
|
||||||
// Get 'sinceDate' parameter
|
// Get 'sinceDate' parameter
|
||||||
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
|
const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
|
||||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||||
|
|
||||||
// Get 'untilDate' parameter
|
// Get 'untilDate' parameter
|
||||||
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
|
const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
|
||||||
if (untilDateErr) throw 'invalid untilDate param';
|
if (untilDateErr) throw 'invalid untilDate param';
|
||||||
|
|
||||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||||
@ -34,7 +34,7 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'mediaOnly' parameter
|
// Get 'mediaOnly' parameter
|
||||||
const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
|
const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
|
||||||
if (mediaOnlyErr) throw 'invalid mediaOnly param';
|
if (mediaOnlyErr) throw 'invalid mediaOnly param';
|
||||||
|
|
||||||
// ミュートしているユーザーを取得
|
// ミュートしているユーザーを取得
|
||||||
|
@ -7,25 +7,25 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get timeline of local
|
* Get timeline of local
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => {
|
export default async (params: any, user: ILocalUser) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) throw 'invalid limit param';
|
if (limitErr) throw 'invalid limit param';
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) throw 'invalid sinceId param';
|
if (sinceIdErr) throw 'invalid sinceId param';
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) throw 'invalid untilId param';
|
if (untilIdErr) throw 'invalid untilId param';
|
||||||
|
|
||||||
// Get 'sinceDate' parameter
|
// Get 'sinceDate' parameter
|
||||||
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
|
const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
|
||||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||||
|
|
||||||
// Get 'untilDate' parameter
|
// Get 'untilDate' parameter
|
||||||
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
|
const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
|
||||||
if (untilDateErr) throw 'invalid untilDate param';
|
if (untilDateErr) throw 'invalid untilDate param';
|
||||||
|
|
||||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||||
@ -34,7 +34,7 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get 'mediaOnly' parameter
|
// Get 'mediaOnly' parameter
|
||||||
const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
|
const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
|
||||||
if (mediaOnlyErr) throw 'invalid mediaOnly param';
|
if (mediaOnlyErr) throw 'invalid mediaOnly param';
|
||||||
|
|
||||||
// ミュートしているユーザーを取得
|
// ミュートしているユーザーを取得
|
||||||
|
@ -7,22 +7,22 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get mentions of myself
|
* Get mentions of myself
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'following' parameter
|
// Get 'following' parameter
|
||||||
const [following = false, followingError] =
|
const [following = false, followingError] =
|
||||||
$.bool.optional().get(params.following);
|
$.bool.optional.get(params.following);
|
||||||
if (followingError) return rej('invalid following param');
|
if (followingError) return rej('invalid following param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -6,13 +6,13 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get recommended polls
|
* Get recommended polls
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Get votes
|
// Get votes
|
||||||
|
@ -10,7 +10,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Vote poll of a note
|
* Vote poll of a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -6,21 +6,21 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show reactions of a note
|
* Show reactions of a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Get 'sort' parameter
|
// Get 'sort' parameter
|
||||||
const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
|
const [sort = 'desc', sortError] = $.str.optional.or('desc asc').get(params.sort);
|
||||||
if (sortError) return rej('invalid sort param');
|
if (sortError) return rej('invalid sort param');
|
||||||
|
|
||||||
// Lookup note
|
// Lookup note
|
||||||
|
@ -3,22 +3,40 @@ import Note from '../../../../../models/note';
|
|||||||
import create from '../../../../../services/note/reaction/create';
|
import create from '../../../../../services/note/reaction/create';
|
||||||
import { validateReaction } from '../../../../../models/note-reaction';
|
import { validateReaction } from '../../../../../models/note-reaction';
|
||||||
import { ILocalUser } from '../../../../../models/user';
|
import { ILocalUser } from '../../../../../models/user';
|
||||||
|
import getParams from '../../../get-params';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
name: 'notes/reactions/create',
|
||||||
|
|
||||||
|
desc: {
|
||||||
|
ja: '投稿にリアクションします。'
|
||||||
|
},
|
||||||
|
|
||||||
|
params: {
|
||||||
|
noteId: $.type(ID).note({
|
||||||
|
desc: {
|
||||||
|
ja: '対象の投稿'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
reaction: $.str.pipe(validateReaction.ok).note({
|
||||||
|
desc: {
|
||||||
|
ja: 'リアクションの種類'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* React to a note
|
* React to a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
const [ps, psErr] = getParams(meta, params);
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
if (psErr) return rej(psErr);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
|
||||||
|
|
||||||
// Get 'reaction' parameter
|
|
||||||
const [reaction, reactionErr] = $.str.pipe(validateReaction.ok).get(params.reaction);
|
|
||||||
if (reactionErr) return rej('invalid reaction param');
|
|
||||||
|
|
||||||
// Fetch reactee
|
// Fetch reactee
|
||||||
const note = await Note.findOne({
|
const note = await Note.findOne({
|
||||||
_id: noteId
|
_id: ps.noteId
|
||||||
});
|
});
|
||||||
|
|
||||||
if (note === null) {
|
if (note === null) {
|
||||||
@ -26,7 +44,7 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await create(user, note, reaction);
|
await create(user, note, ps.reaction);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rej(e);
|
rej(e);
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import { ILocalUser } from '../../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Unreact to a note
|
* Unreact to a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Get replies of a note
|
* Get replies of a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Lookup note
|
// Lookup note
|
||||||
|
@ -5,21 +5,21 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show a renotes of a note
|
* Show a renotes of a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
|
||||||
if (sinceIdErr) return rej('invalid sinceId param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
|
||||||
if (untilIdErr) return rej('invalid untilId param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of sinceId and untilId is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
|
@ -5,17 +5,17 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
import { pack } from '../../../../models/note';
|
import { pack } from '../../../../models/note';
|
||||||
import es from '../../../../db/elasticsearch';
|
import es from '../../../../db/elasticsearch';
|
||||||
|
|
||||||
module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'query' parameter
|
// Get 'query' parameter
|
||||||
const [query, queryError] = $.str.get(params.query);
|
const [query, queryError] = $.str.get(params.query);
|
||||||
if (queryError) return rej('invalid query param');
|
if (queryError) return rej('invalid query param');
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
es.search({
|
es.search({
|
||||||
|
@ -8,65 +8,65 @@ import { pack } from '../../../../models/note';
|
|||||||
/**
|
/**
|
||||||
* Search notes by tag
|
* Search notes by tag
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, me: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'tag' parameter
|
// Get 'tag' parameter
|
||||||
const [tag, tagError] = $.str.get(params.tag);
|
const [tag, tagError] = $.str.get(params.tag);
|
||||||
if (tagError) return rej('invalid tag param');
|
if (tagError) return rej('invalid tag param');
|
||||||
|
|
||||||
// Get 'includeUserIds' parameter
|
// Get 'includeUserIds' parameter
|
||||||
const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional().get(params.includeUserIds);
|
const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional.get(params.includeUserIds);
|
||||||
if (includeUserIdsErr) return rej('invalid includeUserIds param');
|
if (includeUserIdsErr) return rej('invalid includeUserIds param');
|
||||||
|
|
||||||
// Get 'excludeUserIds' parameter
|
// Get 'excludeUserIds' parameter
|
||||||
const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional().get(params.excludeUserIds);
|
const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional.get(params.excludeUserIds);
|
||||||
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
|
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
|
||||||
|
|
||||||
// Get 'includeUserUsernames' parameter
|
// Get 'includeUserUsernames' parameter
|
||||||
const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional().get(params.includeUserUsernames);
|
const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional.get(params.includeUserUsernames);
|
||||||
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
|
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
|
||||||
|
|
||||||
// Get 'excludeUserUsernames' parameter
|
// Get 'excludeUserUsernames' parameter
|
||||||
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional().get(params.excludeUserUsernames);
|
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional.get(params.excludeUserUsernames);
|
||||||
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
|
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
|
||||||
|
|
||||||
// Get 'following' parameter
|
// Get 'following' parameter
|
||||||
const [following = null, followingErr] = $.bool.optional().nullable().get(params.following);
|
const [following = null, followingErr] = $.bool.optional.nullable.get(params.following);
|
||||||
if (followingErr) return rej('invalid following param');
|
if (followingErr) return rej('invalid following param');
|
||||||
|
|
||||||
// Get 'mute' parameter
|
// Get 'mute' parameter
|
||||||
const [mute = 'mute_all', muteErr] = $.str.optional().get(params.mute);
|
const [mute = 'mute_all', muteErr] = $.str.optional.get(params.mute);
|
||||||
if (muteErr) return rej('invalid mute param');
|
if (muteErr) return rej('invalid mute param');
|
||||||
|
|
||||||
// Get 'reply' parameter
|
// Get 'reply' parameter
|
||||||
const [reply = null, replyErr] = $.bool.optional().nullable().get(params.reply);
|
const [reply = null, replyErr] = $.bool.optional.nullable.get(params.reply);
|
||||||
if (replyErr) return rej('invalid reply param');
|
if (replyErr) return rej('invalid reply param');
|
||||||
|
|
||||||
// Get 'renote' parameter
|
// Get 'renote' parameter
|
||||||
const [renote = null, renoteErr] = $.bool.optional().nullable().get(params.renote);
|
const [renote = null, renoteErr] = $.bool.optional.nullable.get(params.renote);
|
||||||
if (renoteErr) return rej('invalid renote param');
|
if (renoteErr) return rej('invalid renote param');
|
||||||
|
|
||||||
// Get 'media' parameter
|
// Get 'media' parameter
|
||||||
const [media = null, mediaErr] = $.bool.optional().nullable().get(params.media);
|
const [media = null, mediaErr] = $.bool.optional.nullable.get(params.media);
|
||||||
if (mediaErr) return rej('invalid media param');
|
if (mediaErr) return rej('invalid media param');
|
||||||
|
|
||||||
// Get 'poll' parameter
|
// Get 'poll' parameter
|
||||||
const [poll = null, pollErr] = $.bool.optional().nullable().get(params.poll);
|
const [poll = null, pollErr] = $.bool.optional.nullable.get(params.poll);
|
||||||
if (pollErr) return rej('invalid poll param');
|
if (pollErr) return rej('invalid poll param');
|
||||||
|
|
||||||
// Get 'sinceDate' parameter
|
// Get 'sinceDate' parameter
|
||||||
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
|
const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
|
||||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||||
|
|
||||||
// Get 'untilDate' parameter
|
// Get 'untilDate' parameter
|
||||||
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
|
const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
|
||||||
if (untilDateErr) throw 'invalid untilDate param';
|
if (untilDateErr) throw 'invalid untilDate param';
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
|
const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit);
|
const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
if (includeUserUsernames != null) {
|
if (includeUserUsernames != null) {
|
||||||
|
@ -5,7 +5,7 @@ import { ILocalUser } from '../../../../models/user';
|
|||||||
/**
|
/**
|
||||||
* Show a note
|
* Show a note
|
||||||
*/
|
*/
|
||||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'noteId' parameter
|
// Get 'noteId' parameter
|
||||||
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
const [noteId, noteIdErr] = $.type(ID).get(params.noteId);
|
||||||
if (noteIdErr) return rej('invalid noteId param');
|
if (noteIdErr) return rej('invalid noteId param');
|
||||||
|
@ -4,48 +4,81 @@ import Mute from '../../../../models/mute';
|
|||||||
import { getFriends } from '../../common/get-friends';
|
import { getFriends } from '../../common/get-friends';
|
||||||
import { pack } from '../../../../models/note';
|
import { pack } from '../../../../models/note';
|
||||||
import { ILocalUser } from '../../../../models/user';
|
import { ILocalUser } from '../../../../models/user';
|
||||||
|
import getParams from '../../get-params';
|
||||||
|
|
||||||
|
export const meta = {
|
||||||
|
name: 'notes/timeline',
|
||||||
|
|
||||||
|
desc: {
|
||||||
|
ja: 'タイムラインを取得します。'
|
||||||
|
},
|
||||||
|
|
||||||
|
params: {
|
||||||
|
limit: $.num.optional.range(1, 100).note({
|
||||||
|
default: 10,
|
||||||
|
desc: {
|
||||||
|
ja: '最大数'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
sinceId: $.type(ID).optional.note({
|
||||||
|
desc: {
|
||||||
|
ja: '指定すると、この投稿を基点としてより新しい投稿を取得します'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
untilId: $.type(ID).optional.note({
|
||||||
|
desc: {
|
||||||
|
ja: '指定すると、この投稿を基点としてより古い投稿を取得します'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
sinceDate: $.num.optional.note({
|
||||||
|
desc: {
|
||||||
|
ja: '指定した時間を基点としてより新しい投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
untilDate: $.num.optional.note({
|
||||||
|
desc: {
|
||||||
|
ja: '指定した時間を基点としてより古い投稿を取得します。数値は、1970年1月1日 00:00:00 UTC から指定した日時までの経過時間をミリ秒単位で表します。'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
includeMyRenotes: $.bool.optional.note({
|
||||||
|
default: true,
|
||||||
|
desc: {
|
||||||
|
ja: '自分の行ったRenoteを含めるかどうか'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
includeRenotedMyNotes: $.bool.optional.note({
|
||||||
|
default: true,
|
||||||
|
desc: {
|
||||||
|
ja: 'Renoteされた自分の投稿を含めるかどうか'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
|
mediaOnly: $.bool.optional.note({
|
||||||
|
desc: {
|
||||||
|
ja: 'true にすると、メディアが添付された投稿だけ取得します'
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get timeline of myself
|
* Get timeline of myself
|
||||||
*/
|
*/
|
||||||
module.exports = async (params: any, user: ILocalUser) => {
|
export default async (params: any, user: ILocalUser) => {
|
||||||
// Get 'limit' parameter
|
const [ps, psErr] = getParams(meta, params);
|
||||||
const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
|
if (psErr) throw psErr;
|
||||||
if (limitErr) throw 'invalid limit param';
|
|
||||||
|
|
||||||
// Get 'sinceId' parameter
|
|
||||||
const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
|
|
||||||
if (sinceIdErr) throw 'invalid sinceId param';
|
|
||||||
|
|
||||||
// Get 'untilId' parameter
|
|
||||||
const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
|
|
||||||
if (untilIdErr) throw 'invalid untilId param';
|
|
||||||
|
|
||||||
// Get 'sinceDate' parameter
|
|
||||||
const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
|
|
||||||
if (sinceDateErr) throw 'invalid sinceDate param';
|
|
||||||
|
|
||||||
// Get 'untilDate' parameter
|
|
||||||
const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
|
|
||||||
if (untilDateErr) throw 'invalid untilDate param';
|
|
||||||
|
|
||||||
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||||
if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
|
if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
|
||||||
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'includeMyRenotes' parameter
|
|
||||||
const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes);
|
|
||||||
if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
|
|
||||||
|
|
||||||
// Get 'includeRenotedMyNotes' parameter
|
|
||||||
const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
|
|
||||||
if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
|
|
||||||
|
|
||||||
// Get 'mediaOnly' parameter
|
|
||||||
const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
|
|
||||||
if (mediaOnlyErr) throw 'invalid mediaOnly param';
|
|
||||||
|
|
||||||
const [followings, mutedUserIds] = await Promise.all([
|
const [followings, mutedUserIds] = await Promise.all([
|
||||||
// フォローを取得
|
// フォローを取得
|
||||||
// Fetch following
|
// Fetch following
|
||||||
@ -107,7 +140,7 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
// つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
|
// つまり、「『自分の投稿かつRenote』ではない」を「『自分の投稿ではない』または『Renoteではない』」と表現します。
|
||||||
// for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
|
// for details: https://en.wikipedia.org/wiki/De_Morgan%27s_laws
|
||||||
|
|
||||||
if (includeMyRenotes === false) {
|
if (ps.includeMyRenotes === false) {
|
||||||
query.$and.push({
|
query.$and.push({
|
||||||
$or: [{
|
$or: [{
|
||||||
userId: { $ne: user._id }
|
userId: { $ne: user._id }
|
||||||
@ -123,7 +156,7 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (includeRenotedMyNotes === false) {
|
if (ps.includeRenotedMyNotes === false) {
|
||||||
query.$and.push({
|
query.$and.push({
|
||||||
$or: [{
|
$or: [{
|
||||||
'_renote.userId': { $ne: user._id }
|
'_renote.userId': { $ne: user._id }
|
||||||
@ -139,29 +172,29 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mediaOnly) {
|
if (ps.mediaOnly) {
|
||||||
query.$and.push({
|
query.$and.push({
|
||||||
mediaIds: { $exists: true, $ne: [] }
|
mediaIds: { $exists: true, $ne: [] }
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sinceId) {
|
if (ps.sinceId) {
|
||||||
sort._id = 1;
|
sort._id = 1;
|
||||||
query._id = {
|
query._id = {
|
||||||
$gt: sinceId
|
$gt: ps.sinceId
|
||||||
};
|
};
|
||||||
} else if (untilId) {
|
} else if (ps.untilId) {
|
||||||
query._id = {
|
query._id = {
|
||||||
$lt: untilId
|
$lt: ps.untilId
|
||||||
};
|
};
|
||||||
} else if (sinceDate) {
|
} else if (ps.sinceDate) {
|
||||||
sort._id = 1;
|
sort._id = 1;
|
||||||
query.createdAt = {
|
query.createdAt = {
|
||||||
$gt: new Date(sinceDate)
|
$gt: new Date(ps.sinceDate)
|
||||||
};
|
};
|
||||||
} else if (untilDate) {
|
} else if (ps.untilDate) {
|
||||||
query.createdAt = {
|
query.createdAt = {
|
||||||
$lt: new Date(untilDate)
|
$lt: new Date(ps.untilDate)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -169,7 +202,7 @@ module.exports = async (params: any, user: ILocalUser) => {
|
|||||||
// Issue query
|
// Issue query
|
||||||
const timeline = await Note
|
const timeline = await Note
|
||||||
.find(query, {
|
.find(query, {
|
||||||
limit: limit,
|
limit: ps.limit,
|
||||||
sort: sort
|
sort: sort
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user