mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-14 06:00:44 +01:00
cafy 5.xに移行
This commit is contained in:
parent
fd2c45cc02
commit
7602e8f938
90 changed files with 255 additions and 350 deletions
|
@ -88,7 +88,7 @@
|
|||
"autwh": "0.1.0",
|
||||
"bcryptjs": "2.4.3",
|
||||
"bootstrap-vue": "2.0.0-rc.6",
|
||||
"cafy": "3.2.1",
|
||||
"cafy": "5.1.0",
|
||||
"chai": "4.1.2",
|
||||
"chai-http": "4.0.0",
|
||||
"chalk": "2.4.0",
|
||||
|
|
29
src/cafy-id.ts
Normal file
29
src/cafy-id.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import { Query } from 'cafy';
|
||||
|
||||
export const isAnId = x => mongo.ObjectID.isValid(x);
|
||||
export const isNotAnId = x => !isAnId(x);
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
export default class ID extends Query<mongo.ObjectID> {
|
||||
constructor(...args) {
|
||||
super(...args);
|
||||
|
||||
this.transform = v => {
|
||||
if (isAnId(v) && !mongo.ObjectID.prototype.isPrototypeOf(v)) {
|
||||
return new mongo.ObjectID(v);
|
||||
} else {
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
this.pushFirstTimeValidator(v => {
|
||||
if (!mongo.ObjectID.prototype.isPrototypeOf(v) && isNotAnId(v)) {
|
||||
return new Error('must-be-an-id');
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import deepcopy = require('deepcopy');
|
||||
import db from '../db/mongodb';
|
||||
import Reaction from './note-reaction';
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import * as mongo from 'mongodb';
|
||||
import deepcopy = require('deepcopy');
|
||||
import db from '../db/mongodb';
|
||||
|
||||
const UserList = db.get<IUserList>('userList');
|
||||
|
@ -38,3 +39,29 @@ export async function deleteUserList(userList: string | mongo.ObjectID | IUserLi
|
|||
_id: u._id
|
||||
});
|
||||
}
|
||||
|
||||
export const pack = (
|
||||
userList: string | mongo.ObjectID | IUserList
|
||||
) => new Promise<any>(async (resolve, reject) => {
|
||||
let _userList: any;
|
||||
|
||||
if (mongo.ObjectID.prototype.isPrototypeOf(userList)) {
|
||||
_userList = await UserList.findOne({
|
||||
_id: userList
|
||||
});
|
||||
} else if (typeof userList === 'string') {
|
||||
_userList = await UserList.findOne({
|
||||
_id: new mongo.ObjectID(userList)
|
||||
});
|
||||
} else {
|
||||
_userList = deepcopy(userList);
|
||||
}
|
||||
|
||||
if (!_userList) throw `invalid userList arg ${userList}`;
|
||||
|
||||
// Rename _id to id
|
||||
_userList.id = _userList._id;
|
||||
delete _userList._id;
|
||||
|
||||
resolve(_userList);
|
||||
});
|
||||
|
|
|
@ -6,9 +6,6 @@ import Note from '../../../../models/note';
|
|||
|
||||
/**
|
||||
* Aggregate notes
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = params => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -6,9 +6,6 @@ import User from '../../../../models/user';
|
|||
|
||||
/**
|
||||
* Aggregate users
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = params => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import User from '../../../../../models/user';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
|
@ -9,9 +9,6 @@ import Note from '../../../../../models/note';
|
|||
|
||||
/**
|
||||
* Aggregate activity of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
@ -19,7 +16,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import User from '../../../../../models/user';
|
||||
import FollowedLog from '../../../../../models/followed-log';
|
||||
|
||||
/**
|
||||
* Aggregate followers of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import User from '../../../../../models/user';
|
||||
import FollowingLog from '../../../../../models/following-log';
|
||||
|
||||
/**
|
||||
* Aggregate following of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import User from '../../../../../models/user';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
/**
|
||||
* Aggregate note of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import User from '../../../../../models/user';
|
||||
import Reaction from '../../../../../models/note-reaction';
|
||||
|
||||
|
@ -13,7 +13,7 @@ import Reaction from '../../../../../models/note-reaction';
|
|||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -79,7 +79,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
if (descriptionErr) return rej('invalid description param');
|
||||
|
||||
// Get 'permission' parameter
|
||||
const [permission, permissionErr] = $(params.permission).array('string').unique().$;
|
||||
const [permission, permissionErr] = $(params.permission).array($().string()).unique().$;
|
||||
if (permissionErr) return rej('invalid permission param');
|
||||
|
||||
// Get 'callbackUrl' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import App, { pack } from '../../../../models/app';
|
||||
|
||||
/**
|
||||
|
@ -41,7 +41,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
const isSecure = user != null && app == null;
|
||||
|
||||
// Get 'appId' parameter
|
||||
const [appId, appIdErr] = $(params.appId).optional.id().$;
|
||||
const [appId, appIdErr] = $(params.appId).optional.type(ID).$;
|
||||
if (appIdErr) return rej('invalid appId param');
|
||||
|
||||
// Get 'nameId' parameter
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*/
|
||||
import rndstr from 'rndstr';
|
||||
const crypto = require('crypto');
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import App from '../../../../models/app';
|
||||
import AuthSess from '../../../../models/auth-session';
|
||||
import AccessToken from '../../../../models/access-token';
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../cafy-id';
|
||||
import Channel, { pack } from '../../../models/channel';
|
||||
|
||||
/**
|
||||
|
@ -17,11 +17,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -8,10 +8,6 @@ import { pack } from '../../../../models/channel';
|
|||
|
||||
/**
|
||||
* Create a channel
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'title' parameter
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import { default as Channel, IChannel } from '../../../../models/channel';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
|
||||
/**
|
||||
* Show a notes of a channel
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
@ -18,11 +14,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -31,7 +27,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
// Fetch channel
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Channel, { IChannel, pack } from '../../../../models/channel';
|
||||
|
||||
/**
|
||||
* Show a channel
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
// Fetch channel
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Channel from '../../../../models/channel';
|
||||
import Watching from '../../../../models/channel-watching';
|
||||
|
||||
/**
|
||||
* Unwatch a channel
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
//#region Fetch channel
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Channel from '../../../../models/channel';
|
||||
import Watching from '../../../../models/channel-watching';
|
||||
|
||||
/**
|
||||
* Watch a channel
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
const [channelId, channelIdErr] = $(params.channelId).type(ID).$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
//#region Fetch channel
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import DriveFile, { pack } from '../../../../models/drive-file';
|
||||
|
||||
/**
|
||||
* Get drive files
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @param {any} app
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user, app) => {
|
||||
// Get 'limit' parameter
|
||||
|
@ -18,11 +13,11 @@ module.exports = async (params, user, app) => {
|
|||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -31,7 +26,7 @@ module.exports = async (params, user, app) => {
|
|||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).$;
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
// Get 'type' parameter
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import { validateFileName, pack } from '../../../../../models/drive-file';
|
||||
import create from '../../../../../services/drive/add-file';
|
||||
|
||||
/**
|
||||
* Create a file
|
||||
*
|
||||
* @param {any} file
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (file, params, user): Promise<any> => {
|
||||
if (file == null) {
|
||||
|
@ -34,7 +29,7 @@ module.exports = async (file, params, user): Promise<any> => {
|
|||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).$;
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
try {
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
|
||||
/**
|
||||
* Find a file(s)
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
|
@ -17,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Issue query
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
|
||||
/**
|
||||
* Show a file
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => {
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
||||
const [fileId, fileIdErr] = $(params.fileId).type(ID).$;
|
||||
if (fileIdErr) throw 'invalid fileId param';
|
||||
|
||||
// Fetch file
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFolder from '../../../../../models/drive-folder';
|
||||
import DriveFile, { validateFileName, pack } from '../../../../../models/drive-file';
|
||||
import { publishDriveStream } from '../../../../../publishers/stream';
|
||||
|
||||
/**
|
||||
* Update a file
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
||||
const [fileId, fileIdErr] = $(params.fileId).type(ID).$;
|
||||
if (fileIdErr) return rej('invalid fileId param');
|
||||
|
||||
// Fetch file
|
||||
|
@ -35,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (name) file.filename = name;
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
const [folderId, folderIdErr] = $(params.folderId).optional.nullable.type(ID).$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
if (folderId !== undefined) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import { pack } from '../../../../../models/drive-file';
|
||||
import uploadFromUrl from '../../../../../services/drive/upload-from-url';
|
||||
|
||||
|
@ -15,7 +15,7 @@ module.exports = async (params, user): Promise<any> => {
|
|||
if (urlErr) throw 'invalid url param';
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).$;
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
return pack(await uploadFromUrl(url, user, folderId));
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import DriveFolder, { pack } from '../../../../models/drive-folder';
|
||||
|
||||
/**
|
||||
* Get drive folders
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @param {any} app
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
@ -18,11 +13,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
@ -31,7 +26,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.type(ID).$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Construct query
|
||||
|
|
|
@ -1,16 +1,12 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder';
|
||||
import { publishDriveStream } from '../../../../../publishers/stream';
|
||||
|
||||
/**
|
||||
* Create drive folder
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
|
@ -18,7 +14,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parentId' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.type(ID).$;
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
|
||||
// If the parent folder is specified
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFolder, { pack } from '../../../../../models/drive-folder';
|
||||
|
||||
/**
|
||||
* Find a folder(s)
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
|
@ -17,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parentId' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.type(ID).$;
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
|
||||
// Issue query
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFolder, { pack } from '../../../../../models/drive-folder';
|
||||
|
||||
/**
|
||||
* Show a folder
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).id().$;
|
||||
const [folderId, folderIdErr] = $(params.folderId).type(ID).$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Get folder
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import DriveFolder, { isValidFolderName, pack } from '../../../../../models/drive-folder';
|
||||
import { publishDriveStream } from '../../../../../publishers/stream';
|
||||
|
||||
/**
|
||||
* Update a folder
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).id().$;
|
||||
const [folderId, folderIdErr] = $(params.folderId).type(ID).$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Fetch folder
|
||||
|
@ -34,7 +30,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (name) folder.name = name;
|
||||
|
||||
// Get 'parentId' parameter
|
||||
const [parentId, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||
const [parentId, parentIdErr] = $(params.parentId).optional.nullable.type(ID).$;
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
if (parentId !== undefined) {
|
||||
if (parentId === null) {
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import DriveFile, { pack } from '../../../../models/drive-file';
|
||||
|
||||
/**
|
||||
* Get drive stream
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
@ -17,11 +13,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import create from '../../../../services/following/create';
|
||||
|
@ -13,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import deleteFollowing from '../../../../services/following/delete';
|
||||
|
@ -13,7 +13,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the followee is yourself
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Following from '../../../../models/following';
|
||||
import { isLocalUser } from '../../../../models/user';
|
||||
|
||||
/**
|
||||
* Stalk a user
|
||||
|
@ -9,7 +8,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch following
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Following from '../../../../models/following';
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const follower = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch following
|
||||
|
|
|
@ -7,10 +7,6 @@ import { pack } from '../../../../models/app';
|
|||
|
||||
/**
|
||||
* Get authorized apps of my account
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -7,10 +7,6 @@ import User from '../../../../models/user';
|
|||
|
||||
/**
|
||||
* Change password
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'currentPasword' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Favorite, { pack } from '../../../../models/favorite';
|
||||
|
||||
/**
|
||||
|
@ -13,11 +13,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Notification from '../../../../models/notification';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { pack } from '../../../../models/notification';
|
||||
|
@ -22,7 +22,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = $(params.type).optional.array('string').unique().$;
|
||||
const [type, typeErr] = $(params.type).optional.array($().string()).unique().$;
|
||||
if (typeErr) return rej('invalid type param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
|
@ -30,11 +30,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Note from '../../../../models/note';
|
||||
import { pack } from '../../../../models/user';
|
||||
|
||||
/**
|
||||
* Pin note
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Fetch pinee
|
||||
|
|
|
@ -9,10 +9,6 @@ import generateUserToken from '../../common/generate-native-user-token';
|
|||
|
||||
/**
|
||||
* Regenerate native token
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'password' parameter
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Signin, { pack } from '../../../../models/signin';
|
||||
|
||||
/**
|
||||
* Get signin history of my account
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
@ -17,11 +13,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User, { isValidName, isValidDescription, isValidLocation, isValidBirthday, pack } from '../../../../models/user';
|
||||
import event from '../../../../publishers/stream';
|
||||
|
||||
|
@ -32,12 +32,12 @@ module.exports = async (params, user, app) => new Promise(async (res, rej) => {
|
|||
if (birthday !== undefined) user.profile.birthday = birthday;
|
||||
|
||||
// Get 'avatarId' parameter
|
||||
const [avatarId, avatarIdErr] = $(params.avatarId).optional.id().$;
|
||||
const [avatarId, avatarIdErr] = $(params.avatarId).optional.type(ID).$;
|
||||
if (avatarIdErr) return rej('invalid avatarId param');
|
||||
if (avatarId) user.avatarId = avatarId;
|
||||
|
||||
// Get 'bannerId' parameter
|
||||
const [bannerId, bannerIdErr] = $(params.bannerId).optional.id().$;
|
||||
const [bannerId, bannerIdErr] = $(params.bannerId).optional.type(ID).$;
|
||||
if (bannerIdErr) return rej('invalid bannerId param');
|
||||
if (bannerId) user.bannerId = bannerId;
|
||||
|
||||
|
|
|
@ -7,10 +7,6 @@ import event from '../../../../publishers/stream';
|
|||
|
||||
/**
|
||||
* Update myself
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name' parameter
|
||||
|
|
|
@ -8,7 +8,7 @@ import event from '../../../../publishers/stream';
|
|||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'home' parameter
|
||||
const [home, homeErr] = $(params.home).optional.array().each(
|
||||
$().strict.object()
|
||||
$().object(true)
|
||||
.have('name', $().string())
|
||||
.have('id', $().string())
|
||||
.have('place', $().string())
|
||||
|
|
|
@ -8,7 +8,7 @@ import event from '../../../../publishers/stream';
|
|||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'home' parameter
|
||||
const [home, homeErr] = $(params.home).optional.array().each(
|
||||
$().strict.object()
|
||||
$().object(true)
|
||||
.have('name', $().string())
|
||||
.have('id', $().string())
|
||||
.have('data', $().object())).$;
|
||||
|
|
|
@ -8,10 +8,6 @@ import { pack } from '../../../../models/messaging-message';
|
|||
|
||||
/**
|
||||
* Show messaging history
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Message from '../../../../models/messaging-message';
|
||||
import User from '../../../../models/user';
|
||||
import { pack } from '../../../../models/messaging-message';
|
||||
|
@ -16,7 +16,7 @@ import read from '../../common/read-messaging-message';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.userId).id().$;
|
||||
const [recipientId, recipientIdErr] = $(params.userId).type(ID).$;
|
||||
if (recipientIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch recipient
|
||||
|
@ -41,11 +41,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import Message from '../../../../../models/messaging-message';
|
||||
import { isValidText } from '../../../../../models/messaging-message';
|
||||
import History from '../../../../../models/messaging-history';
|
||||
|
@ -16,14 +16,10 @@ import config from '../../../../../config';
|
|||
|
||||
/**
|
||||
* Create a message
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.userId).id().$;
|
||||
const [recipientId, recipientIdErr] = $(params.userId).type(ID).$;
|
||||
if (recipientIdErr) return rej('invalid userId param');
|
||||
|
||||
// Myself
|
||||
|
@ -49,7 +45,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).optional.id().$;
|
||||
const [fileId, fileIdErr] = $(params.fileId).optional.type(ID).$;
|
||||
if (fileIdErr) return rej('invalid fileId param');
|
||||
|
||||
let file = null;
|
||||
|
|
|
@ -6,10 +6,6 @@ import Mute from '../../../../models/mute';
|
|||
|
||||
/**
|
||||
* Get count of unread messages
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const mute = await Mute.find({
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Mute from '../../../../models/mute';
|
||||
|
||||
/**
|
||||
* Mute a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Mute from '../../../../models/mute';
|
||||
|
||||
|
@ -12,7 +12,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const muter = user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the mutee is yourself
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { pack } from '../../../../models/user';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
|
||||
/**
|
||||
* Get muted users of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} me
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'iknow' parameter
|
||||
|
@ -23,7 +19,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.id().$;
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).$;
|
||||
if (cursorErr) return rej('invalid cursor param');
|
||||
|
||||
// Construct query
|
||||
|
|
|
@ -6,10 +6,6 @@ import App, { pack } from '../../../../models/app';
|
|||
|
||||
/**
|
||||
* Get my apps
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../cafy-id';
|
||||
import Note, { pack } from '../../../models/note';
|
||||
|
||||
/**
|
||||
|
@ -33,11 +33,11 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import Note, { pack } from '../../../../models/note';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note, { INote, isValidText, isValidCw, pack } from '../../../../models/note';
|
||||
import { ILocalUser } from '../../../../models/user';
|
||||
import Channel, { IChannel } from '../../../../models/channel';
|
||||
|
@ -11,11 +11,6 @@ import { IApp } from '../../../../models/app';
|
|||
|
||||
/**
|
||||
* Create a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @param {any} app
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res, rej) => {
|
||||
// Get 'visibility' parameter
|
||||
|
@ -35,11 +30,11 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
|||
if (viaMobileErr) return rej('invalid viaMobile');
|
||||
|
||||
// Get 'tags' parameter
|
||||
const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
|
||||
const [tags = [], tagsErr] = $(params.tags).optional.array($().string().range(1, 32)).unique().$;
|
||||
if (tagsErr) return rej('invalid tags');
|
||||
|
||||
// Get 'geo' parameter
|
||||
const [geo, geoErr] = $(params.geo).optional.nullable.strict.object()
|
||||
const [geo, geoErr] = $(params.geo).optional.nullable.object(true)
|
||||
.have('coordinates', $().array().length(2)
|
||||
.item(0, $().number().range(-180, 180))
|
||||
.item(1, $().number().range(-90, 90)))
|
||||
|
@ -52,7 +47,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
|||
if (geoErr) return rej('invalid geo');
|
||||
|
||||
// Get 'mediaIds' parameter
|
||||
const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array('id').unique().range(1, 4).$;
|
||||
const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array($().type(ID)).unique().range(1, 4).$;
|
||||
if (mediaIdsErr) return rej('invalid mediaIds');
|
||||
|
||||
let files = [];
|
||||
|
@ -79,7 +74,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
|||
}
|
||||
|
||||
// Get 'renoteId' parameter
|
||||
const [renoteId, renoteIdErr] = $(params.renoteId).optional.id().$;
|
||||
const [renoteId, renoteIdErr] = $(params.renoteId).optional.type(ID).$;
|
||||
if (renoteIdErr) return rej('invalid renoteId');
|
||||
|
||||
let renote: INote = null;
|
||||
|
@ -100,7 +95,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
|||
}
|
||||
|
||||
// Get 'replyId' parameter
|
||||
const [replyId, replyIdErr] = $(params.replyId).optional.id().$;
|
||||
const [replyId, replyIdErr] = $(params.replyId).optional.type(ID).$;
|
||||
if (replyIdErr) return rej('invalid replyId');
|
||||
|
||||
let reply: INote = null;
|
||||
|
@ -121,7 +116,7 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
|||
}
|
||||
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).optional.id().$;
|
||||
const [channelId, channelIdErr] = $(params.channelId).optional.type(ID).$;
|
||||
if (channelIdErr) return rej('invalid channelId');
|
||||
|
||||
let channel: IChannel = null;
|
||||
|
@ -162,8 +157,8 @@ module.exports = (params, user: ILocalUser, app: IApp) => new Promise(async (res
|
|||
}
|
||||
|
||||
// Get 'poll' parameter
|
||||
const [poll, pollErr] = $(params.poll).optional.strict.object()
|
||||
.have('choices', $().array('string')
|
||||
const [poll, pollErr] = $(params.poll).optional.object(true)
|
||||
.have('choices', $().array($().string())
|
||||
.unique()
|
||||
.range(2, 10)
|
||||
.each(c => c.length > 0 && c.length < 50))
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import Favorite from '../../../../../models/favorite';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
/**
|
||||
* Favorite a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get favoritee
|
||||
|
|
|
@ -1,20 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import Favorite from '../../../../../models/favorite';
|
||||
import Note from '../../../../../models/note';
|
||||
|
||||
/**
|
||||
* Unfavorite a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get favoritee
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { pack } from '../../../../models/note';
|
||||
|
@ -15,11 +15,11 @@ module.exports = async (params, user, app) => {
|
|||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Get 'sinceDate' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import Mute from '../../../../models/mute';
|
||||
import { pack } from '../../../../models/note';
|
||||
|
@ -15,11 +15,11 @@ module.exports = async (params, user, app) => {
|
|||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Get 'sinceDate' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import { pack } from '../../../../models/note';
|
||||
|
@ -24,11 +24,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -7,10 +7,6 @@ import Note, { pack } from '../../../../../models/note';
|
|||
|
||||
/**
|
||||
* Get recommended polls
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import Vote from '../../../../../models/poll-vote';
|
||||
import Note from '../../../../../models/note';
|
||||
import Watching from '../../../../../models/note-watching';
|
||||
|
@ -11,14 +11,10 @@ import notify from '../../../../../publishers/notify';
|
|||
|
||||
/**
|
||||
* Vote poll of a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get votee
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import Reaction, { pack } from '../../../../models/note-reaction';
|
||||
|
||||
|
@ -14,7 +14,7 @@ import Reaction, { pack } from '../../../../models/note-reaction';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import Note from '../../../../../models/note';
|
||||
import create from '../../../../../services/note/reaction/create';
|
||||
import { validateReaction } from '../../../../../models/note-reaction';
|
||||
|
@ -11,7 +11,7 @@ import { validateReaction } from '../../../../../models/note-reaction';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'reaction' parameter
|
||||
|
|
|
@ -1,21 +1,16 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import Reaction from '../../../../../models/note-reaction';
|
||||
import Note from '../../../../../models/note';
|
||||
// import event from '../../../publishers/stream';
|
||||
|
||||
/**
|
||||
* Unreact to a note
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Fetch unreactee
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import Note, { pack } from '../../../../models/note';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import Note, { pack } from '../../../../models/note';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
|
@ -21,11 +21,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
const escapeRegexp = require('escape-regexp');
|
||||
import Note from '../../../../models/note';
|
||||
import User from '../../../../models/user';
|
||||
|
@ -22,19 +22,19 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (textError) return rej('invalid text param');
|
||||
|
||||
// Get 'includeUserIds' parameter
|
||||
const [includeUserIds = [], includeUserIdsErr] = $(params.includeUserIds).optional.array('id').$;
|
||||
const [includeUserIds = [], includeUserIdsErr] = $(params.includeUserIds).optional.array($().type(ID)).$;
|
||||
if (includeUserIdsErr) return rej('invalid includeUserIds param');
|
||||
|
||||
// Get 'excludeUserIds' parameter
|
||||
const [excludeUserIds = [], excludeUserIdsErr] = $(params.excludeUserIds).optional.array('id').$;
|
||||
const [excludeUserIds = [], excludeUserIdsErr] = $(params.excludeUserIds).optional.array($().type(ID)).$;
|
||||
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
|
||||
|
||||
// Get 'includeUserUsernames' parameter
|
||||
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.includeUserUsernames).optional.array('string').$;
|
||||
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.includeUserUsernames).optional.array($().string()).$;
|
||||
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
|
||||
|
||||
// Get 'excludeUserUsernames' parameter
|
||||
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.excludeUserUsernames).optional.array('string').$;
|
||||
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.excludeUserUsernames).optional.array($().string()).$;
|
||||
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
|
||||
|
||||
// Get 'following' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import Note, { pack } from '../../../../models/note';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'noteId' parameter
|
||||
const [noteId, noteIdErr] = $(params.noteId).id().$;
|
||||
const [noteId, noteIdErr] = $(params.noteId).type(ID).$;
|
||||
if (noteIdErr) return rej('invalid noteId param');
|
||||
|
||||
// Get note
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import Mute from '../../../../models/mute';
|
||||
import ChannelWatching from '../../../../models/channel-watching';
|
||||
|
@ -17,11 +17,11 @@ module.exports = async (params, user, app) => {
|
|||
if (limitErr) throw 'invalid limit param';
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) throw 'invalid sinceId param';
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) throw 'invalid untilId param';
|
||||
|
||||
// Get 'sinceDate' parameter
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Module dependencies
|
||||
*/
|
||||
const ms = require('ms');
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,10 +6,6 @@ import Mute from '../../../../models/mute';
|
|||
|
||||
/**
|
||||
* Get count of unread notifications
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const mute = await Mute.find({
|
||||
|
|
|
@ -6,10 +6,6 @@ import event from '../../../../publishers/stream';
|
|||
|
||||
/**
|
||||
* Mark as read all notifications
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} user
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Update documents
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import OthelloGame, { pack } from '../../../../models/othello-game';
|
||||
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
|
@ -11,11 +11,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Check if both of sinceId and untilId is specified
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../../cafy-id';
|
||||
import OthelloGame, { pack } from '../../../../../models/othello-game';
|
||||
import Othello from '../../../../../othello/core';
|
||||
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'gameId' parameter
|
||||
const [gameId, gameIdErr] = $(params.gameId).id().$;
|
||||
const [gameId, gameIdErr] = $(params.gameId).type(ID).$;
|
||||
if (gameIdErr) return rej('invalid gameId param');
|
||||
|
||||
const game = await OthelloGame.findOne({ _id: gameId });
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Matching, { pack as packMatching } from '../../../../models/othello-matching';
|
||||
import OthelloGame, { pack as packGame } from '../../../../models/othello-game';
|
||||
import User from '../../../../models/user';
|
||||
|
@ -7,7 +7,7 @@ import { eighteight } from '../../../../othello/maps';
|
|||
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [childId, childIdErr] = $(params.userId).id().$;
|
||||
const [childId, childIdErr] = $(params.userId).type(ID).$;
|
||||
if (childIdErr) return rej('invalid userId param');
|
||||
|
||||
// Myself
|
||||
|
|
|
@ -6,10 +6,6 @@ import User, { pack } from '../../../models/user';
|
|||
|
||||
/**
|
||||
* Lists all users
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} me
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'limit' parameter
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import { pack } from '../../../../models/user';
|
||||
|
@ -9,14 +9,10 @@ import { getFriendIds } from '../../common/get-friends';
|
|||
|
||||
/**
|
||||
* Get followers of a user
|
||||
*
|
||||
* @param {any} params
|
||||
* @param {any} me
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'iknow' parameter
|
||||
|
@ -28,7 +24,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.id().$;
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).$;
|
||||
if (cursorErr) return rej('invalid cursor param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User from '../../../../models/user';
|
||||
import Following from '../../../../models/following';
|
||||
import { pack } from '../../../../models/user';
|
||||
|
@ -16,7 +16,7 @@ import { getFriendIds } from '../../common/get-friends';
|
|||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'iknow' parameter
|
||||
|
@ -28,7 +28,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'cursor' parameter
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.id().$;
|
||||
const [cursor = null, cursorErr] = $(params.cursor).optional.type(ID).$;
|
||||
if (cursorErr) return rej('invalid cursor param');
|
||||
|
||||
// Lookup user
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import Note from '../../../../models/note';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
const [userId, userIdErr] = $(params.userId).type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
|
|
25
src/server/api/endpoints/users/list/create.ts
Normal file
25
src/server/api/endpoints/users/list/create.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import UserList, { pack } from '../../../../../models/user-list';
|
||||
|
||||
/**
|
||||
* Create a user list
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'title' parameter
|
||||
const [title, titleErr] = $(params.title).string().range(1, 100).$;
|
||||
if (titleErr) return rej('invalid title param');
|
||||
|
||||
// insert
|
||||
const userList = await UserList.insert({
|
||||
createdAt: new Date(),
|
||||
userId: user._id,
|
||||
title: title,
|
||||
userIds: []
|
||||
});
|
||||
|
||||
// Response
|
||||
res(await pack(userList));
|
||||
});
|
0
src/server/api/endpoints/users/list/push.ts
Normal file
0
src/server/api/endpoints/users/list/push.ts
Normal file
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import getHostLower from '../../common/get-host-lower';
|
||||
import Note, { pack } from '../../../../models/note';
|
||||
import User from '../../../../models/user';
|
||||
|
@ -11,7 +11,7 @@ import User from '../../../../models/user';
|
|||
*/
|
||||
module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).optional.id().$;
|
||||
const [userId, userIdErr] = $(params.userId).optional.type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'username' parameter
|
||||
|
@ -43,11 +43,11 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'sinceId' parameter
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||
const [sinceId, sinceIdErr] = $(params.sinceId).optional.type(ID).$;
|
||||
if (sinceIdErr) return rej('invalid sinceId param');
|
||||
|
||||
// Get 'untilId' parameter
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||
const [untilId, untilIdErr] = $(params.untilId).optional.type(ID).$;
|
||||
if (untilIdErr) return rej('invalid untilId param');
|
||||
|
||||
// Get 'sinceDate' parameter
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Module dependencies
|
||||
*/
|
||||
const ms = require('ms');
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import { getFriendIds } from '../../common/get-friends';
|
||||
import Mute from '../../../../models/mute';
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Module dependencies
|
||||
*/
|
||||
import * as mongo from 'mongodb';
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import config from '../../../../config';
|
||||
const escapeRegexp = require('escape-regexp');
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
import $ from 'cafy';
|
||||
import $ from 'cafy'; import ID from '../../../../cafy-id';
|
||||
import User, { pack } from '../../../../models/user';
|
||||
import resolveRemoteUser from '../../../../remote/resolve-user';
|
||||
|
||||
|
@ -14,7 +14,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
let user;
|
||||
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).optional.id().$;
|
||||
const [userId, userIdErr] = $(params.userId).optional.type(ID).$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Get 'username' parameter
|
||||
|
|
Loading…
Reference in a new issue