This commit is contained in:
syuilo 2017-03-09 03:50:09 +09:00
parent 3d536ddb3f
commit 31f36fa618
64 changed files with 241 additions and 256 deletions

View file

@ -65,7 +65,7 @@
"@types/websocket": "0.0.33", "@types/websocket": "0.0.33",
"autwh": "0.0.1", "autwh": "0.0.1",
"bcryptjs": "2.4.3", "bcryptjs": "2.4.3",
"cafy": "1.2.0", "cafy": "2.3.0",
"body-parser": "1.17.1", "body-parser": "1.17.1",
"chai": "3.5.0", "chai": "3.5.0",
"chai-http": "3.0.0", "chai-http": "3.0.0",

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../../models/post'; import Post from '../../../models/post';
import Like from '../../../models/like'; import Like from '../../../models/like';
@ -13,7 +13,7 @@ import Like from '../../../models/like';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../../models/post'; import Post from '../../../models/post';
import Like from '../../../models/like'; import Like from '../../../models/like';
@ -13,7 +13,7 @@ import Like from '../../../models/like';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../../models/post'; import Post from '../../../models/post';
/** /**
@ -12,7 +12,7 @@ import Post from '../../../models/post';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../../models/post'; import Post from '../../../models/post';
/** /**
@ -12,7 +12,7 @@ import Post from '../../../models/post';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id).expect.id().required().get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../../models/user'; import User from '../../../models/user';
import Following from '../../../models/following'; import Following from '../../../models/following';
@ -13,7 +13,7 @@ import Following from '../../../models/following';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Lookup user // Lookup user

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../../models/user'; import User from '../../../models/user';
import Following from '../../../models/following'; import Following from '../../../models/following';
@ -13,7 +13,7 @@ import Following from '../../../models/following';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Lookup user // Lookup user

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../../models/user'; import User from '../../../models/user';
import Like from '../../../models/like'; import Like from '../../../models/like';
@ -13,7 +13,7 @@ import Like from '../../../models/like';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Lookup user // Lookup user

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../../models/user'; import User from '../../../models/user';
import Post from '../../../models/post'; import Post from '../../../models/post';
@ -13,7 +13,7 @@ import Post from '../../../models/post';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id).expect.id().required().get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Lookup user // Lookup user

View file

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import rndstr from 'rndstr'; import rndstr from 'rndstr';
import it from 'cafy'; import $ from 'cafy';
import App from '../../models/app'; import App from '../../models/app';
import { isValidNameId } from '../../models/app'; import { isValidNameId } from '../../models/app';
import serialize from '../../serializers/app'; import serialize from '../../serializers/app';
@ -69,24 +69,24 @@ import serialize from '../../serializers/app';
*/ */
module.exports = async (params, user) => new Promise(async (res, rej) => { module.exports = async (params, user) => new Promise(async (res, rej) => {
// Get 'name_id' parameter // Get 'name_id' parameter
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).get(); const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
if (nameIdErr) return rej('invalid name_id param'); if (nameIdErr) return rej('invalid name_id param');
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().required().get(); const [name, nameErr] = $(params.name).string().$;
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');
// Get 'description' parameter // Get 'description' parameter
const [description, descriptionErr] = it(params.description).expect.string().required().get(); const [description, descriptionErr] = $(params.description).string().$;
if (descriptionErr) return rej('invalid description param'); if (descriptionErr) return rej('invalid description param');
// Get 'permission' parameter // Get 'permission' parameter
const [permission, permissionErr] = it(params.permission).expect.array().unique().allString().required().get(); const [permission, permissionErr] = $(params.permission).array('string').unique().$;
if (permissionErr) return rej('invalid permission param'); if (permissionErr) return rej('invalid permission param');
// Get 'callback_url' parameter // Get 'callback_url' parameter
// TODO: Check it is valid url // TODO: Check $ is valid url
const [callbackUrl = null, callbackUrlErr] = it(params.callback_url).expect.nullable.string().get(); const [callbackUrl = null, callbackUrlErr] = $(params.callback_url).optional.nullable.string().$;
if (callbackUrlErr) return rej('invalid callback_url param'); if (callbackUrlErr) return rej('invalid callback_url param');
// Generate secret // Generate secret

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import App from '../../../models/app'; import App from '../../../models/app';
import { isValidNameId } from '../../../models/app'; import { isValidNameId } from '../../../models/app';
@ -42,7 +42,7 @@ import { isValidNameId } from '../../../models/app';
*/ */
module.exports = async (params) => new Promise(async (res, rej) => { module.exports = async (params) => new Promise(async (res, rej) => {
// Get 'name_id' parameter // Get 'name_id' parameter
const [nameId, nameIdErr] = it(params.name_id).expect.string().required().validate(isValidNameId).get(); const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
if (nameIdErr) return rej('invalid name_id param'); if (nameIdErr) return rej('invalid name_id param');
// Get exist // Get exist

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import App from '../../models/app'; import App from '../../models/app';
import serialize from '../../serializers/app'; import serialize from '../../serializers/app';
@ -46,11 +46,11 @@ import serialize from '../../serializers/app';
*/ */
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => { module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
// Get 'app_id' parameter // Get 'app_id' parameter
const [appId, appIdErr] = it(params.app_id, 'id').get(); const [appId, appIdErr] = $(params.app_id).optional.id().$;
if (appIdErr) return rej('invalid app_id param'); if (appIdErr) return rej('invalid app_id param');
// Get 'name_id' parameter // Get 'name_id' parameter
const [nameId, nameIdErr] = it(params.name_id, 'string').get(); const [nameId, nameIdErr] = $(params.name_id).optional.string().$;
if (nameIdErr) return rej('invalid name_id param'); if (nameIdErr) return rej('invalid name_id param');
if (appId === undefined && nameId === undefined) { if (appId === undefined && nameId === undefined) {

View file

@ -3,7 +3,7 @@
*/ */
import rndstr from 'rndstr'; import rndstr from 'rndstr';
const crypto = require('crypto'); const crypto = require('crypto');
import it from 'cafy'; import $ from 'cafy';
import App from '../../models/app'; import App from '../../models/app';
import AuthSess from '../../models/auth-session'; import AuthSess from '../../models/auth-session';
import AccessToken from '../../models/access-token'; import AccessToken from '../../models/access-token';
@ -40,7 +40,7 @@ import AccessToken from '../../models/access-token';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'token' parameter // Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().get(); const [token, tokenErr] = $(params.token).string().$;
if (tokenErr) return rej('invalid token param'); if (tokenErr) return rej('invalid token param');
// Fetch token // Fetch token

View file

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import * as uuid from 'uuid'; import * as uuid from 'uuid';
import it from 'cafy'; import $ from 'cafy';
import App from '../../../models/app'; import App from '../../../models/app';
import AuthSess from '../../../models/auth-session'; import AuthSess from '../../../models/auth-session';
import config from '../../../../conf'; import config from '../../../../conf';
@ -46,7 +46,7 @@ import config from '../../../../conf';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'app_secret' parameter // Get 'app_secret' parameter
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().get(); const [appSecret, appSecretErr] = $(params.app_secret).string().$;
if (appSecretErr) return rej('invalid app_secret param'); if (appSecretErr) return rej('invalid app_secret param');
// Lookup app // Lookup app

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import AuthSess from '../../../models/auth-session'; import AuthSess from '../../../models/auth-session';
import serialize from '../../../serializers/auth-session'; import serialize from '../../../serializers/auth-session';
@ -54,7 +54,7 @@ import serialize from '../../../serializers/auth-session';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'token' parameter // Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().get(); const [token, tokenErr] = $(params.token).string().$;
if (tokenErr) return rej('invalid token param'); if (tokenErr) return rej('invalid token param');
// Lookup session // Lookup session

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import App from '../../../models/app'; import App from '../../../models/app';
import AuthSess from '../../../models/auth-session'; import AuthSess from '../../../models/auth-session';
import AccessToken from '../../../models/access-token'; import AccessToken from '../../../models/access-token';
@ -51,7 +51,7 @@ import serialize from '../../../serializers/user';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'app_secret' parameter // Get 'app_secret' parameter
const [appSecret, appSecretErr] = it(params.app_secret).expect.string().required().get(); const [appSecret, appSecretErr] = $(params.app_secret).string().$;
if (appSecretErr) return rej('invalid app_secret param'); if (appSecretErr) return rej('invalid app_secret param');
// Lookup app // Lookup app
@ -64,7 +64,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
} }
// Get 'token' parameter // Get 'token' parameter
const [token, tokenErr] = it(params.token).expect.string().required().get(); const [token, tokenErr] = $(params.token).string().$;
if (tokenErr) return rej('invalid token param'); if (tokenErr) return rej('invalid token param');
// Fetch token // Fetch token

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFile from '../../models/drive-file'; import DriveFile from '../../models/drive-file';
import serialize from '../../serializers/drive-file'; import serialize from '../../serializers/drive-file';
@ -15,15 +15,15 @@ import serialize from '../../serializers/drive-file';
*/ */
module.exports = (params, user, app) => new Promise(async (res, rej) => { module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
@ -32,7 +32,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
} }
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get(); const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Construct query // Construct query

View file

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import * as fs from 'fs'; import * as fs from 'fs';
import it from 'cafy'; import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file'; import { validateFileName } from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file'; import serialize from '../../../serializers/drive-file';
import create from '../../../common/add-file-to-drive'; import create from '../../../common/add-file-to-drive';
@ -39,7 +39,7 @@ module.exports = (file, params, user) => new Promise(async (res, rej) => {
} }
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get(); const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Create file // Create file

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFile from '../../../models/drive-file'; import DriveFile from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file'; import serialize from '../../../serializers/drive-file';
@ -14,11 +14,11 @@ import serialize from '../../../serializers/drive-file';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().required().get(); const [name, nameErr] = $(params.name).string().$;
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get(); const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Issue query // Issue query

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFile from '../../../models/drive-file'; import DriveFile from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file'; import serialize from '../../../serializers/drive-file';
@ -14,7 +14,7 @@ import serialize from '../../../serializers/drive-file';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'file_id' parameter // Get 'file_id' parameter
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().get(); const [fileId, fileIdErr] = $(params.file_id).id().$;
if (fileIdErr) return rej('invalid file_id param'); if (fileIdErr) return rej('invalid file_id param');
// Fetch file // Fetch file

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder'; import DriveFolder from '../../../models/drive-folder';
import DriveFile from '../../../models/drive-file'; import DriveFile from '../../../models/drive-file';
import { validateFileName } from '../../../models/drive-file'; import { validateFileName } from '../../../models/drive-file';
@ -17,7 +17,7 @@ import event from '../../../event';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'file_id' parameter // Get 'file_id' parameter
const [fileId, fileIdErr] = it(params.file_id).expect.id().required().get(); const [fileId, fileIdErr] = $(params.file_id).id().$;
if (fileIdErr) return rej('invalid file_id param'); if (fileIdErr) return rej('invalid file_id param');
// Fetch file // Fetch file
@ -36,12 +36,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} }
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().validate(validateFileName).get(); const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$;
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');
if (name) file.name = name; if (name) file.name = name;
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId, folderIdErr] = it(params.folder_id).expect.nullable.id().get(); const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
if (folderId !== undefined) { if (folderId !== undefined) {

View file

@ -3,7 +3,7 @@
*/ */
import * as URL from 'url'; import * as URL from 'url';
const download = require('download'); const download = require('download');
import it from 'cafy'; import $ from 'cafy';
import { validateFileName } from '../../../models/drive-file'; import { validateFileName } from '../../../models/drive-file';
import serialize from '../../../serializers/drive-file'; import serialize from '../../../serializers/drive-file';
import create from '../../../common/add-file-to-drive'; import create from '../../../common/add-file-to-drive';
@ -18,7 +18,7 @@ import create from '../../../common/add-file-to-drive';
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'url' parameter // Get 'url' parameter
// TODO: Validate this url // TODO: Validate this url
const [url, urlErr] = it(params.url).expect.string().required().get(); const [url, urlErr] = $(params.url).string().$;
if (urlErr) return rej('invalid url param'); if (urlErr) return rej('invalid url param');
let name = URL.parse(url).pathname.split('/').pop(); let name = URL.parse(url).pathname.split('/').pop();
@ -27,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} }
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get(); const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Download file // Download file

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFolder from '../../models/drive-folder'; import DriveFolder from '../../models/drive-folder';
import serialize from '../../serializers/drive-folder'; import serialize from '../../serializers/drive-folder';
@ -15,15 +15,15 @@ import serialize from '../../serializers/drive-folder';
*/ */
module.exports = (params, user, app) => new Promise(async (res, rej) => { module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
@ -32,7 +32,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
} }
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId = null, folderIdErr] = it(params.folder_id).expect.nullable.id().get(); const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Construct query // Construct query

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder'; import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder'; import { isValidFolderName } from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder'; import serialize from '../../../serializers/drive-folder';
@ -16,11 +16,11 @@ import event from '../../../event';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter // Get 'name' parameter
const [name = '無題のフォルダー', nameErr] = it(params.name).expect.string().validate(isValidFolderName).get(); const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$;
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');
// Get 'parent_id' parameter // Get 'parent_id' parameter
const [parentId = null, parentIdErr] = it(params.parent_id).expect.nullable.id().get(); const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
if (parentIdErr) return rej('invalid parent_id param'); if (parentIdErr) return rej('invalid parent_id param');
// If the parent folder is specified // If the parent folder is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder'; import DriveFolder from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder'; import serialize from '../../../serializers/drive-folder';
@ -14,11 +14,11 @@ import serialize from '../../../serializers/drive-folder';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().required().get(); const [name, nameErr] = $(params.name).string().$;
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');
// Get 'parent_id' parameter // Get 'parent_id' parameter
const [parentId, parentIdErr] = it(params.parent_id).expect.id().get(); const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
if (parentIdErr) return rej('invalid parent_id param'); if (parentIdErr) return rej('invalid parent_id param');
// Issue query // Issue query

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder'; import DriveFolder from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-folder'; import serialize from '../../../serializers/drive-folder';
@ -14,7 +14,7 @@ import serialize from '../../../serializers/drive-folder';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().get(); const [folderId, folderIdErr] = $(params.folder_id).id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Get folder // Get folder

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFolder from '../../../models/drive-folder'; import DriveFolder from '../../../models/drive-folder';
import { isValidFolderName } from '../../../models/drive-folder'; import { isValidFolderName } from '../../../models/drive-folder';
import serialize from '../../../serializers/drive-file'; import serialize from '../../../serializers/drive-file';
@ -16,7 +16,7 @@ import event from '../../../event';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'folder_id' parameter // Get 'folder_id' parameter
const [folderId, folderIdErr] = it(params.folder_id).expect.id().required().get(); const [folderId, folderIdErr] = $(params.folder_id).id().$;
if (folderIdErr) return rej('invalid folder_id param'); if (folderIdErr) return rej('invalid folder_id param');
// Fetch folder // Fetch folder
@ -31,12 +31,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} }
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().validate(isValidFolderName).get(); const [name, nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$;
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 'parent_id' parameter // Get 'parent_id' parameter
const [parentId, parentIdErr] = it(params.parent_id).expect.nullable.id().get(); const [parentId, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
if (parentIdErr) return rej('invalid parent_id param'); if (parentIdErr) return rej('invalid parent_id param');
if (parentId !== undefined) { if (parentId !== undefined) {
if (parentId === null) { if (parentId === null) {

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import DriveFile from '../../models/drive-file'; import DriveFile from '../../models/drive-file';
import serialize from '../../serializers/drive-file'; import serialize from '../../serializers/drive-file';
@ -14,15 +14,15 @@ import serialize from '../../serializers/drive-file';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} }
// Get 'type' parameter // Get 'type' parameter
const [type, typeErr] = it(params.type).expect.string().match(/^[a-zA-Z\/\-\*]+$/).get(); const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$;
if (typeErr) return rej('invalid type param'); if (typeErr) return rej('invalid type param');
// Construct query // Construct query
@ -51,7 +51,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
$lt: maxId $lt: maxId
}; };
} }
if (type !== null) { if (type) {
query.type = new RegExp(`^${type.replace(/\*/g, '.+?')}$`); query.type = new RegExp(`^${type.replace(/\*/g, '.+?')}$`);
} }

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import Following from '../../models/following'; import Following from '../../models/following';
import notify from '../../common/notify'; import notify from '../../common/notify';
@ -19,7 +19,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const follower = user; const follower = user;
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id!').get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// 自分自身 // 自分自身

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import Following from '../../models/following'; import Following from '../../models/following';
import event from '../../event'; import event from '../../event';
@ -18,7 +18,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const follower = user; const follower = user;
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id!').get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Check if the followee is yourself // Check if the followee is yourself

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import AccessToken from '../../models/access-token'; import AccessToken from '../../models/access-token';
import serialize from '../../serializers/app'; import serialize from '../../serializers/app';
@ -14,15 +14,15 @@ import serialize from '../../serializers/app';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter // Get 'sort' parameter
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get(); const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').$;
if (sortError) return rej('invalid sort param'); if (sortError) return rej('invalid sort param');
// Get tokens // Get tokens

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Favorite from '../../models/favorite'; import Favorite from '../../models/favorite';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -14,15 +14,15 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter // Get 'sort' parameter
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get(); const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').$;
if (sortError) return rej('invalid sort param'); if (sortError) return rej('invalid sort param');
// Get favorites // Get favorites

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Notification from '../../models/notification'; import Notification from '../../models/notification';
import serialize from '../../serializers/notification'; import serialize from '../../serializers/notification';
import getFriends from '../../common/get-friends'; import getFriends from '../../common/get-friends';
@ -16,27 +16,27 @@ import getFriends from '../../common/get-friends';
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'following' parameter // Get 'following' parameter
const [following = false, followingError] = const [following = false, followingError] =
it(params.following).expect.boolean().get(); $(params.following).optional.boolean().$;
if (followingError) return rej('invalid following param'); if (followingError) return rej('invalid following param');
// Get 'mark_as_read' parameter // Get 'mark_as_read' parameter
const [markAsRead = true, markAsReadErr] = it(params.mark_as_read).expect.boolean().get(); const [markAsRead = true, markAsReadErr] = $(params.mark_as_read).optional.boolean().$;
if (markAsReadErr) return rej('invalid mark_as_read param'); if (markAsReadErr) return rej('invalid mark_as_read param');
// Get 'type' parameter // Get 'type' parameter
const [type, typeErr] = it(params.type).expect.array().unique().allString().get(); const [type, typeErr] = $(params.type).optional.array('string').unique().$;
if (typeErr) return rej('invalid type param'); if (typeErr) return rej('invalid type param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
@ -53,7 +53,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
}; };
if (following) { if (following) {
// ID list of the user itself and other users who the user follows // ID list of the user $self and other users who the user follows
const followingIds = await getFriends(user._id); const followingIds = await getFriends(user._id);
query.notifier_id = { query.notifier_id = {

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Signin from '../../models/signin'; import Signin from '../../models/signin';
import serialize from '../../serializers/signin'; import serialize from '../../serializers/signin';
@ -14,15 +14,15 @@ import serialize from '../../serializers/signin';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user'; import { isValidName, isValidDescription, isValidLocation, isValidBirthday } from '../../models/user';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
@ -19,32 +19,32 @@ import config from '../../../conf';
*/ */
module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => { module.exports = async (params, user, _, isSecure) => new Promise(async (res, rej) => {
// Get 'name' parameter // Get 'name' parameter
const [name, nameErr] = it(params.name).expect.string().validate(isValidName).get(); const [name, nameErr] = $(params.name).optional.string().pipe(isValidName).$;
if (nameErr) return rej('invalid name param'); if (nameErr) return rej('invalid name param');
if (name) user.name = name; if (name) user.name = name;
// Get 'description' parameter // Get 'description' parameter
const [description, descriptionErr] = it(params.description).expect.nullable.string().validate(isValidDescription).get(); const [description, descriptionErr] = $(params.description).optional.nullable.string().pipe(isValidDescription).$;
if (descriptionErr) return rej('invalid description param'); if (descriptionErr) return rej('invalid description param');
if (description !== undefined) user.description = description; if (description !== undefined) user.description = description;
// Get 'location' parameter // Get 'location' parameter
const [location, locationErr] = it(params.location).expect.nullable.string().validate(isValidLocation).get(); const [location, locationErr] = $(params.location).optional.nullable.string().pipe(isValidLocation).$;
if (locationErr) return rej('invalid location param'); if (locationErr) return rej('invalid location param');
if (location !== undefined) user.profile.location = location; if (location !== undefined) user.profile.location = location;
// Get 'birthday' parameter // Get 'birthday' parameter
const [birthday, birthdayErr] = it(params.birthday).expect.nullable.string().validate(isValidBirthday).get(); const [birthday, birthdayErr] = $(params.birthday).optional.nullable.string().pipe(isValidBirthday).$;
if (birthdayErr) return rej('invalid birthday param'); if (birthdayErr) return rej('invalid birthday param');
if (birthday !== undefined) user.profile.birthday = birthday; if (birthday !== undefined) user.profile.birthday = birthday;
// Get 'avatar_id' parameter // Get 'avatar_id' parameter
const [avatarId, avatarIdErr] = it(params.avatar_id).expect.id().get(); const [avatarId, avatarIdErr] = $(params.avatar_id).optional.id().$;
if (avatarIdErr) return rej('invalid avatar_id param'); if (avatarIdErr) return rej('invalid avatar_id param');
if (avatarId) user.avatar_id = avatarId; if (avatarId) user.avatar_id = avatarId;
// Get 'banner_id' parameter // Get 'banner_id' parameter
const [bannerId, bannerIdErr] = it(params.banner_id).expect.id().get(); const [bannerId, bannerIdErr] = $(params.banner_id).optional.id().$;
if (bannerIdErr) return rej('invalid banner_id param'); if (bannerIdErr) return rej('invalid banner_id param');
if (bannerId) user.banner_id = bannerId; if (bannerId) user.banner_id = bannerId;

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import History from '../../models/messaging-history'; import History from '../../models/messaging-history';
import serialize from '../../serializers/messaging-message'; import serialize from '../../serializers/messaging-message';
@ -14,7 +14,7 @@ import serialize from '../../serializers/messaging-message';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get history // Get history

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Message from '../../models/messaging-message'; import Message from '../../models/messaging-message';
import User from '../../models/user'; import User from '../../models/user';
import serialize from '../../serializers/messaging-message'; import serialize from '../../serializers/messaging-message';
@ -17,7 +17,7 @@ import { publishMessagingStream } from '../../event';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().get(); const [recipientId, recipientIdErr] = $(params.user_id).id().$;
if (recipientIdErr) return rej('invalid user_id param'); if (recipientIdErr) return rej('invalid user_id param');
// Fetch recipient // Fetch recipient
@ -34,19 +34,19 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} }
// Get 'mark_as_read' parameter // Get 'mark_as_read' parameter
const [markAsRead = true, markAsReadErr] = it(params.mark_as_read).expect.boolean().get(); const [markAsRead = true, markAsReadErr] = $(params.mark_as_read).optional.boolean().$;
if (markAsReadErr) return rej('invalid mark_as_read param'); if (markAsReadErr) return rej('invalid mark_as_read param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Message from '../../../models/messaging-message'; import Message from '../../../models/messaging-message';
import { isValidText } from '../../../models/messaging-message'; import { isValidText } from '../../../models/messaging-message';
import History from '../../../models/messaging-history'; import History from '../../../models/messaging-history';
@ -21,7 +21,7 @@ import config from '../../../../conf';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [recipientId, recipientIdErr] = it(params.user_id).expect.id().required().get(); const [recipientId, recipientIdErr] = $(params.user_id).id().$;
if (recipientIdErr) return rej('invalid user_id param'); if (recipientIdErr) return rej('invalid user_id param');
// Myself // Myself
@ -43,11 +43,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
} }
// Get 'text' parameter // Get 'text' parameter
const [text, textErr] = it(params.text).expect.string().validate(isValidText).get(); const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
if (textErr) return rej('invalid text'); if (textErr) return rej('invalid text');
// Get 'file_id' parameter // Get 'file_id' parameter
const [fileId, fileIdErr] = it(params.file_id).expect.id().get(); const [fileId, fileIdErr] = $(params.file_id).optional.id().$;
if (fileIdErr) return rej('invalid file_id param'); if (fileIdErr) return rej('invalid file_id param');
let file = null; let file = null;

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import App from '../../models/app'; import App from '../../models/app';
import serialize from '../../serializers/app'; import serialize from '../../serializers/app';
@ -14,11 +14,11 @@ import serialize from '../../serializers/app';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
const query = { const query = {

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Notification from '../../models/notification'; import Notification from '../../models/notification';
import serialize from '../../serializers/notification'; import serialize from '../../serializers/notification';
import event from '../../event'; import event from '../../event';
@ -14,7 +14,7 @@ import event from '../../event';
* @return {Promise<any>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
const [notificationId, notificationIdErr] = it(params.notification_id).expect.id().required().get(); const [notificationId, notificationIdErr] = $(params.notification_id).id().$;
if (notificationIdErr) return rej('invalid notification_id param'); if (notificationIdErr) return rej('invalid notification_id param');
// Get notification // Get notification

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../models/post'; import Post from '../models/post';
import serialize from '../serializers/post'; import serialize from '../serializers/post';
@ -13,23 +13,23 @@ import serialize from '../serializers/post';
*/ */
module.exports = (params) => new Promise(async (res, rej) => { module.exports = (params) => new Promise(async (res, rej) => {
// Get 'include_replies' parameter // Get 'include_replies' parameter
const [includeReplies = true, includeRepliesErr] = it(params.include_replies).expect.boolean().get(); const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
if (includeRepliesErr) return rej('invalid include_replies param'); if (includeRepliesErr) return rej('invalid include_replies param');
// Get 'include_reposts' parameter // Get 'include_reposts' parameter
const [includeReposts = true, includeRepostsErr] = it(params.include_reposts).expect.boolean().get(); const [includeReposts = true, includeRepostsErr] = $(params.include_reposts).optional.boolean().$;
if (includeRepostsErr) return rej('invalid include_reposts param'); if (includeRepostsErr) return rej('invalid include_reposts param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -14,15 +14,15 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
const parse = require('../../../common/text'); const parse = require('../../../common/text');
import Post from '../../models/post'; import Post from '../../models/post';
import { isValidText } from '../../models/post'; import { isValidText } from '../../models/post';
@ -23,11 +23,11 @@ import config from '../../../conf';
*/ */
module.exports = (params, user, app) => new Promise(async (res, rej) => { module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Get 'text' parameter // Get 'text' parameter
const [text, textErr] = it(params.text).must.be.a.string().validate(isValidText).get(); const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
if (textErr) return rej('invalid text'); if (textErr) return rej('invalid text');
// Get 'media_ids' parameter // Get 'media_ids' parameter
const [mediaIds, mediaIdsErr] = it(params.media_ids).must.be.an.array().unique().range(1, 4).get(); const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$;
if (mediaIdsErr) return rej('invalid media_ids'); if (mediaIdsErr) return rej('invalid media_ids');
let files = []; let files = [];
@ -36,8 +36,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
// forEach だと途中でエラーなどがあっても return できないので // forEach だと途中でエラーなどがあっても return できないので
// 敢えて for を使っています。 // 敢えて for を使っています。
for (let i = 0; i < mediaIds.length; i++) { for (let i = 0; i < mediaIds.length; i++) {
const [mediaId, mediaIdErr] = it(mediaIds[i]).must.be.an.id().required().get(); const mediaId = mediaIds[i];
if (mediaIdErr) return rej('invalid media id');
// Fetch file // Fetch file
// SELECT _id // SELECT _id
@ -59,7 +58,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
} }
// Get 'repost_id' parameter // Get 'repost_id' parameter
const [repostId, repostIdErr] = it(params.repost_id).must.be.an.id().get(); const [repostId, repostIdErr] = $(params.repost_id).optional.id().$;
if (repostIdErr) return rej('invalid repost_id'); if (repostIdErr) return rej('invalid repost_id');
let repost = null; let repost = null;
@ -101,7 +100,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
} }
// Get 'in_reply_to_post_id' parameter // Get 'in_reply_to_post_id' parameter
const [inReplyToPostId, inReplyToPostIdErr] = it(params.reply_to_id, 'id').get(); const [inReplyToPostId, inReplyToPostIdErr] = $(params.reply_to_id).optional.id().$;
if (inReplyToPostIdErr) return rej('invalid in_reply_to_post_id'); if (inReplyToPostIdErr) return rej('invalid in_reply_to_post_id');
let inReplyToPost = null; let inReplyToPost = null;
@ -122,37 +121,24 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
} }
// Get 'poll' parameter // Get 'poll' parameter
const [_poll, pollErr] = it(params.poll, 'object').get(); const [poll, pollErr] = $(params.poll).optional.object()
.have('choices', $().array('string')
.unique()
.range(2, 10)
.each(c => c.length > 0 && c.length < 50))
.$;
if (pollErr) return rej('invalid poll'); if (pollErr) return rej('invalid poll');
let poll = null; if (poll) {
if (_poll !== undefined) { (poll as any).choices = (poll as any).choices.map((choice, i) => ({
const [pollChoices, pollChoicesErr] =
it(params.poll.choices).expect.array()
.required()
.unique()
.allString()
.range(2, 10)
.validate(choices => !choices.some(choice => {
if (typeof choice != 'string') return true;
if (choice.trim().length == 0) return true;
if (choice.trim().length > 50) return true;
return false;
}))
.get();
if (pollChoicesErr) return rej('invalid poll choices');
_poll.choices = pollChoices.map((choice, i) => ({
id: i, // IDを付与 id: i, // IDを付与
text: choice.trim(), text: choice.trim(),
votes: 0 votes: 0
})); }));
poll = _poll;
} }
// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー // テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
if (text === undefined && files === null && repost === null && poll === null) { if (text === undefined && files === null && repost === null && poll === undefined) {
return rej('text, media_ids, repost_id or poll is required'); return rej('text, media_ids, repost_id or poll is required');
} }
@ -162,7 +148,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
media_ids: files ? files.map(file => file._id) : undefined, media_ids: files ? files.map(file => file._id) : undefined,
reply_to_id: inReplyToPost ? inReplyToPost._id : undefined, reply_to_id: inReplyToPost ? inReplyToPost._id : undefined,
repost_id: repost ? repost._id : undefined, repost_id: repost ? repost._id : undefined,
poll: poll ? poll : undefined, poll: poll,
text: text, text: text,
user_id: user._id, user_id: user._id,
app_id: app ? app._id : null app_id: app ? app._id : null
@ -235,7 +221,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
addMention(inReplyToPost.user_id, 'reply'); addMention(inReplyToPost.user_id, 'reply');
} }
// If it is repost // If $ is repost
if (repost) { if (repost) {
// Notify // Notify
const type = text ? 'quote' : 'repost'; const type = text ? 'quote' : 'repost';
@ -243,7 +229,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
post_id: post._id post_id: post._id
}); });
// If it is quote repost // If $ is quote repost
if (text) { if (text) {
// Add mention // Add mention
addMention(repost.user_id, 'quote'); addMention(repost.user_id, 'quote');

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Favorite from '../../../models/favorite'; import Favorite from '../../../models/favorite';
import Post from '../../../models/post'; import Post from '../../../models/post';
@ -14,7 +14,7 @@ import Post from '../../../models/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get favoritee // Get favoritee

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Favorite from '../../../models/favorite'; import Favorite from '../../../models/favorite';
import Post from '../../../models/post'; import Post from '../../../models/post';
@ -14,7 +14,7 @@ import Post from '../../../models/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get favoritee // Get favoritee

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import Like from '../../models/like'; import Like from '../../models/like';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
@ -15,19 +15,19 @@ import serialize from '../../serializers/user';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter // Get 'sort' parameter
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get(); const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').$;
if (sortError) return rej('invalid sort param'); if (sortError) return rej('invalid sort param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Like from '../../../models/like'; import Like from '../../../models/like';
import Post from '../../../models/post'; import Post from '../../../models/post';
import User from '../../../models/user'; import User from '../../../models/user';
@ -16,7 +16,7 @@ import notify from '../../../common/notify';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get likee // Get likee

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Like from '../../../models/like'; import Like from '../../../models/like';
import Post from '../../../models/post'; import Post from '../../../models/post';
import User from '../../../models/user'; import User from '../../../models/user';
@ -16,7 +16,7 @@ import User from '../../../models/user';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get likee // Get likee

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import getFriends from '../../common/get-friends'; import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -16,19 +16,19 @@ import serialize from '../../serializers/post';
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'following' parameter // Get 'following' parameter
const [following = false, followingError] = const [following = false, followingError] =
it(params.following).expect.boolean().get(); $(params.following).optional.boolean().$;
if (followingError) return rej('invalid following param'); if (followingError) return rej('invalid following param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Vote from '../../../models/poll-vote'; import Vote from '../../../models/poll-vote';
import Post from '../../../models/post'; import Post from '../../../models/post';
import notify from '../../../common/notify'; import notify from '../../../common/notify';
@ -15,7 +15,7 @@ import notify from '../../../common/notify';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get votee // Get votee
@ -33,10 +33,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'choice' parameter // Get 'choice' parameter
const [choice, choiceError] = const [choice, choiceError] =
it(params.choice).expect.string() $(params.choice).string()
.required() .pipe(c => post.poll.choices.some(x => x.id == c))
.validate(c => post.poll.choices.some(x => x.id == c)) .$;
.get();
if (choiceError) return rej('invalid choice param'); if (choiceError) return rej('invalid choice param');
// if already voted // if already voted

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -14,19 +14,19 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'sort' parameter // Get 'sort' parameter
const [sort = 'desc', sortError] = it(params.sort).expect.string().or('desc asc').get(); const [sort = 'desc', sortError] = $(params.sort).optional.string().or('desc asc').$;
if (sortError) return rej('invalid sort param'); if (sortError) return rej('invalid sort param');
// Lookup post // Lookup post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -14,19 +14,19 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import * as mongo from 'mongodb'; import * as mongo from 'mongodb';
import it from 'cafy'; import $ from 'cafy';
const escapeRegexp = require('escape-regexp'); const escapeRegexp = require('escape-regexp');
import Post from '../../models/post'; import Post from '../../models/post';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -17,18 +17,18 @@ import config from '../../../conf';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'query' parameter // Get 'query' parameter
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').get(); const [query, queryError] = $(params.query).string().pipe(x => x != '').$;
if (queryError) return rej('invalid query param'); if (queryError) return rej('invalid query param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'max' parameter // Get 'max' parameter
const [max = 10, maxErr] = it(params.max).expect.number().range(1, 30).get(); const [max = 10, maxErr] = $(params.max).optional.number().range(1, 30).$;
if (maxErr) return rej('invalid max param'); if (maxErr) return rej('invalid max param');
// If Elasticsearch is available, search by it // If Elasticsearch is available, search by $
// If not, search by MongoDB // If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative) (config.elasticsearch.enable ? byElasticsearch : byNative)
(res, rej, me, query, offset, max); (res, rej, me, query, offset, max);

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -14,7 +14,7 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
// Get 'post_id' parameter // Get 'post_id' parameter
const [postId, postIdErr] = it(params.post_id, 'id!').get(); const [postId, postIdErr] = $(params.post_id).id().$;
if (postIdErr) return rej('invalid post_id param'); if (postIdErr) return rej('invalid post_id param');
// Get post // Get post

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import getFriends from '../../common/get-friends'; import getFriends from '../../common/get-friends';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -16,15 +16,15 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, user, app) => new Promise(async (res, rej) => { module.exports = (params, user, app) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
@ -32,7 +32,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
return rej('cannot set since_id and max_id'); return rej('cannot set since_id and max_id');
} }
// ID list of the user itself and other users who the user follows // ID list of the user $self and other users who the user follows
const followingIds = await getFriends(user._id); const followingIds = await getFriends(user._id);
// Construct query // Construct query

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import { validateUsername } from '../../models/user'; import { validateUsername } from '../../models/user';
@ -13,7 +13,7 @@ import { validateUsername } from '../../models/user';
*/ */
module.exports = async (params) => new Promise(async (res, rej) => { module.exports = async (params) => new Promise(async (res, rej) => {
// Get 'username' parameter // Get 'username' parameter
const [username, usernameError] = it(params.username).expect.string().required().trim().validate(validateUsername).get(); const [username, usernameError] = $(params.username).string().pipe(validateUsername).$;
if (usernameError) return rej('invalid username param'); if (usernameError) return rej('invalid username param');
// Get exist // Get exist

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../models/user'; import User from '../models/user';
import serialize from '../serializers/user'; import serialize from '../serializers/user';
@ -14,15 +14,15 @@ import serialize from '../serializers/user';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import Following from '../../models/following'; import Following from '../../models/following';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
@ -16,19 +16,19 @@ import getFriends from '../../common/get-friends';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id!').get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Get 'iknow' parameter // Get 'iknow' parameter
const [iknow = false, iknowErr] = it(params.iknow).expect.boolean().get(); const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$;
if (iknowErr) return rej('invalid iknow param'); if (iknowErr) return rej('invalid iknow param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'cursor' parameter // Get 'cursor' parameter
const [cursor = null, cursorErr] = it(params.cursor).expect.id().get(); const [cursor = null, cursorErr] = $(params.cursor).optional.id().$;
if (cursorErr) return rej('invalid cursor param'); if (cursorErr) return rej('invalid cursor param');
// Lookup user // Lookup user

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import Following from '../../models/following'; import Following from '../../models/following';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
@ -16,19 +16,19 @@ import getFriends from '../../common/get-friends';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id!').get(); const [userId, userIdErr] = $(params.user_id).id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Get 'iknow' parameter // Get 'iknow' parameter
const [iknow = false, iknowErr] = it(params.iknow).expect.boolean().get(); const [iknow = false, iknowErr] = $(params.iknow).optional.boolean().$;
if (iknowErr) return rej('invalid iknow param'); if (iknowErr) return rej('invalid iknow param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'cursor' parameter // Get 'cursor' parameter
const [cursor = null, cursorErr] = it(params.cursor).expect.id().get(); const [cursor = null, cursorErr] = $(params.cursor).optional.id().$;
if (cursorErr) return rej('invalid cursor param'); if (cursorErr) return rej('invalid cursor param');
// Lookup user // Lookup user

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import Post from '../../models/post'; import Post from '../../models/post';
import User from '../../models/user'; import User from '../../models/user';
import serialize from '../../serializers/post'; import serialize from '../../serializers/post';
@ -15,11 +15,11 @@ import serialize from '../../serializers/post';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id').get(); const [userId, userIdErr] = $(params.user_id).optional.id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Get 'username' parameter // Get 'username' parameter
const [username, usernameErr] = it(params.username, 'string').get(); const [username, usernameErr] = $(params.username).optional.string().$;
if (usernameErr) return rej('invalid username param'); if (usernameErr) return rej('invalid username param');
if (userId === undefined && username === undefined) { if (userId === undefined && username === undefined) {
@ -27,23 +27,23 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
} }
// Get 'include_replies' parameter // Get 'include_replies' parameter
const [includeReplies = true, includeRepliesErr] = it(params.include_replies).expect.boolean().get(); const [includeReplies = true, includeRepliesErr] = $(params.include_replies).optional.boolean().$;
if (includeRepliesErr) return rej('invalid include_replies param'); if (includeRepliesErr) return rej('invalid include_replies param');
// Get 'with_media' parameter // Get 'with_media' parameter
const [withMedia = false, withMediaErr] = it(params.with_media).expect.boolean().get(); const [withMedia = false, withMediaErr] = $(params.with_media).optional.boolean().$;
if (withMediaErr) return rej('invalid with_media param'); if (withMediaErr) return rej('invalid with_media param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'since_id' parameter // Get 'since_id' parameter
const [sinceId, sinceIdErr] = it(params.since_id).expect.id().get(); const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
if (sinceIdErr) return rej('invalid since_id param'); if (sinceIdErr) return rej('invalid since_id param');
// Get 'max_id' parameter // Get 'max_id' parameter
const [maxId, maxIdErr] = it(params.max_id).expect.id().get(); const [maxId, maxIdErr] = $(params.max_id).optional.id().$;
if (maxIdErr) return rej('invalid max_id param'); if (maxIdErr) return rej('invalid max_id param');
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
import getFriends from '../../common/get-friends'; import getFriends from '../../common/get-friends';
@ -15,14 +15,14 @@ import getFriends from '../../common/get-friends';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// ID list of the user itself and other users who the user follows // ID list of the user $self and other users who the user follows
const followingIds = await getFriends(me._id); const followingIds = await getFriends(me._id);
const users = await User const users = await User

View file

@ -2,7 +2,7 @@
* Module dependencies * Module dependencies
*/ */
import * as mongo from 'mongodb'; import * as mongo from 'mongodb';
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
import config from '../../../conf'; import config from '../../../conf';
@ -17,18 +17,18 @@ const escapeRegexp = require('escape-regexp');
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'query' parameter // Get 'query' parameter
const [query, queryError] = it(params.query).expect.string().required().trim().validate(x => x != '').get(); const [query, queryError] = $(params.query).string().pipe(x => x != '').$;
if (queryError) return rej('invalid query param'); if (queryError) return rej('invalid query param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'max' parameter // Get 'max' parameter
const [max = 10, maxErr] = it(params.max).expect.number().range(1, 30).get(); const [max = 10, maxErr] = $(params.max).optional.number().range(1, 30).$;
if (maxErr) return rej('invalid max param'); if (maxErr) return rej('invalid max param');
// If Elasticsearch is available, search by it // If Elasticsearch is available, search by $
// If not, search by MongoDB // If not, search by MongoDB
(config.elasticsearch.enable ? byElasticsearch : byNative) (config.elasticsearch.enable ? byElasticsearch : byNative)
(res, rej, me, query, offset, max); (res, rej, me, query, offset, max);

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import { validateUsername } from '../../models/user'; import { validateUsername } from '../../models/user';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
@ -15,15 +15,15 @@ import serialize from '../../serializers/user';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'query' parameter // Get 'query' parameter
const [query, queryError] = it(params.query).expect.string().required().trim().validate(validateUsername).get(); const [query, queryError] = $(params.query).string().pipe(validateUsername).$;
if (queryError) return rej('invalid query param'); if (queryError) return rej('invalid query param');
// Get 'offset' parameter // Get 'offset' parameter
const [offset = 0, offsetErr] = it(params.offset).expect.number().min(0).get(); const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
if (offsetErr) return rej('invalid offset param'); if (offsetErr) return rej('invalid offset param');
// Get 'limit' parameter // Get 'limit' parameter
const [limit = 10, limitErr] = it(params.limit).expect.number().range(1, 100).get(); const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
if (limitErr) return rej('invalid limit param'); if (limitErr) return rej('invalid limit param');
const users = await User const users = await User

View file

@ -1,7 +1,7 @@
/** /**
* Module dependencies * Module dependencies
*/ */
import it from 'cafy'; import $ from 'cafy';
import User from '../../models/user'; import User from '../../models/user';
import serialize from '../../serializers/user'; import serialize from '../../serializers/user';
@ -14,11 +14,11 @@ import serialize from '../../serializers/user';
*/ */
module.exports = (params, me) => new Promise(async (res, rej) => { module.exports = (params, me) => new Promise(async (res, rej) => {
// Get 'user_id' parameter // Get 'user_id' parameter
const [userId, userIdErr] = it(params.user_id, 'id').get(); const [userId, userIdErr] = $(params.user_id).optional.id().$;
if (userIdErr) return rej('invalid user_id param'); if (userIdErr) return rej('invalid user_id param');
// Get 'username' parameter // Get 'username' parameter
const [username, usernameErr] = it(params.username, 'string').get(); const [username, usernameErr] = $(params.username).optional.string().$;
if (usernameErr) return rej('invalid username param'); if (usernameErr) return rej('invalid username param');
if (userId === undefined && username === undefined) { if (userId === undefined && username === undefined) {