Use any instead of Object

This commit is contained in:
Aya Morisawa 2017-03-01 17:37:01 +09:00
parent d2c70afd37
commit ac8eb94a27
81 changed files with 398 additions and 397 deletions

View file

@ -10,8 +10,8 @@ import Like from '../../../models/like';
/** /**
* Aggregate like of a post * Aggregate like of a post
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,8 +10,8 @@ import Like from '../../../models/like';
/** /**
* Aggregate likes of a post * Aggregate likes of a post
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -9,8 +9,8 @@ import Post from '../../../models/post';
/** /**
* Aggregate reply of a post * Aggregate reply of a post
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -9,8 +9,8 @@ import Post from '../../../models/post';
/** /**
* Aggregate repost of a post * Aggregate repost of a post
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,8 +10,8 @@ import Following from '../../../models/following';
/** /**
* Aggregate followers of a user * Aggregate followers of a user
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,8 +10,8 @@ import Following from '../../../models/following';
/** /**
* Aggregate following of a user * Aggregate following of a user
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,8 +10,8 @@ import Like from '../../../models/like';
/** /**
* Aggregate like of a user * Aggregate like of a user
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,8 +10,8 @@ import Post from '../../../models/post';
/** /**
* Aggregate post of a user * Aggregate post of a user
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -47,13 +47,13 @@ import serialize from '../../serializers/app';
* in: formData * in: formData
* required: false * required: false
* type: string * type: string
* *
* responses: * responses:
* 200: * 200:
* description: Created application's information * description: Created application's information
* schema: * schema:
* $ref: "#/definitions/Application" * $ref: "#/definitions/Application"
* *
* default: * default:
* description: Failed * description: Failed
* schema: * schema:
@ -63,9 +63,9 @@ import serialize from '../../serializers/app';
/** /**
* Create an app * Create an app
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = async (params, user) => module.exports = async (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -17,7 +17,7 @@ import App from '../../../models/app';
* in: formData * in: formData
* required: true * required: true
* type: string * type: string
* *
* responses: * responses:
* 200: * 200:
* description: Success * description: Success
@ -27,7 +27,7 @@ import App from '../../../models/app';
* available: * available:
* description: Whether name_id is available * description: Whether name_id is available
* type: boolean * type: boolean
* *
* default: * default:
* description: Failed * description: Failed
* schema: * schema:
@ -37,8 +37,8 @@ import App from '../../../models/app';
/** /**
* Check available name_id of app * Check available name_id of app
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = async (params) => module.exports = async (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -24,13 +24,13 @@ import serialize from '../../serializers/app';
* description: Application unique name * description: Application unique name
* in: formData * in: formData
* type: string * type: string
* *
* responses: * responses:
* 200: * 200:
* description: Success * description: Success
* schema: * schema:
* $ref: "#/definitions/Application" * $ref: "#/definitions/Application"
* *
* default: * default:
* description: Failed * description: Failed
* schema: * schema:
@ -40,11 +40,11 @@ import serialize from '../../serializers/app';
/** /**
* Show an app * Show an app
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} _ * @param {any} _
* @param {Object} isSecure * @param {any} isSecure
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, _, isSecure) => module.exports = (params, user, _, isSecure) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -16,7 +16,7 @@ import AccessToken from '../../models/access-token';
* summary: Accept a session * summary: Accept a session
* parameters: * parameters:
* - $ref: "#/parameters/NativeToken" * - $ref: "#/parameters/NativeToken"
* - * -
* name: token * name: token
* description: Session Token * description: Session Token
* in: formData * in: formData
@ -25,7 +25,7 @@ import AccessToken from '../../models/access-token';
* responses: * responses:
* 204: * 204:
* description: OK * description: OK
* *
* default: * default:
* description: Failed * description: Failed
* schema: * schema:
@ -35,9 +35,9 @@ import AccessToken from '../../models/access-token';
/** /**
* Accept * Accept
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -20,7 +20,7 @@ import config from '../../../../conf';
* in: formData * in: formData
* required: true * required: true
* type: string * type: string
* *
* responses: * responses:
* 200: * 200:
* description: OK * description: OK
@ -42,8 +42,8 @@ import config from '../../../../conf';
/** /**
* Generate a session * Generate a session
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -18,11 +18,11 @@ import serialize from '../../../serializers/auth-session';
* in: formData * in: formData
* required: true * required: true
* type: string * type: string
* *
* responses: * responses:
* 200: * 200:
* description: OK * description: OK
* schema: * schema:
* type: object * type: object
* properties: * properties:
* created_at: * created_at:
@ -49,9 +49,9 @@ import serialize from '../../../serializers/auth-session';
/** /**
* Show a session * Show a session
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -47,8 +47,8 @@ import serialize from '../../../serializers/user';
/** /**
* Generate a session * Generate a session
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -8,30 +8,33 @@ import DriveFile from '../models/drive-file';
/** /**
* Get drive information * Get drive information
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) => {
{ // Calculate drive usage
// Calculate drive usage const usage = ((await DriveFile
const usage = ((await DriveFile .aggregate([
.aggregate([ { $match: { user_id: user._id } },
{ $match: { user_id: user._id } }, {
{ $project: { $project: {
datasize: true datasize: true
}}, }
{ $group: { },
_id: null, {
usage: { $sum: '$datasize' } $group: {
}} _id: null,
]))[0] || { usage: { $sum: '$datasize' }
usage: 0 }
}).usage; }
]))[0] || {
usage: 0
}).usage;
res({ res({
capacity: user.drive_capacity, capacity: user.drive_capacity,
usage: usage usage: usage
});
}); });
});

View file

@ -10,10 +10,10 @@ import serialize from '../../serializers/drive-file';
/** /**
* Get drive files * Get drive files
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -14,10 +14,10 @@ import create from '../../../common/add-file-to-drive';
/** /**
* Create a file * Create a file
* *
* @param {Object} file * @param {any} file
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (file, params, user) => module.exports = (file, params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../../serializers/drive-file';
/** /**
* Find a file(s) * Find a file(s)
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../../serializers/drive-file';
/** /**
* Show a file * Show a file
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -13,9 +13,9 @@ import event from '../../../event';
/** /**
* Update a file * Update a file
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -15,9 +15,9 @@ import create from '../../../common/add-file-to-drive';
/** /**
* Create a file from a URL * Create a file from a URL
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,10 +10,10 @@ import serialize from '../../serializers/drive-folder';
/** /**
* Get drive folders * Get drive folders
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ import event from '../../../event';
/** /**
* Create drive folder * Create drive folder
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../../serializers/drive-folder';
/** /**
* Find a folder(s) * Find a folder(s)
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../../serializers/drive-folder';
/** /**
* Show a folder * Show a folder
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ import event from '../../../event';
/** /**
* Update a folder * Update a folder
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/drive-file';
/** /**
* Get drive stream * Get drive stream
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -13,9 +13,9 @@ import serializeUser from '../../serializers/user';
/** /**
* Follow a user * Follow a user
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ import serializeUser from '../../serializers/user';
/** /**
* Unfollow a user * Unfollow a user
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -8,11 +8,11 @@ import serialize from '../serializers/user';
/** /**
* Show myself * Show myself
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @param {Boolean} isSecure * @param {Boolean} isSecure
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, _, isSecure) => module.exports = (params, user, _, isSecure) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -8,11 +8,11 @@ import Appdata from '../../../models/appdata';
/** /**
* Get app data * Get app data
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @param {Boolean} isSecure * @param {Boolean} isSecure
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app, isSecure) => module.exports = (params, user, app, isSecure) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -11,11 +11,11 @@ import event from '../../../event';
/** /**
* Set app data * Set app data
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @param {Boolean} isSecure * @param {Boolean} isSecure
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app, isSecure) => module.exports = (params, user, app, isSecure) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/app';
/** /**
* Get authorized apps of my account * Get authorized apps of my account
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,8 +10,8 @@ import serialize from '../../serializers/post';
/** /**
* Get followers of a user * Get followers of a user
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -11,9 +11,9 @@ import getFriends from '../../common/get-friends';
/** /**
* Get notifications * Get notifications
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/signin';
/** /**
* Get signin history of my account * Get signin history of my account
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -13,11 +13,11 @@ import config from '../../../conf';
/** /**
* Update myself * Update myself
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} _ * @param {any} _
* @param {boolean} isSecure * @param {boolean} isSecure
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = async (params, user, _, isSecure) => module.exports = async (params, user, _, isSecure) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/messaging-message';
/** /**
* Show messaging history * Show messaging history
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -13,9 +13,9 @@ import { publishMessagingStream } from '../../event';
/** /**
* Get messages * Get messages
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -21,9 +21,9 @@ const maxTextLength = 500;
/** /**
* Create a message * Create a message
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -8,9 +8,9 @@ import Message from '../../models/messaging-message';
/** /**
* Get count of unread messages * Get count of unread messages
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -36,8 +36,8 @@ import git from 'git-last-commit';
/** /**
* Show core info * Show core info
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/app';
/** /**
* Get my apps * Get my apps
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -11,9 +11,9 @@ import event from '../../../event';
/** /**
* Mark as read a notification * Mark as read a notification
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -9,80 +9,79 @@ import serialize from '../serializers/post';
/** /**
* Lists all posts * Lists all posts
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params) => module.exports = (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) => {
{ // Get 'include_replies' parameter
// Get 'include_replies' parameter let includeReplies = params.include_replies;
let includeReplies = params.include_replies; if (includeReplies === true) {
if (includeReplies === true) { includeReplies = true;
includeReplies = true; } else {
} else { includeReplies = false;
includeReplies = false;
}
// Get 'include_reposts' parameter
let includeReposts = params.include_reposts;
if (includeReposts === true) {
includeReposts = true;
} else {
includeReposts = false;
}
// Get 'limit' parameter
let limit = params.limit;
if (limit !== undefined && limit !== null) {
limit = parseInt(limit, 10);
// From 1 to 100
if (!(1 <= limit && limit <= 100)) {
return rej('invalid limit range');
} }
} else {
limit = 10;
}
const since = params.since_id || null; // Get 'include_reposts' parameter
const max = params.max_id || null; let includeReposts = params.include_reposts;
if (includeReposts === true) {
includeReposts = true;
} else {
includeReposts = false;
}
// Check if both of since_id and max_id is specified // Get 'limit' parameter
if (since !== null && max !== null) { let limit = params.limit;
return rej('cannot set since_id and max_id'); if (limit !== undefined && limit !== null) {
} limit = parseInt(limit, 10);
// Construct query // From 1 to 100
const sort = { if (!(1 <= limit && limit <= 100)) {
_id: -1 return rej('invalid limit range');
}; }
const query = {}; } else {
if (since !== null) { limit = 10;
sort._id = 1; }
query._id = {
$gt: new mongo.ObjectID(since) const since = params.since_id || null;
const max = params.max_id || null;
// Check if both of since_id and max_id is specified
if (since !== null && max !== null) {
return rej('cannot set since_id and max_id');
}
// Construct query
const sort = {
_id: -1
}; };
} else if (max !== null) { const query = {};
query._id = { if (since !== null) {
$lt: new mongo.ObjectID(max) sort._id = 1;
}; query._id = {
} $gt: new mongo.ObjectID(since)
};
} else if (max !== null) {
query._id = {
$lt: new mongo.ObjectID(max)
};
}
if (!includeReplies) { if (!includeReplies) {
query.reply_to_id = null; query.reply_to_id = null;
} }
if (!includeReposts) { if (!includeReposts) {
query.repost_id = null; query.repost_id = null;
} }
// Issue query // Issue query
const posts = await Post const posts = await Post
.find(query, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}); });
// Serialize // Serialize
res(await Promise.all(posts.map(async post => await serialize(post)))); res(await Promise.all(posts.map(async post => await serialize(post))));
}); });

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/post';
/** /**
* Show a context of a post * Show a context of a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -28,10 +28,10 @@ const maxMediaCount = 4;
/** /**
* Create a post * Create a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import Post from '../../models/post';
/** /**
* Favorite a post * Favorite a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -10,9 +10,9 @@ import Post from '../../models/post';
/** /**
* Unfavorite a post * Unfavorite a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -11,9 +11,9 @@ import serialize from '../../serializers/user';
/** /**
* Show a likes of a post * Show a likes of a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ import notify from '../../../common/notify';
/** /**
* Like a post * Like a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -12,9 +12,9 @@ import User from '../../../models/user';
/** /**
* Unlike a post * Unlike a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -11,9 +11,9 @@ import serialize from '../../serializers/post';
/** /**
* Get mentions of myself * Get mentions of myself
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -11,9 +11,9 @@ import notify from '../../../common/notify';
/** /**
* Vote poll of a post * Vote poll of a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => { new Promise(async (res, rej) => {

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/post';
/** /**
* Show a replies of a post * Show a replies of a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/post';
/** /**
* Show a reposts of a post * Show a reposts of a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ import config from '../../../conf';
/** /**
* Search a post * Search a post
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/post';
/** /**
* Show a post * Show a post
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user) => module.exports = (params, user) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -11,10 +11,10 @@ import serialize from '../../serializers/post';
/** /**
* Get timeline of myself * Get timeline of myself
* *
* @param {Object} params * @param {any} params
* @param {Object} user * @param {any} user
* @param {Object} app * @param {any} app
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, user, app) => module.exports = (params, user, app) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -9,8 +9,8 @@ import { validateUsername } from '../../models/user';
/** /**
* Check available username * Check available username
* *
* @param {Object} params * @param {any} params
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = async (params) => module.exports = async (params) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -9,58 +9,57 @@ import serialize from '../serializers/user';
/** /**
* Lists all users * Lists all users
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) => {
{ // Get 'limit' parameter
// Get 'limit' parameter let limit = params.limit;
let limit = params.limit; if (limit !== undefined && limit !== null) {
if (limit !== undefined && limit !== null) { limit = parseInt(limit, 10);
limit = parseInt(limit, 10);
// From 1 to 100 // From 1 to 100
if (!(1 <= limit && limit <= 100)) { if (!(1 <= limit && limit <= 100)) {
return rej('invalid limit range'); return rej('invalid limit range');
}
} else {
limit = 10;
} }
} else {
limit = 10;
}
const since = params.since_id || null; const since = params.since_id || null;
const max = params.max_id || null; const max = params.max_id || null;
// Check if both of since_id and max_id is specified // Check if both of since_id and max_id is specified
if (since !== null && max !== null) { if (since !== null && max !== null) {
return rej('cannot set since_id and max_id'); return rej('cannot set since_id and max_id');
} }
// Construct query // Construct query
const sort = { const sort = {
_id: -1 _id: -1
};
const query = {};
if (since !== null) {
sort._id = 1;
query._id = {
$gt: new mongo.ObjectID(since)
}; };
} else if (max !== null) { const query = {};
query._id = { if (since !== null) {
$lt: new mongo.ObjectID(max) sort._id = 1;
}; query._id = {
} $gt: new mongo.ObjectID(since)
};
} else if (max !== null) {
query._id = {
$lt: new mongo.ObjectID(max)
};
}
// Issue query // Issue query
const users = await User const users = await User
.find(query, { .find(query, {
limit: limit, limit: limit,
sort: sort sort: sort
}); });
// Serialize // Serialize
res(await Promise.all(users.map(async user => res(await Promise.all(users.map(async user =>
await serialize(user, me)))); await serialize(user, me))));
}); });

View file

@ -12,9 +12,9 @@ import getFriends from '../../common/get-friends';
/** /**
* Get followers of a user * Get followers of a user
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ import getFriends from '../../common/get-friends';
/** /**
* Get following users of a user * Get following users of a user
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -11,9 +11,9 @@ import serialize from '../../serializers/post';
/** /**
* Get posts of a user * Get posts of a user
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import getFriends from '../../common/get-friends';
/** /**
* Get recommended users * Get recommended users
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -12,9 +12,9 @@ const escapeRegexp = require('escape-regexp');
/** /**
* Search a user * Search a user
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/user';
/** /**
* Search a user by username * Search a user by username
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -10,9 +10,9 @@ import serialize from '../../serializers/user';
/** /**
* Show a user * Show a user
* *
* @param {Object} params * @param {any} params
* @param {Object} me * @param {any} me
* @return {Promise<object>} * @return {Promise<any>}
*/ */
module.exports = (params, me) => module.exports = (params, me) =>
new Promise(async (res, rej) => new Promise(async (res, rej) =>

View file

@ -13,7 +13,7 @@ class MisskeyEvent {
config.redis.port, config.redis.host); config.redis.port, config.redis.host);
} }
private publish(channel: string, type: string, value?: Object): void { private publish(channel: string, type: string, value?: any): void {
const message = value == null ? const message = value == null ?
{ type: type } : { type: type } :
{ type: type, body: value }; { type: type, body: value };
@ -21,11 +21,11 @@ class MisskeyEvent {
this.redisClient.publish(`misskey:${channel}`, JSON.stringify(message)); this.redisClient.publish(`misskey:${channel}`, JSON.stringify(message));
} }
public publishUserStream(userId: ID, type: string, value?: Object): void { public publishUserStream(userId: ID, type: string, value?: any): void {
this.publish(`user-stream:${userId}`, type, typeof value === 'undefined' ? null : value); this.publish(`user-stream:${userId}`, type, typeof value === 'undefined' ? null : value);
} }
public publishMessagingStream(userId: ID, otherpartyId: ID, type: string, value?: Object): void { public publishMessagingStream(userId: ID, otherpartyId: ID, type: string, value?: any): void {
this.publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value); this.publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value);
} }
} }

View file

@ -12,10 +12,10 @@ import config from '../../conf';
/** /**
* Serialize an app * Serialize an app
* *
* @param {Object} app * @param {any} app
* @param {Object} me? * @param {any} me?
* @param {Object} options? * @param {any} options?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default ( export default (
app: any, app: any,
@ -75,8 +75,8 @@ export default (
app_id: _app.id, app_id: _app.id,
user_id: me, user_id: me,
}, { }, {
limit: 1 limit: 1
}); });
_app.is_authorized = exist === 1; _app.is_authorized = exist === 1;
} }

View file

@ -10,9 +10,9 @@ import serializeApp from './app';
/** /**
* Serialize an auth session * Serialize an auth session
* *
* @param {Object} session * @param {any} session
* @param {Object} me? * @param {any} me?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default ( export default (
session: any, session: any,

View file

@ -13,16 +13,16 @@ import config from '../../conf';
/** /**
* Serialize a drive file * Serialize a drive file
* *
* @param {Object} file * @param {any} file
* @param {Object} options? * @param {any} options?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default ( export default (
file: any, file: any,
options?: { options?: {
detail: boolean detail: boolean
} }
) => new Promise<Object>(async (resolve, reject) => { ) => new Promise<any>(async (resolve, reject) => {
const opts = Object.assign({ const opts = Object.assign({
detail: false detail: false
}, options); }, options);
@ -34,18 +34,18 @@ export default (
_file = await DriveFile.findOne({ _file = await DriveFile.findOne({
_id: file _id: file
}, { }, {
fields: { fields: {
data: false data: false
} }
}); });
} else if (typeof file === 'string') { } else if (typeof file === 'string') {
_file = await DriveFile.findOne({ _file = await DriveFile.findOne({
_id: new mongo.ObjectID(file) _id: new mongo.ObjectID(file)
}, { }, {
fields: { fields: {
data: false data: false
} }
}); });
} else { } else {
_file = deepcopy(file); _file = deepcopy(file);
} }

View file

@ -10,16 +10,16 @@ import deepcopy = require('deepcopy');
/** /**
* Serialize a drive folder * Serialize a drive folder
* *
* @param {Object} folder * @param {any} folder
* @param {Object} options? * @param {any} options?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
const self = ( const self = (
folder: any, folder: any,
options?: { options?: {
detail: boolean detail: boolean
} }
) => new Promise<Object>(async (resolve, reject) => { ) => new Promise<any>(async (resolve, reject) => {
const opts = Object.assign({ const opts = Object.assign({
detail: false detail: false
}, options); }, options);
@ -28,9 +28,9 @@ const self = (
// Populate the folder if 'folder' is ID // Populate the folder if 'folder' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(folder)) { if (mongo.ObjectID.prototype.isPrototypeOf(folder)) {
_folder = await DriveFolder.findOne({_id: folder}); _folder = await DriveFolder.findOne({ _id: folder });
} else if (typeof folder === 'string') { } else if (typeof folder === 'string') {
_folder = await DriveFolder.findOne({_id: new mongo.ObjectID(folder)}); _folder = await DriveFolder.findOne({ _id: new mongo.ObjectID(folder) });
} else { } else {
_folder = deepcopy(folder); _folder = deepcopy(folder);
} }

View file

@ -10,19 +10,19 @@ import deepcopy = require('deepcopy');
/** /**
* Serialize a drive tag * Serialize a drive tag
* *
* @param {Object} tag * @param {any} tag
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
const self = ( const self = (
tag: any tag: any
) => new Promise<Object>(async (resolve, reject) => { ) => new Promise<any>(async (resolve, reject) => {
let _tag: any; let _tag: any;
// Populate the tag if 'tag' is ID // Populate the tag if 'tag' is ID
if (mongo.ObjectID.prototype.isPrototypeOf(tag)) { if (mongo.ObjectID.prototype.isPrototypeOf(tag)) {
_tag = await DriveTag.findOne({_id: tag}); _tag = await DriveTag.findOne({ _id: tag });
} else if (typeof tag === 'string') { } else if (typeof tag === 'string') {
_tag = await DriveTag.findOne({_id: new mongo.ObjectID(tag)}); _tag = await DriveTag.findOne({ _id: new mongo.ObjectID(tag) });
} else { } else {
_tag = deepcopy(tag); _tag = deepcopy(tag);
} }

View file

@ -12,10 +12,10 @@ import deepcopy = require('deepcopy');
/** /**
* Serialize a message * Serialize a message
* *
* @param {Object} message * @param {any} message
* @param {Object} me? * @param {any} me?
* @param {Object} options? * @param {any} options?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default ( export default (
message: any, message: any,
@ -23,7 +23,7 @@ export default (
options?: { options?: {
populateRecipient: boolean populateRecipient: boolean
} }
) => new Promise<Object>(async (resolve, reject) => { ) => new Promise<any>(async (resolve, reject) => {
const opts = options || { const opts = options || {
populateRecipient: true populateRecipient: true
}; };

View file

@ -12,10 +12,10 @@ import deepcopy = require('deepcopy');
/** /**
* Serialize a notification * Serialize a notification
* *
* @param {Object} notification * @param {any} notification
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default (notification: any) => new Promise<Object>(async (resolve, reject) => { export default (notification: any) => new Promise<any>(async (resolve, reject) => {
let _notification: any; let _notification: any;
// Populate the notification if 'notification' is ID // Populate the notification if 'notification' is ID

View file

@ -15,10 +15,10 @@ import deepcopy = require('deepcopy');
/** /**
* Serialize a post * Serialize a post
* *
* @param {Object} post * @param {any} post
* @param {Object} me? * @param {any} me?
* @param {Object} options? * @param {any} options?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
const self = ( const self = (
post: any, post: any,
@ -26,7 +26,7 @@ const self = (
options?: { options?: {
detail: boolean detail: boolean
} }
) => new Promise<Object>(async (resolve, reject) => { ) => new Promise<any>(async (resolve, reject) => {
const opts = options || { const opts = options || {
detail: true, detail: true,
}; };

View file

@ -8,12 +8,12 @@ import deepcopy = require('deepcopy');
/** /**
* Serialize a signin record * Serialize a signin record
* *
* @param {Object} record * @param {any} record
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default ( export default (
record: any record: any
) => new Promise<Object>(async (resolve, reject) => { ) => new Promise<any>(async (resolve, reject) => {
const _record = deepcopy(record); const _record = deepcopy(record);

View file

@ -13,10 +13,10 @@ import config from '../../conf';
/** /**
* Serialize a user * Serialize a user
* *
* @param {Object} user * @param {any} user
* @param {Object} me? * @param {any} me?
* @param {Object} options? * @param {any} options?
* @return {Promise<Object>} * @return {Promise<any>}
*/ */
export default ( export default (
user: any, user: any,

View file

@ -11,8 +11,8 @@ let pending = 0;
* Send a request to API * Send a request to API
* @param {string|Object} i Credential * @param {string|Object} i Credential
* @param {string} endpoint Endpoint * @param {string} endpoint Endpoint
* @param {Object} [data={}] Data * @param {any} [data={}] Data
* @return {Promise<Object>} Response * @return {Promise<any>} Response
*/ */
module.exports = (i, endpoint, data = {}) => { module.exports = (i, endpoint, data = {}) => {
if (++pending === 1) { if (++pending === 1) {