wip
This commit is contained in:
		@@ -11,11 +11,11 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Lookup note
 | 
			
		||||
 
 | 
			
		||||
@@ -1,33 +1,83 @@
 | 
			
		||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
 | 
			
		||||
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
 | 
			
		||||
import User, { ILocalUser, IUser } from '../../../../models/user';
 | 
			
		||||
import DriveFile from '../../../../models/drive-file';
 | 
			
		||||
import DriveFile, { IDriveFile } from '../../../../models/drive-file';
 | 
			
		||||
import create from '../../../../services/note/create';
 | 
			
		||||
import { IApp } from '../../../../models/app';
 | 
			
		||||
import getParams from '../../get-params';
 | 
			
		||||
 | 
			
		||||
export const meta = {
 | 
			
		||||
	params: {
 | 
			
		||||
		visibility: {
 | 
			
		||||
			def: $.str.optional().or(['public', 'home', 'followers', 'specified', 'private']),
 | 
			
		||||
		visibility: $.str.optional.or(['public', 'home', 'followers', 'specified', 'private']).note({
 | 
			
		||||
			default: 'public',
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: '投稿の公開範囲'
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		visibleUserIds: {
 | 
			
		||||
			def: $.arr($.type(ID)).optional().unique().min(1),
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		visibleUserIds: $.arr($.type(ID)).optional.unique().min(1).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: '(投稿の公開範囲が specified の場合)投稿を閲覧できるユーザー'
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		text: {
 | 
			
		||||
			def: $.str.optional().nullable().pipe(isValidText),
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		text: $.str.optional.nullable.pipe(isValidText).note({
 | 
			
		||||
			default: null,
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: '投稿内容'
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		cw: $.str.optional.nullable.pipe(isValidCw).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: 'コンテンツの警告。このパラメータを指定すると設定したテキストで投稿のコンテンツを隠す事が出来ます。'
 | 
			
		||||
			}
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		viaMobile: $.bool.optional.note({
 | 
			
		||||
			default: false,
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: 'モバイルデバイスからの投稿か否か。'
 | 
			
		||||
			}
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		geo: $.obj({
 | 
			
		||||
			coordinates: $.arr().length(2)
 | 
			
		||||
				.item(0, $.num.range(-180, 180))
 | 
			
		||||
				.item(1, $.num.range(-90, 90)),
 | 
			
		||||
			altitude: $.num.nullable,
 | 
			
		||||
			accuracy: $.num.nullable,
 | 
			
		||||
			altitudeAccuracy: $.num.nullable,
 | 
			
		||||
			heading: $.num.nullable.range(0, 360),
 | 
			
		||||
			speed: $.num.nullable
 | 
			
		||||
		}).optional.nullable.strict().note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: '位置情報'
 | 
			
		||||
			}
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		mediaIds: $.arr($.type(ID)).optional.unique().range(1, 4).note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: '添付するメディア'
 | 
			
		||||
			}
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		renoteId: $.type(ID).optional.note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: 'Renote対象'
 | 
			
		||||
			}
 | 
			
		||||
		}),
 | 
			
		||||
 | 
			
		||||
		poll: $.obj({
 | 
			
		||||
			choices: $.arr($.str)
 | 
			
		||||
				.unique()
 | 
			
		||||
				.range(2, 10)
 | 
			
		||||
				.each(c => c.length > 0 && c.length < 50)
 | 
			
		||||
		}).optional.strict().note({
 | 
			
		||||
			desc: {
 | 
			
		||||
				ja: 'アンケート'
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -45,45 +95,12 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
 | 
			
		||||
		})));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'text' parameter
 | 
			
		||||
	const [text = null, textErr] = $.str.optional().nullable().pipe(isValidText).get(params.text);
 | 
			
		||||
	if (textErr) return rej('invalid text');
 | 
			
		||||
 | 
			
		||||
	// Get 'cw' parameter
 | 
			
		||||
	const [cw, cwErr] = $.str.optional().nullable().pipe(isValidCw).get(params.cw);
 | 
			
		||||
	if (cwErr) return rej('invalid cw');
 | 
			
		||||
 | 
			
		||||
	// Get 'viaMobile' parameter
 | 
			
		||||
	const [viaMobile = false, viaMobileErr] = $.bool.optional().get(params.viaMobile);
 | 
			
		||||
	if (viaMobileErr) return rej('invalid viaMobile');
 | 
			
		||||
 | 
			
		||||
	// Get 'tags' parameter
 | 
			
		||||
	const [tags = [], tagsErr] = $.arr($.str.range(1, 32)).optional().unique().get(params.tags);
 | 
			
		||||
	if (tagsErr) return rej('invalid tags');
 | 
			
		||||
 | 
			
		||||
	// Get 'geo' parameter
 | 
			
		||||
	const [geo, geoErr] = $.obj.optional().nullable().strict()
 | 
			
		||||
		.have('coordinates', $.arr().length(2)
 | 
			
		||||
			.item(0, $.num.range(-180, 180))
 | 
			
		||||
			.item(1, $.num.range(-90, 90)))
 | 
			
		||||
		.have('altitude', $.num.nullable())
 | 
			
		||||
		.have('accuracy', $.num.nullable())
 | 
			
		||||
		.have('altitudeAccuracy', $.num.nullable())
 | 
			
		||||
		.have('heading', $.num.nullable().range(0, 360))
 | 
			
		||||
		.have('speed', $.num.nullable())
 | 
			
		||||
		.get(params.geo);
 | 
			
		||||
	if (geoErr) return rej('invalid geo');
 | 
			
		||||
 | 
			
		||||
	// Get 'mediaIds' parameter
 | 
			
		||||
	const [mediaIds, mediaIdsErr] = $.arr($.type(ID)).optional().unique().range(1, 4).get(params.mediaIds);
 | 
			
		||||
	if (mediaIdsErr) return rej('invalid mediaIds');
 | 
			
		||||
 | 
			
		||||
	let files = [];
 | 
			
		||||
	if (mediaIds !== undefined) {
 | 
			
		||||
	let files: IDriveFile[] = [];
 | 
			
		||||
	if (ps.mediaIds !== undefined) {
 | 
			
		||||
		// Fetch files
 | 
			
		||||
		// forEach だと途中でエラーなどがあっても return できないので
 | 
			
		||||
		// 敢えて for を使っています。
 | 
			
		||||
		for (const mediaId of mediaIds) {
 | 
			
		||||
		for (const mediaId of ps.mediaIds) {
 | 
			
		||||
			// Fetch file
 | 
			
		||||
			// SELECT _id
 | 
			
		||||
			const entity = await DriveFile.findOne({
 | 
			
		||||
@@ -101,15 +118,11 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
 | 
			
		||||
		files = null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'renoteId' parameter
 | 
			
		||||
	const [renoteId, renoteIdErr] = $.type(ID).optional().get(params.renoteId);
 | 
			
		||||
	if (renoteIdErr) return rej('invalid renoteId');
 | 
			
		||||
 | 
			
		||||
	let renote: INote = null;
 | 
			
		||||
	if (renoteId !== undefined) {
 | 
			
		||||
	if (ps.renoteId !== undefined) {
 | 
			
		||||
		// Fetch renote to note
 | 
			
		||||
		renote = await Note.findOne({
 | 
			
		||||
			_id: renoteId
 | 
			
		||||
			_id: ps.renoteId
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		if (renote == null) {
 | 
			
		||||
@@ -120,7 +133,7 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'replyId' parameter
 | 
			
		||||
	const [replyId, replyIdErr] = $.type(ID).optional().get(params.replyId);
 | 
			
		||||
	const [replyId, replyIdErr] = $.type(ID).optional.get(params.replyId);
 | 
			
		||||
	if (replyIdErr) return rej('invalid replyId');
 | 
			
		||||
 | 
			
		||||
	let reply: INote = null;
 | 
			
		||||
@@ -140,17 +153,8 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'poll' parameter
 | 
			
		||||
	const [poll, pollErr] = $.obj.optional().strict()
 | 
			
		||||
		.have('choices', $.arr($.str)
 | 
			
		||||
			.unique()
 | 
			
		||||
			.range(2, 10)
 | 
			
		||||
			.each(c => c.length > 0 && c.length < 50))
 | 
			
		||||
		.get(params.poll);
 | 
			
		||||
	if (pollErr) return rej('invalid poll');
 | 
			
		||||
 | 
			
		||||
	if (poll) {
 | 
			
		||||
		(poll as any).choices = (poll as any).choices.map((choice: string, i: number) => ({
 | 
			
		||||
	if (ps.poll) {
 | 
			
		||||
		(ps.poll as any).choices = (ps.poll as any).choices.map((choice: string, i: number) => ({
 | 
			
		||||
			id: i, // IDを付与
 | 
			
		||||
			text: choice.trim(),
 | 
			
		||||
			votes: 0
 | 
			
		||||
@@ -158,7 +162,7 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// テキストが無いかつ添付ファイルが無いかつRenoteも無いかつ投票も無かったらエラー
 | 
			
		||||
	if ((text === undefined || text === null) && files === null && renote === null && poll === undefined) {
 | 
			
		||||
	if ((ps.text === undefined || ps.text === null) && files === null && renote === null && ps.poll === undefined) {
 | 
			
		||||
		return rej('text, mediaIds, renoteId or poll is required');
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -166,17 +170,16 @@ module.exports = (params: any, user: ILocalUser, app: IApp) => new Promise(async
 | 
			
		||||
	const note = await create(user, {
 | 
			
		||||
		createdAt: new Date(),
 | 
			
		||||
		media: files,
 | 
			
		||||
		poll,
 | 
			
		||||
		text,
 | 
			
		||||
		poll: ps.poll,
 | 
			
		||||
		text: ps.text,
 | 
			
		||||
		reply,
 | 
			
		||||
		renote,
 | 
			
		||||
		cw,
 | 
			
		||||
		tags,
 | 
			
		||||
		cw: ps.cw,
 | 
			
		||||
		app,
 | 
			
		||||
		viaMobile,
 | 
			
		||||
		visibility,
 | 
			
		||||
		viaMobile: ps.viaMobile,
 | 
			
		||||
		visibility: ps.visibility,
 | 
			
		||||
		visibleUsers,
 | 
			
		||||
		geo
 | 
			
		||||
		geo: ps.geo
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	const noteObj = await pack(note, user);
 | 
			
		||||
 
 | 
			
		||||
@@ -9,23 +9,23 @@ import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
 */
 | 
			
		||||
module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) throw 'invalid limit param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceId' parameter
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
			
		||||
	if (sinceIdErr) throw 'invalid sinceId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilId' parameter
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
			
		||||
	if (untilIdErr) throw 'invalid untilId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceDate' parameter
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
 | 
			
		||||
	if (sinceDateErr) throw 'invalid sinceDate param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilDate' parameter
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
 | 
			
		||||
	if (untilDateErr) throw 'invalid untilDate param';
 | 
			
		||||
 | 
			
		||||
	// Check if only one of sinceId, untilId, sinceDate, untilDate specified
 | 
			
		||||
@@ -34,7 +34,7 @@ module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'mediaOnly' parameter
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
 | 
			
		||||
	if (mediaOnlyErr) throw 'invalid mediaOnly param';
 | 
			
		||||
 | 
			
		||||
	// ミュートしているユーザーを取得
 | 
			
		||||
 
 | 
			
		||||
@@ -9,23 +9,23 @@ import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
 */
 | 
			
		||||
module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) throw 'invalid limit param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceId' parameter
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
			
		||||
	if (sinceIdErr) throw 'invalid sinceId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilId' parameter
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
			
		||||
	if (untilIdErr) throw 'invalid untilId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceDate' parameter
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
 | 
			
		||||
	if (sinceDateErr) throw 'invalid sinceDate param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilDate' parameter
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
 | 
			
		||||
	if (untilDateErr) throw 'invalid untilDate param';
 | 
			
		||||
 | 
			
		||||
	// Check if only one of sinceId, untilId, sinceDate, untilDate specified
 | 
			
		||||
@@ -34,7 +34,7 @@ module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'mediaOnly' parameter
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
 | 
			
		||||
	if (mediaOnlyErr) throw 'invalid mediaOnly param';
 | 
			
		||||
 | 
			
		||||
	// ミュートしているユーザーを取得
 | 
			
		||||
 
 | 
			
		||||
@@ -10,19 +10,19 @@ import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	// Get 'following' parameter
 | 
			
		||||
	const [following = false, followingError] =
 | 
			
		||||
		$.bool.optional().get(params.following);
 | 
			
		||||
		$.bool.optional.get(params.following);
 | 
			
		||||
	if (followingError) return rej('invalid following param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceId' parameter
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
			
		||||
	if (sinceIdErr) return rej('invalid sinceId param');
 | 
			
		||||
 | 
			
		||||
	// Get 'untilId' parameter
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
			
		||||
	if (untilIdErr) return rej('invalid untilId param');
 | 
			
		||||
 | 
			
		||||
	// Check if both of sinceId and untilId is specified
 | 
			
		||||
 
 | 
			
		||||
@@ -8,11 +8,11 @@ import { ILocalUser } from '../../../../../models/user';
 | 
			
		||||
 */
 | 
			
		||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Get votes
 | 
			
		||||
 
 | 
			
		||||
@@ -12,15 +12,15 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Get 'sort' parameter
 | 
			
		||||
	const [sort = 'desc', sortError] = $.str.optional().or('desc asc').get(params.sort);
 | 
			
		||||
	const [sort = 'desc', sortError] = $.str.optional.or('desc asc').get(params.sort);
 | 
			
		||||
	if (sortError) return rej('invalid sort param');
 | 
			
		||||
 | 
			
		||||
	// Lookup note
 | 
			
		||||
 
 | 
			
		||||
@@ -11,11 +11,11 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Lookup note
 | 
			
		||||
 
 | 
			
		||||
@@ -11,15 +11,15 @@ module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej)
 | 
			
		||||
	if (noteIdErr) return rej('invalid noteId param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceId' parameter
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
			
		||||
	if (sinceIdErr) return rej('invalid sinceId param');
 | 
			
		||||
 | 
			
		||||
	// Get 'untilId' parameter
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
			
		||||
	if (untilIdErr) return rej('invalid untilId param');
 | 
			
		||||
 | 
			
		||||
	// Check if both of sinceId and untilId is specified
 | 
			
		||||
 
 | 
			
		||||
@@ -11,11 +11,11 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) =
 | 
			
		||||
	if (queryError) return rej('invalid query param');
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	es.search({
 | 
			
		||||
 
 | 
			
		||||
@@ -14,59 +14,59 @@ module.exports = (params: any, me: ILocalUser) => new Promise(async (res, rej) =
 | 
			
		||||
	if (tagError) return rej('invalid tag param');
 | 
			
		||||
 | 
			
		||||
	// Get 'includeUserIds' parameter
 | 
			
		||||
	const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional().get(params.includeUserIds);
 | 
			
		||||
	const [includeUserIds = [], includeUserIdsErr] = $.arr($.type(ID)).optional.get(params.includeUserIds);
 | 
			
		||||
	if (includeUserIdsErr) return rej('invalid includeUserIds param');
 | 
			
		||||
 | 
			
		||||
	// Get 'excludeUserIds' parameter
 | 
			
		||||
	const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional().get(params.excludeUserIds);
 | 
			
		||||
	const [excludeUserIds = [], excludeUserIdsErr] = $.arr($.type(ID)).optional.get(params.excludeUserIds);
 | 
			
		||||
	if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
 | 
			
		||||
 | 
			
		||||
	// Get 'includeUserUsernames' parameter
 | 
			
		||||
	const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional().get(params.includeUserUsernames);
 | 
			
		||||
	const [includeUserUsernames = [], includeUserUsernamesErr] = $.arr($.str).optional.get(params.includeUserUsernames);
 | 
			
		||||
	if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
 | 
			
		||||
 | 
			
		||||
	// Get 'excludeUserUsernames' parameter
 | 
			
		||||
	const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional().get(params.excludeUserUsernames);
 | 
			
		||||
	const [excludeUserUsernames = [], excludeUserUsernamesErr] = $.arr($.str).optional.get(params.excludeUserUsernames);
 | 
			
		||||
	if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
 | 
			
		||||
 | 
			
		||||
	// Get 'following' parameter
 | 
			
		||||
	const [following = null, followingErr] = $.bool.optional().nullable().get(params.following);
 | 
			
		||||
	const [following = null, followingErr] = $.bool.optional.nullable.get(params.following);
 | 
			
		||||
	if (followingErr) return rej('invalid following param');
 | 
			
		||||
 | 
			
		||||
	// Get 'mute' parameter
 | 
			
		||||
	const [mute = 'mute_all', muteErr] = $.str.optional().get(params.mute);
 | 
			
		||||
	const [mute = 'mute_all', muteErr] = $.str.optional.get(params.mute);
 | 
			
		||||
	if (muteErr) return rej('invalid mute param');
 | 
			
		||||
 | 
			
		||||
	// Get 'reply' parameter
 | 
			
		||||
	const [reply = null, replyErr] = $.bool.optional().nullable().get(params.reply);
 | 
			
		||||
	const [reply = null, replyErr] = $.bool.optional.nullable.get(params.reply);
 | 
			
		||||
	if (replyErr) return rej('invalid reply param');
 | 
			
		||||
 | 
			
		||||
	// Get 'renote' parameter
 | 
			
		||||
	const [renote = null, renoteErr] = $.bool.optional().nullable().get(params.renote);
 | 
			
		||||
	const [renote = null, renoteErr] = $.bool.optional.nullable.get(params.renote);
 | 
			
		||||
	if (renoteErr) return rej('invalid renote param');
 | 
			
		||||
 | 
			
		||||
	// Get 'media' parameter
 | 
			
		||||
	const [media = null, mediaErr] = $.bool.optional().nullable().get(params.media);
 | 
			
		||||
	const [media = null, mediaErr] = $.bool.optional.nullable.get(params.media);
 | 
			
		||||
	if (mediaErr) return rej('invalid media param');
 | 
			
		||||
 | 
			
		||||
	// Get 'poll' parameter
 | 
			
		||||
	const [poll = null, pollErr] = $.bool.optional().nullable().get(params.poll);
 | 
			
		||||
	const [poll = null, pollErr] = $.bool.optional.nullable.get(params.poll);
 | 
			
		||||
	if (pollErr) return rej('invalid poll param');
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceDate' parameter
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
 | 
			
		||||
	if (sinceDateErr) throw 'invalid sinceDate param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilDate' parameter
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
 | 
			
		||||
	if (untilDateErr) throw 'invalid untilDate param';
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 30).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 30).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	if (includeUserUsernames != null) {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,23 +10,23 @@ import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
 */
 | 
			
		||||
module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) throw 'invalid limit param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceId' parameter
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
			
		||||
	if (sinceIdErr) throw 'invalid sinceId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilId' parameter
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
			
		||||
	if (untilIdErr) throw 'invalid untilId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceDate' parameter
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
 | 
			
		||||
	if (sinceDateErr) throw 'invalid sinceDate param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilDate' parameter
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
 | 
			
		||||
	if (untilDateErr) throw 'invalid untilDate param';
 | 
			
		||||
 | 
			
		||||
	// Check if only one of sinceId, untilId, sinceDate, untilDate specified
 | 
			
		||||
@@ -35,15 +35,15 @@ module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'includeMyRenotes' parameter
 | 
			
		||||
	const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes);
 | 
			
		||||
	const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes);
 | 
			
		||||
	if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
 | 
			
		||||
 | 
			
		||||
	// Get 'includeRenotedMyNotes' parameter
 | 
			
		||||
	const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
 | 
			
		||||
	const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes);
 | 
			
		||||
	if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
 | 
			
		||||
 | 
			
		||||
	// Get 'mediaOnly' parameter
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
 | 
			
		||||
	if (mediaOnlyErr) throw 'invalid mediaOnly param';
 | 
			
		||||
 | 
			
		||||
	const [followings, mutedUserIds] = await Promise.all([
 | 
			
		||||
 
 | 
			
		||||
@@ -8,27 +8,27 @@ import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
 */
 | 
			
		||||
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) return rej('invalid limit param');
 | 
			
		||||
 | 
			
		||||
	// Get 'offset' parameter
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional().min(0).get(params.offset);
 | 
			
		||||
	const [offset = 0, offsetErr] = $.num.optional.min(0).get(params.offset);
 | 
			
		||||
	if (offsetErr) return rej('invalid offset param');
 | 
			
		||||
 | 
			
		||||
	// Get 'reply' parameter
 | 
			
		||||
	const [reply, replyErr] = $.bool.optional().get(params.reply);
 | 
			
		||||
	const [reply, replyErr] = $.bool.optional.get(params.reply);
 | 
			
		||||
	if (replyErr) return rej('invalid reply param');
 | 
			
		||||
 | 
			
		||||
	// Get 'renote' parameter
 | 
			
		||||
	const [renote, renoteErr] = $.bool.optional().get(params.renote);
 | 
			
		||||
	const [renote, renoteErr] = $.bool.optional.get(params.renote);
 | 
			
		||||
	if (renoteErr) return rej('invalid renote param');
 | 
			
		||||
 | 
			
		||||
	// Get 'media' parameter
 | 
			
		||||
	const [media, mediaErr] = $.bool.optional().get(params.media);
 | 
			
		||||
	const [media, mediaErr] = $.bool.optional.get(params.media);
 | 
			
		||||
	if (mediaErr) return rej('invalid media param');
 | 
			
		||||
 | 
			
		||||
	// Get 'poll' parameter
 | 
			
		||||
	const [poll, pollErr] = $.bool.optional().get(params.poll);
 | 
			
		||||
	const [poll, pollErr] = $.bool.optional.get(params.poll);
 | 
			
		||||
	if (pollErr) return rej('invalid poll param');
 | 
			
		||||
 | 
			
		||||
	const query = {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,23 +10,23 @@ import { ILocalUser } from '../../../../models/user';
 | 
			
		||||
 */
 | 
			
		||||
module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	// Get 'limit' parameter
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional().range(1, 100).get(params.limit);
 | 
			
		||||
	const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
 | 
			
		||||
	if (limitErr) throw 'invalid limit param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceId' parameter
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional().get(params.sinceId);
 | 
			
		||||
	const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
 | 
			
		||||
	if (sinceIdErr) throw 'invalid sinceId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilId' parameter
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional().get(params.untilId);
 | 
			
		||||
	const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
 | 
			
		||||
	if (untilIdErr) throw 'invalid untilId param';
 | 
			
		||||
 | 
			
		||||
	// Get 'sinceDate' parameter
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional().get(params.sinceDate);
 | 
			
		||||
	const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
 | 
			
		||||
	if (sinceDateErr) throw 'invalid sinceDate param';
 | 
			
		||||
 | 
			
		||||
	// Get 'untilDate' parameter
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional().get(params.untilDate);
 | 
			
		||||
	const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
 | 
			
		||||
	if (untilDateErr) throw 'invalid untilDate param';
 | 
			
		||||
 | 
			
		||||
	// Check if only one of sinceId, untilId, sinceDate, untilDate specified
 | 
			
		||||
@@ -35,15 +35,15 @@ module.exports = async (params: any, user: ILocalUser) => {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Get 'includeMyRenotes' parameter
 | 
			
		||||
	const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional().get(params.includeMyRenotes);
 | 
			
		||||
	const [includeMyRenotes = true, includeMyRenotesErr] = $.bool.optional.get(params.includeMyRenotes);
 | 
			
		||||
	if (includeMyRenotesErr) throw 'invalid includeMyRenotes param';
 | 
			
		||||
 | 
			
		||||
	// Get 'includeRenotedMyNotes' parameter
 | 
			
		||||
	const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional().get(params.includeRenotedMyNotes);
 | 
			
		||||
	const [includeRenotedMyNotes = true, includeRenotedMyNotesErr] = $.bool.optional.get(params.includeRenotedMyNotes);
 | 
			
		||||
	if (includeRenotedMyNotesErr) throw 'invalid includeRenotedMyNotes param';
 | 
			
		||||
 | 
			
		||||
	// Get 'mediaOnly' parameter
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional().get(params.mediaOnly);
 | 
			
		||||
	const [mediaOnly, mediaOnlyErr] = $.bool.optional.get(params.mediaOnly);
 | 
			
		||||
	if (mediaOnlyErr) throw 'invalid mediaOnly param';
 | 
			
		||||
 | 
			
		||||
	// Get 'listId' parameter
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user