mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-22 11:25:13 +00:00
wip
This commit is contained in:
parent
7d4d9dbaa6
commit
3d5cdb8d2d
237 changed files with 1661 additions and 1354 deletions
|
@ -55,10 +55,10 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv
|
|||
}
|
||||
|
||||
const app = await App
|
||||
.findOne({ _id: accessToken.app_id });
|
||||
.findOne({ _id: accessToken.appId });
|
||||
|
||||
const user = await User
|
||||
.findOne({ _id: accessToken.user_id });
|
||||
.findOne({ _id: accessToken.userId });
|
||||
|
||||
return resolve({
|
||||
app: app,
|
||||
|
|
|
@ -208,7 +208,7 @@ class SigninContext extends Context {
|
|||
if (this.temporaryUser == null) {
|
||||
// Fetch user
|
||||
const user: IUser = await User.findOne({
|
||||
username_lower: query.toLowerCase(),
|
||||
usernameLower: query.toLowerCase(),
|
||||
host: null
|
||||
}, {
|
||||
fields: {
|
||||
|
|
|
@ -115,7 +115,7 @@ class LineBot extends BotCore {
|
|||
actions.push({
|
||||
type: 'uri',
|
||||
label: 'Twitterアカウントを見る',
|
||||
uri: `https://twitter.com/${user.account.twitter.screen_name}`
|
||||
uri: `https://twitter.com/${user.account.twitter.screenName}`
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,7 @@ class LineBot extends BotCore {
|
|||
|
||||
public async showUserTimelinePostback(userId: string) {
|
||||
const tl = await require('../../endpoints/users/posts')({
|
||||
user_id: userId,
|
||||
userId: userId,
|
||||
limit: 5
|
||||
}, this.user);
|
||||
|
||||
|
@ -174,7 +174,7 @@ module.exports = async (app: express.Application) => {
|
|||
const user = await User.findOne({
|
||||
host: null,
|
||||
'account.line': {
|
||||
user_id: sourceId
|
||||
userId: sourceId
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -184,7 +184,7 @@ module.exports = async (app: express.Application) => {
|
|||
User.update(user._id, {
|
||||
$set: {
|
||||
'account.line': {
|
||||
user_id: sourceId
|
||||
userId: sourceId
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -194,7 +194,7 @@ module.exports = async (app: express.Application) => {
|
|||
User.update(user._id, {
|
||||
$set: {
|
||||
'account.line': {
|
||||
user_id: null
|
||||
userId: null
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
306
src/api/common/add-file-to-drive.ts
Normal file
306
src/api/common/add-file-to-drive.ts
Normal file
|
@ -0,0 +1,306 @@
|
|||
import { Buffer } from 'buffer';
|
||||
import * as fs from 'fs';
|
||||
import * as tmp from 'tmp';
|
||||
import * as stream from 'stream';
|
||||
|
||||
import * as mongodb from 'mongodb';
|
||||
import * as crypto from 'crypto';
|
||||
import * as _gm from 'gm';
|
||||
import * as debug from 'debug';
|
||||
import fileType = require('file-type');
|
||||
import prominence = require('prominence');
|
||||
|
||||
import DriveFile, { getGridFSBucket } from '../models/drive-file';
|
||||
import DriveFolder from '../models/drive-folder';
|
||||
import { pack } from '../models/drive-file';
|
||||
import event, { publishDriveStream } from '../event';
|
||||
import config from '../../conf';
|
||||
|
||||
const gm = _gm.subClass({
|
||||
imageMagick: true
|
||||
});
|
||||
|
||||
const log = debug('misskey:register-drive-file');
|
||||
|
||||
const tmpFile = (): Promise<string> => new Promise((resolve, reject) => {
|
||||
tmp.file((e, path) => {
|
||||
if (e) return reject(e);
|
||||
resolve(path);
|
||||
});
|
||||
});
|
||||
|
||||
const addToGridFS = (name: string, readable: stream.Readable, type: string, metadata: any): Promise<any> =>
|
||||
getGridFSBucket()
|
||||
.then(bucket => new Promise((resolve, reject) => {
|
||||
const writeStream = bucket.openUploadStream(name, { contentType: type, metadata });
|
||||
writeStream.once('finish', (doc) => { resolve(doc); });
|
||||
writeStream.on('error', reject);
|
||||
readable.pipe(writeStream);
|
||||
}));
|
||||
|
||||
const addFile = async (
|
||||
user: any,
|
||||
path: string,
|
||||
name: string = null,
|
||||
comment: string = null,
|
||||
folderId: mongodb.ObjectID = null,
|
||||
force: boolean = false
|
||||
) => {
|
||||
log(`registering ${name} (user: ${user.username}, path: ${path})`);
|
||||
|
||||
// Calculate hash, get content type and get file size
|
||||
const [hash, [mime, ext], size] = await Promise.all([
|
||||
// hash
|
||||
((): Promise<string> => new Promise((res, rej) => {
|
||||
const readable = fs.createReadStream(path);
|
||||
const hash = crypto.createHash('md5');
|
||||
const chunks = [];
|
||||
readable
|
||||
.on('error', rej)
|
||||
.pipe(hash)
|
||||
.on('error', rej)
|
||||
.on('data', (chunk) => chunks.push(chunk))
|
||||
.on('end', () => {
|
||||
const buffer = Buffer.concat(chunks);
|
||||
res(buffer.toString('hex'));
|
||||
});
|
||||
}))(),
|
||||
// mime
|
||||
((): Promise<[string, string | null]> => new Promise((res, rej) => {
|
||||
const readable = fs.createReadStream(path);
|
||||
readable
|
||||
.on('error', rej)
|
||||
.once('data', (buffer: Buffer) => {
|
||||
readable.destroy();
|
||||
const type = fileType(buffer);
|
||||
if (type) {
|
||||
return res([type.mime, type.ext]);
|
||||
} else {
|
||||
// 種類が同定できなかったら application/octet-stream にする
|
||||
return res(['application/octet-stream', null]);
|
||||
}
|
||||
});
|
||||
}))(),
|
||||
// size
|
||||
((): Promise<number> => new Promise((res, rej) => {
|
||||
fs.stat(path, (err, stats) => {
|
||||
if (err) return rej(err);
|
||||
res(stats.size);
|
||||
});
|
||||
}))()
|
||||
]);
|
||||
|
||||
log(`hash: ${hash}, mime: ${mime}, ext: ${ext}, size: ${size}`);
|
||||
|
||||
// detect name
|
||||
const detectedName: string = name || (ext ? `untitled.${ext}` : 'untitled');
|
||||
|
||||
if (!force) {
|
||||
// Check if there is a file with the same hash
|
||||
const much = await DriveFile.findOne({
|
||||
md5: hash,
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (much !== null) {
|
||||
log('file with same hash is found');
|
||||
return much;
|
||||
} else {
|
||||
log('file with same hash is not found');
|
||||
}
|
||||
}
|
||||
|
||||
const [wh, avgColor, folder] = await Promise.all([
|
||||
// Width and height (when image)
|
||||
(async () => {
|
||||
// 画像かどうか
|
||||
if (!/^image\/.*$/.test(mime)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const imageType = mime.split('/')[1];
|
||||
|
||||
// 画像でもPNGかJPEGかGIFでないならスキップ
|
||||
if (imageType != 'png' && imageType != 'jpeg' && imageType != 'gif') {
|
||||
return null;
|
||||
}
|
||||
|
||||
log('calculate image width and height...');
|
||||
|
||||
// Calculate width and height
|
||||
const g = gm(fs.createReadStream(path), name);
|
||||
const size = await prominence(g).size();
|
||||
|
||||
log(`image width and height is calculated: ${size.width}, ${size.height}`);
|
||||
|
||||
return [size.width, size.height];
|
||||
})(),
|
||||
// average color (when image)
|
||||
(async () => {
|
||||
// 画像かどうか
|
||||
if (!/^image\/.*$/.test(mime)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const imageType = mime.split('/')[1];
|
||||
|
||||
// 画像でもPNGかJPEGでないならスキップ
|
||||
if (imageType != 'png' && imageType != 'jpeg') {
|
||||
return null;
|
||||
}
|
||||
|
||||
log('calculate average color...');
|
||||
|
||||
const buffer = await prominence(gm(fs.createReadStream(path), name)
|
||||
.setFormat('ppm')
|
||||
.resize(1, 1)) // 1pxのサイズに縮小して平均色を取得するというハック
|
||||
.toBuffer();
|
||||
|
||||
const r = buffer.readUInt8(buffer.length - 3);
|
||||
const g = buffer.readUInt8(buffer.length - 2);
|
||||
const b = buffer.readUInt8(buffer.length - 1);
|
||||
|
||||
log(`average color is calculated: ${r}, ${g}, ${b}`);
|
||||
|
||||
return [r, g, b];
|
||||
})(),
|
||||
// folder
|
||||
(async () => {
|
||||
if (!folderId) {
|
||||
return null;
|
||||
}
|
||||
const driveFolder = await DriveFolder.findOne({
|
||||
_id: folderId,
|
||||
userId: user._id
|
||||
});
|
||||
if (!driveFolder) {
|
||||
throw 'folder-not-found';
|
||||
}
|
||||
return driveFolder;
|
||||
})(),
|
||||
// usage checker
|
||||
(async () => {
|
||||
// Calculate drive usage
|
||||
const usage = await DriveFile
|
||||
.aggregate([{
|
||||
$match: { 'metadata.userId': user._id }
|
||||
}, {
|
||||
$project: {
|
||||
length: true
|
||||
}
|
||||
}, {
|
||||
$group: {
|
||||
_id: null,
|
||||
usage: { $sum: '$length' }
|
||||
}
|
||||
}])
|
||||
.then((aggregates: any[]) => {
|
||||
if (aggregates.length > 0) {
|
||||
return aggregates[0].usage;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
|
||||
log(`drive usage is ${usage}`);
|
||||
|
||||
// If usage limit exceeded
|
||||
if (usage + size > user.driveCapacity) {
|
||||
throw 'no-free-space';
|
||||
}
|
||||
})()
|
||||
]);
|
||||
|
||||
const readable = fs.createReadStream(path);
|
||||
|
||||
const properties = {};
|
||||
|
||||
if (wh) {
|
||||
properties['width'] = wh[0];
|
||||
properties['height'] = wh[1];
|
||||
}
|
||||
|
||||
if (avgColor) {
|
||||
properties['avgColor'] = avgColor;
|
||||
}
|
||||
|
||||
return addToGridFS(detectedName, readable, mime, {
|
||||
userId: user._id,
|
||||
folderId: folder !== null ? folder._id : null,
|
||||
comment: comment,
|
||||
properties: properties
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Add file to drive
|
||||
*
|
||||
* @param user User who wish to add file
|
||||
* @param file File path or readableStream
|
||||
* @param comment Comment
|
||||
* @param type File type
|
||||
* @param folderId Folder ID
|
||||
* @param force If set to true, forcibly upload the file even if there is a file with the same hash.
|
||||
* @return Object that represents added file
|
||||
*/
|
||||
export default (user: any, file: string | stream.Readable, ...args) => new Promise<any>((resolve, reject) => {
|
||||
// Get file path
|
||||
new Promise((res: (v: [string, boolean]) => void, rej) => {
|
||||
if (typeof file === 'string') {
|
||||
res([file, false]);
|
||||
return;
|
||||
}
|
||||
if (typeof file === 'object' && typeof file.read === 'function') {
|
||||
tmpFile()
|
||||
.then(path => {
|
||||
const readable: stream.Readable = file;
|
||||
const writable = fs.createWriteStream(path);
|
||||
readable
|
||||
.on('error', rej)
|
||||
.on('end', () => {
|
||||
res([path, true]);
|
||||
})
|
||||
.pipe(writable)
|
||||
.on('error', rej);
|
||||
})
|
||||
.catch(rej);
|
||||
}
|
||||
rej(new Error('un-compatible file.'));
|
||||
})
|
||||
.then(([path, shouldCleanup]): Promise<any> => new Promise((res, rej) => {
|
||||
addFile(user, path, ...args)
|
||||
.then(file => {
|
||||
res(file);
|
||||
if (shouldCleanup) {
|
||||
fs.unlink(path, (e) => {
|
||||
if (e) log(e.stack);
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(rej);
|
||||
}))
|
||||
.then(file => {
|
||||
log(`drive file has been created ${file._id}`);
|
||||
resolve(file);
|
||||
|
||||
pack(file).then(serializedFile => {
|
||||
// Publish drive_file_created event
|
||||
event(user._id, 'drive_file_created', serializedFile);
|
||||
publishDriveStream(user._id, 'file_created', serializedFile);
|
||||
|
||||
// Register to search database
|
||||
if (config.elasticsearch.enable) {
|
||||
const es = require('../../db/elasticsearch');
|
||||
es.index({
|
||||
index: 'misskey',
|
||||
type: 'drive_file',
|
||||
id: file._id.toString(),
|
||||
body: {
|
||||
name: file.name,
|
||||
userId: user._id.toString()
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
|
@ -100,7 +100,7 @@ const addFile = async (
|
|||
// Check if there is a file with the same hash
|
||||
const much = await DriveFile.findOne({
|
||||
md5: hash,
|
||||
'metadata.user_id': user._id
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (much !== null) {
|
||||
|
@ -172,7 +172,7 @@ const addFile = async (
|
|||
}
|
||||
const driveFolder = await DriveFolder.findOne({
|
||||
_id: folderId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
if (!driveFolder) {
|
||||
throw 'folder-not-found';
|
||||
|
@ -184,7 +184,7 @@ const addFile = async (
|
|||
// Calculate drive usage
|
||||
const usage = await DriveFile
|
||||
.aggregate([{
|
||||
$match: { 'metadata.user_id': user._id }
|
||||
$match: { 'metadata.userId': user._id }
|
||||
}, {
|
||||
$project: {
|
||||
length: true
|
||||
|
@ -205,7 +205,7 @@ const addFile = async (
|
|||
log(`drive usage is ${usage}`);
|
||||
|
||||
// If usage limit exceeded
|
||||
if (usage + size > user.drive_capacity) {
|
||||
if (usage + size > user.driveCapacity) {
|
||||
throw 'no-free-space';
|
||||
}
|
||||
})()
|
||||
|
@ -221,12 +221,12 @@ const addFile = async (
|
|||
}
|
||||
|
||||
if (averageColor) {
|
||||
properties['average_color'] = averageColor;
|
||||
properties['avgColor'] = averageColor;
|
||||
}
|
||||
|
||||
return addToGridFS(detectedName, readable, mime, {
|
||||
user_id: user._id,
|
||||
folder_id: folder !== null ? folder._id : null,
|
||||
userId: user._id,
|
||||
folderId: folder !== null ? folder._id : null,
|
||||
comment: comment,
|
||||
properties: properties
|
||||
});
|
||||
|
@ -297,7 +297,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
|
|||
id: file._id.toString(),
|
||||
body: {
|
||||
name: file.name,
|
||||
user_id: user._id.toString()
|
||||
userId: user._id.toString()
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@ export default async (me: mongodb.ObjectID, includeMe: boolean = true) => {
|
|||
// SELECT followee
|
||||
const myfollowing = await Following
|
||||
.find({
|
||||
follower_id: me,
|
||||
followerId: me,
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
fields: {
|
||||
followee_id: true
|
||||
followeeId: true
|
||||
}
|
||||
});
|
||||
|
||||
// ID list of other users who the I follows
|
||||
const myfollowingIds = myfollowing.map(follow => follow.followee_id);
|
||||
const myfollowingIds = myfollowing.map(follow => follow.followeeId);
|
||||
|
||||
if (includeMe) {
|
||||
myfollowingIds.push(me);
|
||||
|
|
|
@ -16,11 +16,11 @@ export default (
|
|||
|
||||
// Create notification
|
||||
const notification = await Notification.insert(Object.assign({
|
||||
created_at: new Date(),
|
||||
notifiee_id: notifiee,
|
||||
notifier_id: notifier,
|
||||
createdAt: new Date(),
|
||||
notifieeId: notifiee,
|
||||
notifierId: notifier,
|
||||
type: type,
|
||||
is_read: false
|
||||
isRead: false
|
||||
}, content));
|
||||
|
||||
resolve(notification);
|
||||
|
@ -31,14 +31,14 @@ export default (
|
|||
|
||||
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
|
||||
setTimeout(async () => {
|
||||
const fresh = await Notification.findOne({ _id: notification._id }, { is_read: true });
|
||||
if (!fresh.is_read) {
|
||||
const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true });
|
||||
if (!fresh.isRead) {
|
||||
//#region ただしミュートしているユーザーからの通知なら無視
|
||||
const mute = await Mute.find({
|
||||
muter_id: notifiee,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: notifiee,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mutedUserIds = mute.map(m => m.mutee_id.toString());
|
||||
const mutedUserIds = mute.map(m => m.muteeId.toString());
|
||||
if (mutedUserIds.indexOf(notifier.toString()) != -1) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
|
|||
|
||||
// Fetch
|
||||
const subscriptions = await Subscription.find({
|
||||
user_id: userId
|
||||
userId: userId
|
||||
});
|
||||
|
||||
subscriptions.forEach(subscription => {
|
||||
|
@ -41,7 +41,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
|
|||
|
||||
if (err.statusCode == 410) {
|
||||
Subscription.remove({
|
||||
user_id: userId,
|
||||
userId: userId,
|
||||
endpoint: subscription.endpoint,
|
||||
auth: subscription.auth,
|
||||
publickey: subscription.publickey
|
||||
|
|
|
@ -37,12 +37,12 @@ export default (
|
|||
// Update documents
|
||||
await Message.update({
|
||||
_id: { $in: ids },
|
||||
user_id: otherpartyId,
|
||||
recipient_id: userId,
|
||||
is_read: false
|
||||
userId: otherpartyId,
|
||||
recipientId: userId,
|
||||
isRead: false
|
||||
}, {
|
||||
$set: {
|
||||
is_read: true
|
||||
isRead: true
|
||||
}
|
||||
}, {
|
||||
multi: true
|
||||
|
@ -55,8 +55,8 @@ export default (
|
|||
// Calc count of my unread messages
|
||||
const count = await Message
|
||||
.count({
|
||||
recipient_id: userId,
|
||||
is_read: false
|
||||
recipientId: userId,
|
||||
isRead: false
|
||||
});
|
||||
|
||||
if (count == 0) {
|
||||
|
|
|
@ -29,10 +29,10 @@ export default (
|
|||
// Update documents
|
||||
await Notification.update({
|
||||
_id: { $in: ids },
|
||||
is_read: false
|
||||
isRead: false
|
||||
}, {
|
||||
$set: {
|
||||
is_read: true
|
||||
isRead: true
|
||||
}
|
||||
}, {
|
||||
multi: true
|
||||
|
@ -41,8 +41,8 @@ export default (
|
|||
// Calc count of my unread notifications
|
||||
const count = await Notification
|
||||
.count({
|
||||
notifiee_id: userId,
|
||||
is_read: false
|
||||
notifieeId: userId,
|
||||
isRead: false
|
||||
});
|
||||
|
||||
if (count == 0) {
|
||||
|
|
|
@ -3,15 +3,15 @@ import Watching from '../models/post-watching';
|
|||
|
||||
export default async (me: mongodb.ObjectID, post: object) => {
|
||||
// 自分の投稿はwatchできない
|
||||
if (me.equals((post as any).user_id)) {
|
||||
if (me.equals((post as any).userId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// if watching now
|
||||
const exist = await Watching.findOne({
|
||||
post_id: (post as any)._id,
|
||||
user_id: me,
|
||||
deleted_at: { $exists: false }
|
||||
postId: (post as any)._id,
|
||||
userId: me,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -19,8 +19,8 @@ export default async (me: mongodb.ObjectID, post: object) => {
|
|||
}
|
||||
|
||||
await Watching.insert({
|
||||
created_at: new Date(),
|
||||
post_id: (post as any)._id,
|
||||
user_id: me
|
||||
createdAt: new Date(),
|
||||
postId: (post as any)._id,
|
||||
userId: me
|
||||
});
|
||||
};
|
||||
|
|
|
@ -18,23 +18,23 @@ module.exports = params => new Promise(async (res, rej) => {
|
|||
const datas = await Post
|
||||
.aggregate([
|
||||
{ $project: {
|
||||
repost_id: '$repost_id',
|
||||
reply_id: '$reply_id',
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
repostId: '$repostId',
|
||||
replyId: '$replyId',
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
},
|
||||
type: {
|
||||
$cond: {
|
||||
if: { $ne: ['$repost_id', null] },
|
||||
if: { $ne: ['$repostId', null] },
|
||||
then: 'repost',
|
||||
else: {
|
||||
$cond: {
|
||||
if: { $ne: ['$reply_id', null] },
|
||||
if: { $ne: ['$replyId', null] },
|
||||
then: 'reply',
|
||||
else: 'post'
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
|
@ -27,15 +27,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const datas = await Reaction
|
||||
.aggregate([
|
||||
{ $match: { post_id: post._id } },
|
||||
{ $match: { postId: post._id } },
|
||||
{ $project: {
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
}
|
||||
}},
|
||||
{ $group: {
|
||||
|
|
|
@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
|
@ -29,10 +29,10 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const reactions = await Reaction
|
||||
.find({
|
||||
post_id: post._id,
|
||||
postId: post._id,
|
||||
$or: [
|
||||
{ deleted_at: { $exists: false } },
|
||||
{ deleted_at: { $gt: startTime } }
|
||||
{ deletedAt: { $exists: false } },
|
||||
{ deletedAt: { $gt: startTime } }
|
||||
]
|
||||
}, {
|
||||
sort: {
|
||||
|
@ -40,7 +40,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
},
|
||||
fields: {
|
||||
_id: false,
|
||||
post_id: false
|
||||
postId: false
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -55,7 +55,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
// day = day.getTime();
|
||||
|
||||
const count = reactions.filter(r =>
|
||||
r.created_at < day && (r.deleted_at == null || r.deleted_at > day)
|
||||
r.createdAt < day && (r.deletedAt == null || r.deletedAt > day)
|
||||
).length;
|
||||
|
||||
graph.push({
|
||||
|
|
|
@ -11,9 +11,9 @@ import Post from '../../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
|
@ -28,13 +28,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
.aggregate([
|
||||
{ $match: { reply: post._id } },
|
||||
{ $project: {
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
}
|
||||
}},
|
||||
{ $group: {
|
||||
|
|
|
@ -11,9 +11,9 @@ import Post from '../../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Lookup post
|
||||
const post = await Post.findOne({
|
||||
|
@ -26,15 +26,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const datas = await Post
|
||||
.aggregate([
|
||||
{ $match: { repost_id: post._id } },
|
||||
{ $match: { repostId: post._id } },
|
||||
{ $project: {
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
}
|
||||
}},
|
||||
{ $group: {
|
||||
|
|
|
@ -22,8 +22,8 @@ module.exports = params => new Promise(async (res, rej) => {
|
|||
},
|
||||
fields: {
|
||||
_id: false,
|
||||
created_at: true,
|
||||
deleted_at: true
|
||||
createdAt: true,
|
||||
deletedAt: true
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -44,11 +44,11 @@ module.exports = params => new Promise(async (res, rej) => {
|
|||
// day = day.getTime();
|
||||
|
||||
const total = users.filter(u =>
|
||||
u.created_at < dayEnd && (u.deleted_at == null || u.deleted_at > dayEnd)
|
||||
u.createdAt < dayEnd && (u.deletedAt == null || u.deletedAt > dayEnd)
|
||||
).length;
|
||||
|
||||
const created = users.filter(u =>
|
||||
u.created_at < dayEnd && u.created_at > dayStart
|
||||
u.createdAt < dayEnd && u.createdAt > dayStart
|
||||
).length;
|
||||
|
||||
graph.push({
|
||||
|
|
|
@ -18,9 +18,9 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$;
|
||||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
const user = await User.findOne({
|
||||
|
@ -37,25 +37,25 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const datas = await Post
|
||||
.aggregate([
|
||||
{ $match: { user_id: user._id } },
|
||||
{ $match: { userId: user._id } },
|
||||
{ $project: {
|
||||
repost_id: '$repost_id',
|
||||
reply_id: '$reply_id',
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
repostId: '$repostId',
|
||||
replyId: '$replyId',
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
},
|
||||
type: {
|
||||
$cond: {
|
||||
if: { $ne: ['$repost_id', null] },
|
||||
if: { $ne: ['$repostId', null] },
|
||||
then: 'repost',
|
||||
else: {
|
||||
$cond: {
|
||||
if: { $ne: ['$reply_id', null] },
|
||||
if: { $ne: ['$replyId', null] },
|
||||
then: 'reply',
|
||||
else: 'post'
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import Following from '../../../models/following';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
const user = await User.findOne({
|
||||
|
@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const following = await Following
|
||||
.find({
|
||||
followee_id: user._id,
|
||||
followeeId: user._id,
|
||||
$or: [
|
||||
{ deleted_at: { $exists: false } },
|
||||
{ deleted_at: { $gt: startTime } }
|
||||
{ deletedAt: { $exists: false } },
|
||||
{ deletedAt: { $gt: startTime } }
|
||||
]
|
||||
}, {
|
||||
_id: false,
|
||||
follower_id: false,
|
||||
followee_id: false
|
||||
followerId: false,
|
||||
followeeId: false
|
||||
}, {
|
||||
sort: { created_at: -1 }
|
||||
sort: { createdAt: -1 }
|
||||
});
|
||||
|
||||
const graph = [];
|
||||
|
@ -57,7 +57,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
// day = day.getTime();
|
||||
|
||||
const count = following.filter(f =>
|
||||
f.created_at < day && (f.deleted_at == null || f.deleted_at > day)
|
||||
f.createdAt < day && (f.deletedAt == null || f.deletedAt > day)
|
||||
).length;
|
||||
|
||||
graph.push({
|
||||
|
|
|
@ -12,9 +12,9 @@ import Following from '../../../models/following';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
const user = await User.findOne({
|
||||
|
@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const following = await Following
|
||||
.find({
|
||||
follower_id: user._id,
|
||||
followerId: user._id,
|
||||
$or: [
|
||||
{ deleted_at: { $exists: false } },
|
||||
{ deleted_at: { $gt: startTime } }
|
||||
{ deletedAt: { $exists: false } },
|
||||
{ deletedAt: { $gt: startTime } }
|
||||
]
|
||||
}, {
|
||||
_id: false,
|
||||
follower_id: false,
|
||||
followee_id: false
|
||||
followerId: false,
|
||||
followeeId: false
|
||||
}, {
|
||||
sort: { created_at: -1 }
|
||||
sort: { createdAt: -1 }
|
||||
});
|
||||
|
||||
const graph = [];
|
||||
|
@ -56,7 +56,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
day = new Date(day.setHours(23));
|
||||
|
||||
const count = following.filter(f =>
|
||||
f.created_at < day && (f.deleted_at == null || f.deleted_at > day)
|
||||
f.createdAt < day && (f.deletedAt == null || f.deletedAt > day)
|
||||
).length;
|
||||
|
||||
graph.push({
|
||||
|
|
|
@ -12,9 +12,9 @@ import Post from '../../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
const user = await User.findOne({
|
||||
|
@ -31,25 +31,25 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const datas = await Post
|
||||
.aggregate([
|
||||
{ $match: { user_id: user._id } },
|
||||
{ $match: { userId: user._id } },
|
||||
{ $project: {
|
||||
repost_id: '$repost_id',
|
||||
reply_id: '$reply_id',
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
repostId: '$repostId',
|
||||
replyId: '$replyId',
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
},
|
||||
type: {
|
||||
$cond: {
|
||||
if: { $ne: ['$repost_id', null] },
|
||||
if: { $ne: ['$repostId', null] },
|
||||
then: 'repost',
|
||||
else: {
|
||||
$cond: {
|
||||
if: { $ne: ['$reply_id', null] },
|
||||
if: { $ne: ['$replyId', null] },
|
||||
then: 'reply',
|
||||
else: 'post'
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Lookup user
|
||||
const user = await User.findOne({
|
||||
|
@ -31,15 +31,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
const datas = await Reaction
|
||||
.aggregate([
|
||||
{ $match: { user_id: user._id } },
|
||||
{ $match: { userId: user._id } },
|
||||
{ $project: {
|
||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||
}},
|
||||
{ $project: {
|
||||
date: {
|
||||
year: { $year: '$created_at' },
|
||||
month: { $month: '$created_at' },
|
||||
day: { $dayOfMonth: '$created_at' }
|
||||
year: { $year: '$createdAt' },
|
||||
month: { $month: '$createdAt' },
|
||||
day: { $dayOfMonth: '$createdAt' }
|
||||
}
|
||||
}},
|
||||
{ $group: {
|
||||
|
|
|
@ -13,7 +13,7 @@ import App, { isValidNameId, pack } from '../../models/app';
|
|||
* parameters:
|
||||
* - $ref: "#/parameters/AccessToken"
|
||||
* -
|
||||
* name: name_id
|
||||
* name: nameId
|
||||
* description: Application unique name
|
||||
* in: formData
|
||||
* required: true
|
||||
|
@ -66,9 +66,9 @@ import App, { isValidNameId, pack } from '../../models/app';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).string().$;
|
||||
|
@ -92,11 +92,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create account
|
||||
const app = await App.insert({
|
||||
created_at: new Date(),
|
||||
user_id: user._id,
|
||||
createdAt: new Date(),
|
||||
userId: user._id,
|
||||
name: name,
|
||||
name_id: nameId,
|
||||
name_id_lower: nameId.toLowerCase(),
|
||||
nameId: nameId,
|
||||
nameIdLower: nameId.toLowerCase(),
|
||||
description: description,
|
||||
permission: permission,
|
||||
callback_url: callbackUrl,
|
||||
|
|
|
@ -7,12 +7,12 @@ import { isValidNameId } from '../../../models/app';
|
|||
|
||||
/**
|
||||
* @swagger
|
||||
* /app/name_id/available:
|
||||
* /app/nameId/available:
|
||||
* post:
|
||||
* summary: Check available name_id on creation an application
|
||||
* summary: Check available nameId on creation an application
|
||||
* parameters:
|
||||
* -
|
||||
* name: name_id
|
||||
* name: nameId
|
||||
* description: Application unique name
|
||||
* in: formData
|
||||
* required: true
|
||||
|
@ -25,7 +25,7 @@ import { isValidNameId } from '../../../models/app';
|
|||
* type: object
|
||||
* properties:
|
||||
* available:
|
||||
* description: Whether name_id is available
|
||||
* description: Whether nameId is available
|
||||
* type: boolean
|
||||
*
|
||||
* default:
|
||||
|
@ -35,20 +35,20 @@ import { isValidNameId } from '../../../models/app';
|
|||
*/
|
||||
|
||||
/**
|
||||
* Check available name_id of app
|
||||
* Check available nameId of app
|
||||
*
|
||||
* @param {any} params
|
||||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params) => new Promise(async (res, rej) => {
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
// Get exist
|
||||
const exist = await App
|
||||
.count({
|
||||
name_id_lower: nameId.toLowerCase()
|
||||
nameIdLower: nameId.toLowerCase()
|
||||
}, {
|
||||
limit: 1
|
||||
});
|
||||
|
|
|
@ -9,15 +9,15 @@ import App, { pack } from '../../models/app';
|
|||
* /app/show:
|
||||
* post:
|
||||
* summary: Show an application's information
|
||||
* description: Require app_id or name_id
|
||||
* description: Require appId or nameId
|
||||
* parameters:
|
||||
* -
|
||||
* name: app_id
|
||||
* name: appId
|
||||
* description: Application ID
|
||||
* in: formData
|
||||
* type: string
|
||||
* -
|
||||
* name: name_id
|
||||
* name: nameId
|
||||
* description: Application unique name
|
||||
* in: formData
|
||||
* type: string
|
||||
|
@ -44,22 +44,22 @@ import App, { pack } from '../../models/app';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
||||
// Get 'app_id' parameter
|
||||
const [appId, appIdErr] = $(params.app_id).optional.id().$;
|
||||
if (appIdErr) return rej('invalid app_id param');
|
||||
// Get 'appId' parameter
|
||||
const [appId, appIdErr] = $(params.appId).optional.id().$;
|
||||
if (appIdErr) return rej('invalid appId param');
|
||||
|
||||
// Get 'name_id' parameter
|
||||
const [nameId, nameIdErr] = $(params.name_id).optional.string().$;
|
||||
if (nameIdErr) return rej('invalid name_id param');
|
||||
// Get 'nameId' parameter
|
||||
const [nameId, nameIdErr] = $(params.nameId).optional.string().$;
|
||||
if (nameIdErr) return rej('invalid nameId param');
|
||||
|
||||
if (appId === undefined && nameId === undefined) {
|
||||
return rej('app_id or name_id is required');
|
||||
return rej('appId or nameId is required');
|
||||
}
|
||||
|
||||
// Lookup app
|
||||
const app = appId !== undefined
|
||||
? await App.findOne({ _id: appId })
|
||||
: await App.findOne({ name_id_lower: nameId.toLowerCase() });
|
||||
: await App.findOne({ nameIdLower: nameId.toLowerCase() });
|
||||
|
||||
if (app === null) {
|
||||
return rej('app not found');
|
||||
|
@ -67,6 +67,6 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
|
|||
|
||||
// Send response
|
||||
res(await pack(app, user, {
|
||||
includeSecret: isSecure && app.user_id.equals(user._id)
|
||||
includeSecret: isSecure && app.userId.equals(user._id)
|
||||
}));
|
||||
});
|
||||
|
|
|
@ -56,14 +56,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Fetch exist access token
|
||||
const exist = await AccessToken.findOne({
|
||||
app_id: session.app_id,
|
||||
user_id: user._id,
|
||||
appId: session.appId,
|
||||
userId: user._id,
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
// Lookup app
|
||||
const app = await App.findOne({
|
||||
_id: session.app_id
|
||||
_id: session.appId
|
||||
});
|
||||
|
||||
// Generate Hash
|
||||
|
@ -73,9 +73,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Insert access token doc
|
||||
await AccessToken.insert({
|
||||
created_at: new Date(),
|
||||
app_id: session.app_id,
|
||||
user_id: user._id,
|
||||
createdAt: new Date(),
|
||||
appId: session.appId,
|
||||
userId: user._id,
|
||||
token: accessToken,
|
||||
hash: hash
|
||||
});
|
||||
|
@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Update session
|
||||
await AuthSess.update(session._id, {
|
||||
$set: {
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create session token document
|
||||
const doc = await AuthSess.insert({
|
||||
created_at: new Date(),
|
||||
app_id: app._id,
|
||||
createdAt: new Date(),
|
||||
appId: app._id,
|
||||
token: token
|
||||
});
|
||||
|
||||
|
|
|
@ -23,17 +23,17 @@ import AuthSess, { pack } from '../../../models/auth-session';
|
|||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* created_at:
|
||||
* createdAt:
|
||||
* type: string
|
||||
* format: date-time
|
||||
* description: Date and time of the session creation
|
||||
* app_id:
|
||||
* appId:
|
||||
* type: string
|
||||
* description: Application ID
|
||||
* token:
|
||||
* type: string
|
||||
* description: Session Token
|
||||
* user_id:
|
||||
* userId:
|
||||
* type: string
|
||||
* description: ID of user who create the session
|
||||
* app:
|
||||
|
|
|
@ -71,21 +71,21 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
const session = await AuthSess
|
||||
.findOne({
|
||||
token: token,
|
||||
app_id: app._id
|
||||
appId: app._id
|
||||
});
|
||||
|
||||
if (session === null) {
|
||||
return rej('session not found');
|
||||
}
|
||||
|
||||
if (session.user_id == null) {
|
||||
if (session.userId == null) {
|
||||
return rej('this session is not allowed yet');
|
||||
}
|
||||
|
||||
// Lookup access token
|
||||
const accessToken = await AccessToken.findOne({
|
||||
app_id: app._id,
|
||||
user_id: session.user_id
|
||||
appId: app._id,
|
||||
userId: session.userId
|
||||
});
|
||||
|
||||
// Delete session
|
||||
|
@ -101,8 +101,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
// Response
|
||||
res({
|
||||
access_token: accessToken.token,
|
||||
user: await pack(session.user_id, null, {
|
||||
accessToken: accessToken.token,
|
||||
user: await pack(session.userId, null, {
|
||||
detail: true
|
||||
})
|
||||
});
|
||||
|
|
|
@ -20,11 +20,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create a channel
|
||||
const channel = await Channel.insert({
|
||||
created_at: new Date(),
|
||||
user_id: user._id,
|
||||
createdAt: new Date(),
|
||||
userId: user._id,
|
||||
title: title,
|
||||
index: 0,
|
||||
watching_count: 1
|
||||
watchingCount: 1
|
||||
});
|
||||
|
||||
// Response
|
||||
|
@ -32,8 +32,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create Watching
|
||||
await Watching.insert({
|
||||
created_at: new Date(),
|
||||
user_id: user._id,
|
||||
channel_id: channel._id
|
||||
createdAt: new Date(),
|
||||
userId: user._id,
|
||||
channelId: channel._id
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,9 +30,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
return rej('cannot set since_id and until_id');
|
||||
}
|
||||
|
||||
// Get 'channel_id' parameter
|
||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
||||
if (channelIdErr) return rej('invalid channel_id param');
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
// Fetch channel
|
||||
const channel: IChannel = await Channel.findOne({
|
||||
|
@ -49,7 +49,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
};
|
||||
|
||||
const query = {
|
||||
channel_id: channel._id
|
||||
channelId: channel._id
|
||||
} as any;
|
||||
|
||||
if (sinceId) {
|
||||
|
|
|
@ -12,9 +12,9 @@ import Channel, { IChannel, pack } from '../../models/channel';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channel_id' parameter
|
||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
||||
if (channelIdErr) return rej('invalid channel_id param');
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
// Fetch channel
|
||||
const channel: IChannel = await Channel.findOne({
|
||||
|
|
|
@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channel_id' parameter
|
||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
||||
if (channelIdErr) return rej('invalid channel_id param');
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
//#region Fetch channel
|
||||
const channel = await Channel.findOne({
|
||||
|
@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
//#region Check whether not watching
|
||||
const exist = await Watching.findOne({
|
||||
user_id: user._id,
|
||||
channel_id: channel._id,
|
||||
deleted_at: { $exists: false }
|
||||
userId: user._id,
|
||||
channelId: channel._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
|
@ -44,7 +44,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: exist._id
|
||||
}, {
|
||||
$set: {
|
||||
deleted_at: new Date()
|
||||
deletedAt: new Date()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Decrement watching count
|
||||
Channel.update(channel._id, {
|
||||
$inc: {
|
||||
watching_count: -1
|
||||
watchingCount: -1
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'channel_id' parameter
|
||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
||||
if (channelIdErr) return rej('invalid channel_id param');
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||
if (channelIdErr) return rej('invalid channelId param');
|
||||
|
||||
//#region Fetch channel
|
||||
const channel = await Channel.findOne({
|
||||
|
@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
//#region Check whether already watching
|
||||
const exist = await Watching.findOne({
|
||||
user_id: user._id,
|
||||
channel_id: channel._id,
|
||||
deleted_at: { $exists: false }
|
||||
userId: user._id,
|
||||
channelId: channel._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create Watching
|
||||
await Watching.insert({
|
||||
created_at: new Date(),
|
||||
user_id: user._id,
|
||||
channel_id: channel._id
|
||||
createdAt: new Date(),
|
||||
userId: user._id,
|
||||
channelId: channel._id
|
||||
});
|
||||
|
||||
// Send response
|
||||
|
@ -52,7 +52,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Increment watching count
|
||||
Channel.update(channel._id, {
|
||||
$inc: {
|
||||
watching_count: 1
|
||||
watchingCount: 1
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Calculate drive usage
|
||||
const usage = ((await DriveFile
|
||||
.aggregate([
|
||||
{ $match: { 'metadata.user_id': user._id } },
|
||||
{ $match: { 'metadata.userId': user._id } },
|
||||
{
|
||||
$project: {
|
||||
length: true
|
||||
|
@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}).usage;
|
||||
|
||||
res({
|
||||
capacity: user.drive_capacity,
|
||||
capacity: user.driveCapacity,
|
||||
usage: usage
|
||||
});
|
||||
});
|
||||
|
|
|
@ -30,9 +30,9 @@ module.exports = async (params, user, app) => {
|
|||
throw 'cannot set since_id and until_id';
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) throw 'invalid folder_id param';
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
// Get 'type' parameter
|
||||
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$;
|
||||
|
@ -43,8 +43,8 @@ module.exports = async (params, user, app) => {
|
|||
_id: -1
|
||||
};
|
||||
const query = {
|
||||
'metadata.user_id': user._id,
|
||||
'metadata.folder_id': folderId
|
||||
'metadata.userId': user._id,
|
||||
'metadata.folderId': folderId
|
||||
} as any;
|
||||
if (sinceId) {
|
||||
sort._id = 1;
|
||||
|
|
|
@ -33,9 +33,9 @@ module.exports = async (file, params, user): Promise<any> => {
|
|||
name = null;
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) throw 'invalid folder_id param';
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
try {
|
||||
// Create file
|
||||
|
|
|
@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const [name, nameErr] = $(params.name).string().$;
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Issue query
|
||||
const files = await DriveFile
|
||||
.find({
|
||||
filename: name,
|
||||
'metadata.user_id': user._id,
|
||||
'metadata.folder_id': folderId
|
||||
'metadata.userId': user._id,
|
||||
'metadata.folderId': folderId
|
||||
});
|
||||
|
||||
// Serialize
|
||||
|
|
|
@ -12,15 +12,15 @@ import DriveFile, { pack } from '../../../models/drive-file';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => {
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = $(params.file_id).id().$;
|
||||
if (fileIdErr) throw 'invalid file_id param';
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
||||
if (fileIdErr) throw 'invalid fileId param';
|
||||
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
_id: fileId,
|
||||
'metadata.user_id': user._id
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (file === null) {
|
||||
|
|
|
@ -14,15 +14,15 @@ import { publishDriveStream } from '../../../event';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = $(params.file_id).id().$;
|
||||
if (fileIdErr) return rej('invalid file_id param');
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
||||
if (fileIdErr) return rej('invalid fileId param');
|
||||
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
_id: fileId,
|
||||
'metadata.user_id': user._id
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (file === null) {
|
||||
|
@ -34,33 +34,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (nameErr) return rej('invalid name param');
|
||||
if (name) file.filename = name;
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
if (folderId !== undefined) {
|
||||
if (folderId === null) {
|
||||
file.metadata.folder_id = null;
|
||||
file.metadata.folderId = null;
|
||||
} else {
|
||||
// Fetch folder
|
||||
const folder = await DriveFolder
|
||||
.findOne({
|
||||
_id: folderId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (folder === null) {
|
||||
return rej('folder-not-found');
|
||||
}
|
||||
|
||||
file.metadata.folder_id = folder._id;
|
||||
file.metadata.folderId = folder._id;
|
||||
}
|
||||
}
|
||||
|
||||
await DriveFile.update(file._id, {
|
||||
$set: {
|
||||
filename: file.filename,
|
||||
'metadata.folder_id': file.metadata.folder_id
|
||||
'metadata.folderId': file.metadata.folderId
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@ module.exports = async (params, user): Promise<any> => {
|
|||
const [url, urlErr] = $(params.url).string().$;
|
||||
if (urlErr) throw 'invalid url param';
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) throw 'invalid folder_id param';
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
if (folderIdErr) throw 'invalid folderId param';
|
||||
|
||||
return pack(await uploadFromUrl(url, user, folderId));
|
||||
};
|
||||
|
|
|
@ -30,17 +30,17 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
return rej('cannot set since_id and until_id');
|
||||
}
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
// Get 'folderId' parameter
|
||||
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Construct query
|
||||
const sort = {
|
||||
_id: -1
|
||||
};
|
||||
const query = {
|
||||
user_id: user._id,
|
||||
parent_id: folderId
|
||||
userId: user._id,
|
||||
parentId: folderId
|
||||
} as any;
|
||||
if (sinceId) {
|
||||
sort._id = 1;
|
||||
|
|
|
@ -17,9 +17,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$;
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parent_id' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
||||
if (parentIdErr) return rej('invalid parent_id param');
|
||||
// Get 'parentId' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
|
||||
// If the parent folder is specified
|
||||
let parent = null;
|
||||
|
@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
parent = await DriveFolder
|
||||
.findOne({
|
||||
_id: parentId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (parent === null) {
|
||||
|
@ -38,10 +38,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create folder
|
||||
const folder = await DriveFolder.insert({
|
||||
created_at: new Date(),
|
||||
createdAt: new Date(),
|
||||
name: name,
|
||||
parent_id: parent !== null ? parent._id : null,
|
||||
user_id: user._id
|
||||
parentId: parent !== null ? parent._id : null,
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
// Serialize
|
||||
|
|
|
@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const [name, nameErr] = $(params.name).string().$;
|
||||
if (nameErr) return rej('invalid name param');
|
||||
|
||||
// Get 'parent_id' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
||||
if (parentIdErr) return rej('invalid parent_id param');
|
||||
// Get 'parentId' parameter
|
||||
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
|
||||
// Issue query
|
||||
const folders = await DriveFolder
|
||||
.find({
|
||||
name: name,
|
||||
user_id: user._id,
|
||||
parent_id: parentId
|
||||
userId: user._id,
|
||||
parentId: parentId
|
||||
});
|
||||
|
||||
// Serialize
|
||||
|
|
|
@ -12,15 +12,15 @@ import DriveFolder, { pack } from '../../../models/drive-folder';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = $(params.folder_id).id().$;
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).id().$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Get folder
|
||||
const folder = await DriveFolder
|
||||
.findOne({
|
||||
_id: folderId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (folder === null) {
|
||||
|
|
|
@ -13,15 +13,15 @@ import { publishDriveStream } from '../../../event';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = $(params.folder_id).id().$;
|
||||
if (folderIdErr) return rej('invalid folder_id param');
|
||||
// Get 'folderId' parameter
|
||||
const [folderId, folderIdErr] = $(params.folderId).id().$;
|
||||
if (folderIdErr) return rej('invalid folderId param');
|
||||
|
||||
// Fetch folder
|
||||
const folder = await DriveFolder
|
||||
.findOne({
|
||||
_id: folderId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (folder === null) {
|
||||
|
@ -33,18 +33,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (nameErr) return rej('invalid name param');
|
||||
if (name) folder.name = name;
|
||||
|
||||
// Get 'parent_id' parameter
|
||||
const [parentId, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
||||
if (parentIdErr) return rej('invalid parent_id param');
|
||||
// Get 'parentId' parameter
|
||||
const [parentId, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||
if (parentIdErr) return rej('invalid parentId param');
|
||||
if (parentId !== undefined) {
|
||||
if (parentId === null) {
|
||||
folder.parent_id = null;
|
||||
folder.parentId = null;
|
||||
} else {
|
||||
// Get parent folder
|
||||
const parent = await DriveFolder
|
||||
.findOne({
|
||||
_id: parentId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (parent === null) {
|
||||
|
@ -58,25 +58,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: folderId
|
||||
}, {
|
||||
_id: true,
|
||||
parent_id: true
|
||||
parentId: true
|
||||
});
|
||||
|
||||
if (folder2._id.equals(folder._id)) {
|
||||
return true;
|
||||
} else if (folder2.parent_id) {
|
||||
return await checkCircle(folder2.parent_id);
|
||||
} else if (folder2.parentId) {
|
||||
return await checkCircle(folder2.parentId);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (parent.parent_id !== null) {
|
||||
if (await checkCircle(parent.parent_id)) {
|
||||
if (parent.parentId !== null) {
|
||||
if (await checkCircle(parent.parentId)) {
|
||||
return rej('detected-circular-definition');
|
||||
}
|
||||
}
|
||||
|
||||
folder.parent_id = parent._id;
|
||||
folder.parentId = parent._id;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
DriveFolder.update(folder._id, {
|
||||
$set: {
|
||||
name: folder.name,
|
||||
parent_id: folder.parent_id
|
||||
parentId: folder.parentId
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: -1
|
||||
};
|
||||
const query = {
|
||||
'metadata.user_id': user._id
|
||||
'metadata.userId': user._id
|
||||
} as any;
|
||||
if (sinceId) {
|
||||
sort._id = 1;
|
||||
|
|
|
@ -17,9 +17,9 @@ import event from '../../event';
|
|||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
if (user._id.equals(userId)) {
|
||||
|
@ -42,9 +42,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Check if already following
|
||||
const exist = await Following.findOne({
|
||||
follower_id: follower._id,
|
||||
followee_id: followee._id,
|
||||
deleted_at: { $exists: false }
|
||||
followerId: follower._id,
|
||||
followeeId: followee._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create following
|
||||
await Following.insert({
|
||||
created_at: new Date(),
|
||||
follower_id: follower._id,
|
||||
followee_id: followee._id
|
||||
createdAt: new Date(),
|
||||
followerId: follower._id,
|
||||
followeeId: followee._id
|
||||
});
|
||||
|
||||
// Send response
|
||||
|
@ -64,14 +64,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Increment following count
|
||||
User.update(follower._id, {
|
||||
$inc: {
|
||||
following_count: 1
|
||||
followingCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
// Increment followers count
|
||||
User.update({ _id: followee._id }, {
|
||||
$inc: {
|
||||
followers_count: 1
|
||||
followersCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@ import event from '../../event';
|
|||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const follower = user;
|
||||
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the followee is yourself
|
||||
if (user._id.equals(userId)) {
|
||||
|
@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Check not following
|
||||
const exist = await Following.findOne({
|
||||
follower_id: follower._id,
|
||||
followee_id: followee._id,
|
||||
deleted_at: { $exists: false }
|
||||
followerId: follower._id,
|
||||
followeeId: followee._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
|
@ -55,7 +55,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: exist._id
|
||||
}, {
|
||||
$set: {
|
||||
deleted_at: new Date()
|
||||
deletedAt: new Date()
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -65,14 +65,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Decrement following count
|
||||
User.update({ _id: follower._id }, {
|
||||
$inc: {
|
||||
following_count: -1
|
||||
followingCount: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Decrement followers count
|
||||
User.update({ _id: followee._id }, {
|
||||
$inc: {
|
||||
followers_count: -1
|
||||
followersCount: -1
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
|
|||
// Update lastUsedAt
|
||||
User.update({ _id: user._id }, {
|
||||
$set: {
|
||||
'account.last_used_at': new Date()
|
||||
'account.lastUsedAt': new Date()
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,12 +12,12 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
const _token = token.replace(/\s/g, '');
|
||||
|
||||
if (user.two_factor_temp_secret == null) {
|
||||
if (user.twoFactorTempSecret == null) {
|
||||
return rej('二段階認証の設定が開始されていません');
|
||||
}
|
||||
|
||||
const verified = (speakeasy as any).totp.verify({
|
||||
secret: user.two_factor_temp_secret,
|
||||
secret: user.twoFactorTempSecret,
|
||||
encoding: 'base32',
|
||||
token: _token
|
||||
});
|
||||
|
@ -28,8 +28,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.two_factor_secret': user.two_factor_temp_secret,
|
||||
'account.two_factor_enabled': true
|
||||
'account.twoFactorSecret': user.twoFactorTempSecret,
|
||||
'account.twoFactorEnabled': true
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
two_factor_temp_secret: secret.base32
|
||||
twoFactorTempSecret: secret.base32
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.two_factor_secret': null,
|
||||
'account.two_factor_enabled': false
|
||||
'account.twoFactorSecret': null,
|
||||
'account.twoFactorEnabled': false
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -25,8 +25,8 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
select[`data.${key}`] = true;
|
||||
}
|
||||
const appdata = await Appdata.findOne({
|
||||
app_id: app._id,
|
||||
user_id: user._id
|
||||
appId: app._id,
|
||||
userId: user._id
|
||||
}, {
|
||||
fields: select
|
||||
});
|
||||
|
|
|
@ -43,11 +43,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
await Appdata.update({
|
||||
app_id: app._id,
|
||||
user_id: user._id
|
||||
appId: app._id,
|
||||
userId: user._id
|
||||
}, Object.assign({
|
||||
app_id: app._id,
|
||||
user_id: user._id
|
||||
appId: app._id,
|
||||
userId: user._id
|
||||
}, {
|
||||
$set: set
|
||||
}), {
|
||||
|
|
|
@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Get tokens
|
||||
const tokens = await AccessToken
|
||||
.find({
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
|
@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Serialize
|
||||
res(await Promise.all(tokens.map(async token =>
|
||||
await pack(token.app_id))));
|
||||
await pack(token.appId))));
|
||||
});
|
||||
|
|
|
@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Get favorites
|
||||
const favorites = await Favorite
|
||||
.find({
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
|
|
|
@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
const mute = await Mute.find({
|
||||
muter_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
const query = {
|
||||
notifiee_id: user._id,
|
||||
notifieeId: user._id,
|
||||
$and: [{
|
||||
notifier_id: {
|
||||
$nin: mute.map(m => m.mutee_id)
|
||||
notifierId: {
|
||||
$nin: mute.map(m => m.muteeId)
|
||||
}
|
||||
}]
|
||||
} as any;
|
||||
|
@ -69,7 +69,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const followingIds = await getFriends(user._id);
|
||||
|
||||
query.$and.push({
|
||||
notifier_id: {
|
||||
notifierId: {
|
||||
$in: followingIds
|
||||
}
|
||||
});
|
||||
|
|
|
@ -14,14 +14,14 @@ import { pack } from '../../models/user';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Fetch pinee
|
||||
const post = await Post.findOne({
|
||||
_id: postId,
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (post === null) {
|
||||
|
@ -30,7 +30,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
pinned_post_id: post._id
|
||||
pinnedPostId: post._id
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
const query = {
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
} as any;
|
||||
|
||||
const sort = {
|
||||
|
|
|
@ -36,20 +36,20 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
|||
if (birthdayErr) return rej('invalid birthday param');
|
||||
if (birthday !== undefined) user.account.profile.birthday = birthday;
|
||||
|
||||
// Get 'avatar_id' parameter
|
||||
const [avatarId, avatarIdErr] = $(params.avatar_id).optional.id().$;
|
||||
if (avatarIdErr) return rej('invalid avatar_id param');
|
||||
if (avatarId) user.avatar_id = avatarId;
|
||||
// Get 'avatarId' parameter
|
||||
const [avatarId, avatarIdErr] = $(params.avatarId).optional.id().$;
|
||||
if (avatarIdErr) return rej('invalid avatarId param');
|
||||
if (avatarId) user.avatarId = avatarId;
|
||||
|
||||
// Get 'banner_id' parameter
|
||||
const [bannerId, bannerIdErr] = $(params.banner_id).optional.id().$;
|
||||
if (bannerIdErr) return rej('invalid banner_id param');
|
||||
if (bannerId) user.banner_id = bannerId;
|
||||
// Get 'bannerId' parameter
|
||||
const [bannerId, bannerIdErr] = $(params.bannerId).optional.id().$;
|
||||
if (bannerIdErr) return rej('invalid bannerId param');
|
||||
if (bannerId) user.bannerId = bannerId;
|
||||
|
||||
// Get 'is_bot' parameter
|
||||
const [isBot, isBotErr] = $(params.is_bot).optional.boolean().$;
|
||||
if (isBotErr) return rej('invalid is_bot param');
|
||||
if (isBot != null) user.account.is_bot = isBot;
|
||||
// Get 'isBot' parameter
|
||||
const [isBot, isBotErr] = $(params.isBot).optional.boolean().$;
|
||||
if (isBotErr) return rej('invalid isBot param');
|
||||
if (isBot != null) user.account.isBot = isBot;
|
||||
|
||||
// Get 'auto_watch' parameter
|
||||
const [autoWatch, autoWatchErr] = $(params.auto_watch).optional.boolean().$;
|
||||
|
@ -60,10 +60,10 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
|||
$set: {
|
||||
name: user.name,
|
||||
description: user.description,
|
||||
avatar_id: user.avatar_id,
|
||||
banner_id: user.banner_id,
|
||||
avatarId: user.avatarId,
|
||||
bannerId: user.bannerId,
|
||||
'account.profile': user.account.profile,
|
||||
'account.is_bot': user.account.is_bot,
|
||||
'account.isBot': user.account.isBot,
|
||||
'account.settings': user.account.settings
|
||||
}
|
||||
});
|
||||
|
|
|
@ -22,14 +22,14 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
if (valueErr) return rej('invalid value param');
|
||||
|
||||
const x = {};
|
||||
x[`account.client_settings.${name}`] = value;
|
||||
x[`account.clientSettings.${name}`] = value;
|
||||
|
||||
await User.update(user._id, {
|
||||
$set: x
|
||||
});
|
||||
|
||||
// Serialize
|
||||
user.account.client_settings[name] = value;
|
||||
user.account.clientSettings[name] = value;
|
||||
const iObj = await pack(user, user, {
|
||||
detail: true,
|
||||
includeSecrets: true
|
||||
|
|
|
@ -26,7 +26,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
if (home) {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.client_settings.home': home
|
||||
'account.clientSettings.home': home
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -38,7 +38,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
} else {
|
||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
||||
|
||||
const _home = user.account.client_settings.home;
|
||||
const _home = user.account.clientSettings.home;
|
||||
const widget = _home.find(w => w.id == id);
|
||||
|
||||
if (widget == null) return rej('widget not found');
|
||||
|
@ -47,7 +47,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.client_settings.home': _home
|
||||
'account.clientSettings.home': _home
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
if (home) {
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.client_settings.mobile_home': home
|
||||
'account.clientSettings.mobile_home': home
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -37,7 +37,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
} else {
|
||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
||||
|
||||
const _home = user.account.client_settings.mobile_home || [];
|
||||
const _home = user.account.clientSettings.mobile_home || [];
|
||||
const widget = _home.find(w => w.id == id);
|
||||
|
||||
if (widget == null) return rej('widget not found');
|
||||
|
@ -46,7 +46,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await User.update(user._id, {
|
||||
$set: {
|
||||
'account.client_settings.mobile_home': _home
|
||||
'account.clientSettings.mobile_home': _home
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -19,25 +19,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (limitErr) return rej('invalid limit param');
|
||||
|
||||
const mute = await Mute.find({
|
||||
muter_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
// Get history
|
||||
const history = await History
|
||||
.find({
|
||||
user_id: user._id,
|
||||
partner: {
|
||||
$nin: mute.map(m => m.mutee_id)
|
||||
userId: user._id,
|
||||
partnerId: {
|
||||
$nin: mute.map(m => m.muteeId)
|
||||
}
|
||||
}, {
|
||||
limit: limit,
|
||||
sort: {
|
||||
updated_at: -1
|
||||
updatedAt: -1
|
||||
}
|
||||
});
|
||||
|
||||
// Serialize
|
||||
res(await Promise.all(history.map(async h =>
|
||||
await pack(h.message, user))));
|
||||
await pack(h.messageId, user))));
|
||||
});
|
||||
|
|
|
@ -15,9 +15,9 @@ import read from '../../common/read-messaging-message';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.user_id).id().$;
|
||||
if (recipientIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.userId).id().$;
|
||||
if (recipientIdErr) return rej('invalid userId param');
|
||||
|
||||
// Fetch recipient
|
||||
const recipient = await User.findOne({
|
||||
|
@ -55,11 +55,11 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
const query = {
|
||||
$or: [{
|
||||
user_id: user._id,
|
||||
recipient_id: recipient._id
|
||||
userId: user._id,
|
||||
recipientId: recipient._id
|
||||
}, {
|
||||
user_id: recipient._id,
|
||||
recipient_id: user._id
|
||||
userId: recipient._id,
|
||||
recipientId: user._id
|
||||
}]
|
||||
} as any;
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ import config from '../../../../conf';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.user_id).id().$;
|
||||
if (recipientIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [recipientId, recipientIdErr] = $(params.userId).id().$;
|
||||
if (recipientIdErr) return rej('invalid userId param');
|
||||
|
||||
// Myself
|
||||
if (recipientId.equals(user._id)) {
|
||||
|
@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'file_id' parameter
|
||||
const [fileId, fileIdErr] = $(params.file_id).optional.id().$;
|
||||
if (fileIdErr) return rej('invalid file_id param');
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $(params.fileId).optional.id().$;
|
||||
if (fileIdErr) return rej('invalid fileId param');
|
||||
|
||||
let file = null;
|
||||
if (fileId !== undefined) {
|
||||
file = await DriveFile.findOne({
|
||||
_id: fileId,
|
||||
'metadata.user_id': user._id
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (file === null) {
|
||||
|
@ -70,12 +70,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// メッセージを作成
|
||||
const message = await Message.insert({
|
||||
created_at: new Date(),
|
||||
file_id: file ? file._id : undefined,
|
||||
recipient_id: recipient._id,
|
||||
createdAt: new Date(),
|
||||
fileId: file ? file._id : undefined,
|
||||
recipientId: recipient._id,
|
||||
text: text ? text : undefined,
|
||||
user_id: user._id,
|
||||
is_read: false
|
||||
userId: user._id,
|
||||
isRead: false
|
||||
});
|
||||
|
||||
// Serialize
|
||||
|
@ -85,32 +85,32 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
res(messageObj);
|
||||
|
||||
// 自分のストリーム
|
||||
publishMessagingStream(message.user_id, message.recipient_id, 'message', messageObj);
|
||||
publishMessagingIndexStream(message.user_id, 'message', messageObj);
|
||||
publishUserStream(message.user_id, 'messaging_message', messageObj);
|
||||
publishMessagingStream(message.userId, message.recipientId, 'message', messageObj);
|
||||
publishMessagingIndexStream(message.userId, 'message', messageObj);
|
||||
publishUserStream(message.userId, 'messaging_message', messageObj);
|
||||
|
||||
// 相手のストリーム
|
||||
publishMessagingStream(message.recipient_id, message.user_id, 'message', messageObj);
|
||||
publishMessagingIndexStream(message.recipient_id, 'message', messageObj);
|
||||
publishUserStream(message.recipient_id, 'messaging_message', messageObj);
|
||||
publishMessagingStream(message.recipientId, message.userId, 'message', messageObj);
|
||||
publishMessagingIndexStream(message.recipientId, 'message', messageObj);
|
||||
publishUserStream(message.recipientId, 'messaging_message', messageObj);
|
||||
|
||||
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
|
||||
setTimeout(async () => {
|
||||
const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true });
|
||||
if (!freshMessage.is_read) {
|
||||
const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });
|
||||
if (!freshMessage.isRead) {
|
||||
//#region ただしミュートされているなら発行しない
|
||||
const mute = await Mute.find({
|
||||
muter_id: recipient._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: recipient._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mutedUserIds = mute.map(m => m.mutee_id.toString());
|
||||
const mutedUserIds = mute.map(m => m.muteeId.toString());
|
||||
if (mutedUserIds.indexOf(user._id.toString()) != -1) {
|
||||
return;
|
||||
}
|
||||
//#endregion
|
||||
|
||||
publishUserStream(message.recipient_id, 'unread_messaging_message', messageObj);
|
||||
pushSw(message.recipient_id, 'unread_messaging_message', messageObj);
|
||||
publishUserStream(message.recipientId, 'unread_messaging_message', messageObj);
|
||||
pushSw(message.recipientId, 'unread_messaging_message', messageObj);
|
||||
}
|
||||
}, 3000);
|
||||
|
||||
|
@ -130,26 +130,26 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// 履歴作成(自分)
|
||||
History.update({
|
||||
user_id: user._id,
|
||||
partner: recipient._id
|
||||
userId: user._id,
|
||||
partnerId: recipient._id
|
||||
}, {
|
||||
updated_at: new Date(),
|
||||
user_id: user._id,
|
||||
partner: recipient._id,
|
||||
message: message._id
|
||||
updatedAt: new Date(),
|
||||
userId: user._id,
|
||||
partnerId: recipient._id,
|
||||
messageId: message._id
|
||||
}, {
|
||||
upsert: true
|
||||
});
|
||||
|
||||
// 履歴作成(相手)
|
||||
History.update({
|
||||
user_id: recipient._id,
|
||||
partner: user._id
|
||||
userId: recipient._id,
|
||||
partnerId: user._id
|
||||
}, {
|
||||
updated_at: new Date(),
|
||||
user_id: recipient._id,
|
||||
partner: user._id,
|
||||
message: message._id
|
||||
updatedAt: new Date(),
|
||||
userId: recipient._id,
|
||||
partnerId: user._id,
|
||||
messageId: message._id
|
||||
}, {
|
||||
upsert: true
|
||||
});
|
||||
|
|
|
@ -13,18 +13,18 @@ import Mute from '../../models/mute';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const mute = await Mute.find({
|
||||
muter_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mutedUserIds = mute.map(m => m.mutee_id);
|
||||
const mutedUserIds = mute.map(m => m.muteeId);
|
||||
|
||||
const count = await Message
|
||||
.count({
|
||||
user_id: {
|
||||
userId: {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
recipient_id: user._id,
|
||||
is_read: false
|
||||
recipientId: user._id,
|
||||
isRead: false
|
||||
});
|
||||
|
||||
res({
|
||||
|
|
|
@ -15,9 +15,9 @@ import Mute from '../../models/mute';
|
|||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// 自分自身
|
||||
if (user._id.equals(userId)) {
|
||||
|
@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Check if already muting
|
||||
const exist = await Mute.findOne({
|
||||
muter_id: muter._id,
|
||||
mutee_id: mutee._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: muter._id,
|
||||
muteeId: mutee._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -51,9 +51,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create mute
|
||||
await Mute.insert({
|
||||
created_at: new Date(),
|
||||
muter_id: muter._id,
|
||||
mutee_id: mutee._id,
|
||||
createdAt: new Date(),
|
||||
muterId: muter._id,
|
||||
muteeId: mutee._id,
|
||||
});
|
||||
|
||||
// Send response
|
||||
|
|
|
@ -15,9 +15,9 @@ import Mute from '../../models/mute';
|
|||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const muter = user;
|
||||
|
||||
// Get 'user_id' parameter
|
||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
||||
if (userIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [userId, userIdErr] = $(params.userId).id().$;
|
||||
if (userIdErr) return rej('invalid userId param');
|
||||
|
||||
// Check if the mutee is yourself
|
||||
if (user._id.equals(userId)) {
|
||||
|
@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Check not muting
|
||||
const exist = await Mute.findOne({
|
||||
muter_id: muter._id,
|
||||
mutee_id: mutee._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: muter._id,
|
||||
muteeId: mutee._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
|
@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: exist._id
|
||||
}, {
|
||||
$set: {
|
||||
deleted_at: new Date()
|
||||
deletedAt: new Date()
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -28,15 +28,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
|
||||
// Construct query
|
||||
const query = {
|
||||
muter_id: me._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: me._id,
|
||||
deletedAt: { $exists: false }
|
||||
} as any;
|
||||
|
||||
if (iknow) {
|
||||
// Get my friends
|
||||
const myFriends = await getFriends(me._id);
|
||||
|
||||
query.mutee_id = {
|
||||
query.muteeId = {
|
||||
$in: myFriends
|
||||
};
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
|
||||
// Serialize
|
||||
const users = await Promise.all(mutes.map(async m =>
|
||||
await pack(m.mutee_id, me, { detail: true })));
|
||||
await pack(m.muteeId, me, { detail: true })));
|
||||
|
||||
// Response
|
||||
res({
|
||||
|
|
|
@ -21,7 +21,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (offsetErr) return rej('invalid offset param');
|
||||
|
||||
const query = {
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
};
|
||||
|
||||
// Execute query
|
||||
|
|
|
@ -13,18 +13,18 @@ import Mute from '../../models/mute';
|
|||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
const mute = await Mute.find({
|
||||
muter_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mutedUserIds = mute.map(m => m.mutee_id);
|
||||
const mutedUserIds = mute.map(m => m.muteeId);
|
||||
|
||||
const count = await Notification
|
||||
.count({
|
||||
notifiee_id: user._id,
|
||||
notifier_id: {
|
||||
notifieeId: user._id,
|
||||
notifierId: {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
is_read: false
|
||||
isRead: false
|
||||
});
|
||||
|
||||
res({
|
||||
|
|
|
@ -14,11 +14,11 @@ import event from '../../event';
|
|||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Update documents
|
||||
await Notification.update({
|
||||
notifiee_id: user._id,
|
||||
is_read: false
|
||||
notifieeId: user._id,
|
||||
isRead: false
|
||||
}, {
|
||||
$set: {
|
||||
is_read: true
|
||||
isRead: true
|
||||
}
|
||||
}, {
|
||||
multi: true
|
||||
|
|
|
@ -24,14 +24,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
const q: any = my ? {
|
||||
is_started: true,
|
||||
isStarted: true,
|
||||
$or: [{
|
||||
user1_id: user._id
|
||||
user1Id: user._id
|
||||
}, {
|
||||
user2_id: user._id
|
||||
user2Id: user._id
|
||||
}]
|
||||
} : {
|
||||
is_started: true
|
||||
isStarted: true
|
||||
};
|
||||
|
||||
const sort = {
|
||||
|
|
|
@ -14,9 +14,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
const o = new Othello(game.settings.map, {
|
||||
isLlotheo: game.settings.is_llotheo,
|
||||
canPutEverywhere: game.settings.can_put_everywhere,
|
||||
loopedBoard: game.settings.looped_board
|
||||
isLlotheo: game.settings.isLlotheo,
|
||||
canPutEverywhere: game.settings.canPutEverywhere,
|
||||
loopedBoard: game.settings.loopedBoard
|
||||
});
|
||||
|
||||
game.logs.forEach(log => {
|
||||
|
|
|
@ -3,7 +3,7 @@ import Matching, { pack as packMatching } from '../../models/othello-matching';
|
|||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Find session
|
||||
const invitations = await Matching.find({
|
||||
child_id: user._id
|
||||
childId: user._id
|
||||
}, {
|
||||
sort: {
|
||||
_id: -1
|
||||
|
|
|
@ -6,19 +6,19 @@ import publishUserStream, { publishOthelloStream } from '../../event';
|
|||
import { eighteight } from '../../../common/othello/maps';
|
||||
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'user_id' parameter
|
||||
const [childId, childIdErr] = $(params.user_id).id().$;
|
||||
if (childIdErr) return rej('invalid user_id param');
|
||||
// Get 'userId' parameter
|
||||
const [childId, childIdErr] = $(params.userId).id().$;
|
||||
if (childIdErr) return rej('invalid userId param');
|
||||
|
||||
// Myself
|
||||
if (childId.equals(user._id)) {
|
||||
return rej('invalid user_id param');
|
||||
return rej('invalid userId param');
|
||||
}
|
||||
|
||||
// Find session
|
||||
const exist = await Matching.findOne({
|
||||
parent_id: childId,
|
||||
child_id: user._id
|
||||
parentId: childId,
|
||||
childId: user._id
|
||||
});
|
||||
|
||||
if (exist) {
|
||||
|
@ -29,28 +29,28 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create game
|
||||
const game = await OthelloGame.insert({
|
||||
created_at: new Date(),
|
||||
user1_id: exist.parent_id,
|
||||
user2_id: user._id,
|
||||
user1_accepted: false,
|
||||
user2_accepted: false,
|
||||
is_started: false,
|
||||
is_ended: false,
|
||||
createdAt: new Date(),
|
||||
user1Id: exist.parentId,
|
||||
user2Id: user._id,
|
||||
user1Accepted: false,
|
||||
user2Accepted: false,
|
||||
isStarted: false,
|
||||
isEnded: false,
|
||||
logs: [],
|
||||
settings: {
|
||||
map: eighteight.data,
|
||||
bw: 'random',
|
||||
is_llotheo: false
|
||||
isLlotheo: false
|
||||
}
|
||||
});
|
||||
|
||||
// Reponse
|
||||
res(await packGame(game, user));
|
||||
|
||||
publishOthelloStream(exist.parent_id, 'matched', await packGame(game, exist.parent_id));
|
||||
publishOthelloStream(exist.parentId, 'matched', await packGame(game, exist.parentId));
|
||||
|
||||
const other = await Matching.count({
|
||||
child_id: user._id
|
||||
childId: user._id
|
||||
});
|
||||
|
||||
if (other == 0) {
|
||||
|
@ -72,14 +72,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// 以前のセッションはすべて削除しておく
|
||||
await Matching.remove({
|
||||
parent_id: user._id
|
||||
parentId: user._id
|
||||
});
|
||||
|
||||
// セッションを作成
|
||||
const matching = await Matching.insert({
|
||||
created_at: new Date(),
|
||||
parent_id: user._id,
|
||||
child_id: child._id
|
||||
createdAt: new Date(),
|
||||
parentId: user._id,
|
||||
childId: child._id
|
||||
});
|
||||
|
||||
// Reponse
|
||||
|
|
|
@ -2,7 +2,7 @@ import Matching from '../../../models/othello-matching';
|
|||
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
await Matching.remove({
|
||||
parent_id: user._id
|
||||
parentId: user._id
|
||||
});
|
||||
|
||||
res();
|
||||
|
|
|
@ -65,15 +65,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
if (reply != undefined) {
|
||||
query.reply_id = reply ? { $exists: true, $ne: null } : null;
|
||||
query.replyId = reply ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (repost != undefined) {
|
||||
query.repost_id = repost ? { $exists: true, $ne: null } : null;
|
||||
query.repostId = repost ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (media != undefined) {
|
||||
query.media_ids = media ? { $exists: true, $ne: null } : null;
|
||||
query.mediaIds = media ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (poll != undefined) {
|
||||
|
@ -82,7 +82,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
|||
|
||||
// TODO
|
||||
//if (bot != undefined) {
|
||||
// query.is_bot = bot;
|
||||
// query.isBot = bot;
|
||||
//}
|
||||
|
||||
// Issue query
|
||||
|
|
|
@ -12,13 +12,13 @@ import Post from '../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
if (!user.account.is_pro) {
|
||||
if (!user.account.isPro) {
|
||||
return rej('This endpoint is available only from a Pro account');
|
||||
}
|
||||
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get categorizee
|
||||
const post = await Post.findOne({
|
||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
|
@ -48,13 +48,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
return;
|
||||
}
|
||||
|
||||
if (p.reply_id) {
|
||||
await get(p.reply_id);
|
||||
if (p.replyId) {
|
||||
await get(p.replyId);
|
||||
}
|
||||
}
|
||||
|
||||
if (post.reply_id) {
|
||||
await get(post.reply_id);
|
||||
if (post.replyId) {
|
||||
await get(post.replyId);
|
||||
}
|
||||
|
||||
// Serialize
|
||||
|
|
|
@ -33,9 +33,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
|
||||
if (textErr) return rej('invalid text');
|
||||
|
||||
// Get 'via_mobile' parameter
|
||||
const [viaMobile = false, viaMobileErr] = $(params.via_mobile).optional.boolean().$;
|
||||
if (viaMobileErr) return rej('invalid via_mobile');
|
||||
// Get 'viaMobile' parameter
|
||||
const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().$;
|
||||
if (viaMobileErr) return rej('invalid viaMobile');
|
||||
|
||||
// Get 'tags' parameter
|
||||
const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
|
||||
|
@ -53,9 +53,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
.$;
|
||||
if (geoErr) return rej('invalid geo');
|
||||
|
||||
// Get 'media_ids' parameter
|
||||
const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$;
|
||||
if (mediaIdsErr) return rej('invalid media_ids');
|
||||
// Get 'mediaIds' parameter
|
||||
const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array('id').unique().range(1, 4).$;
|
||||
if (mediaIdsErr) return rej('invalid mediaIds');
|
||||
|
||||
let files = [];
|
||||
if (mediaIds !== undefined) {
|
||||
|
@ -67,7 +67,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
// SELECT _id
|
||||
const entity = await DriveFile.findOne({
|
||||
_id: mediaId,
|
||||
'metadata.user_id': user._id
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (entity === null) {
|
||||
|
@ -80,9 +80,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
files = null;
|
||||
}
|
||||
|
||||
// Get 'repost_id' parameter
|
||||
const [repostId, repostIdErr] = $(params.repost_id).optional.id().$;
|
||||
if (repostIdErr) return rej('invalid repost_id');
|
||||
// Get 'repostId' parameter
|
||||
const [repostId, repostIdErr] = $(params.repostId).optional.id().$;
|
||||
if (repostIdErr) return rej('invalid repostId');
|
||||
|
||||
let repost: IPost = null;
|
||||
let isQuote = false;
|
||||
|
@ -94,13 +94,13 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
|
||||
if (repost == null) {
|
||||
return rej('repostee is not found');
|
||||
} else if (repost.repost_id && !repost.text && !repost.media_ids) {
|
||||
} else if (repost.repostId && !repost.text && !repost.mediaIds) {
|
||||
return rej('cannot repost to repost');
|
||||
}
|
||||
|
||||
// Fetch recently post
|
||||
const latestPost = await Post.findOne({
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
}, {
|
||||
sort: {
|
||||
_id: -1
|
||||
|
@ -111,8 +111,8 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
|
||||
// 直近と同じRepost対象かつ引用じゃなかったらエラー
|
||||
if (latestPost &&
|
||||
latestPost.repost_id &&
|
||||
latestPost.repost_id.equals(repost._id) &&
|
||||
latestPost.repostId &&
|
||||
latestPost.repostId.equals(repost._id) &&
|
||||
!isQuote) {
|
||||
return rej('cannot repost same post that already reposted in your latest post');
|
||||
}
|
||||
|
@ -125,9 +125,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
}
|
||||
|
||||
// Get 'reply_id' parameter
|
||||
const [replyId, replyIdErr] = $(params.reply_id).optional.id().$;
|
||||
if (replyIdErr) return rej('invalid reply_id');
|
||||
// Get 'replyId' parameter
|
||||
const [replyId, replyIdErr] = $(params.replyId).optional.id().$;
|
||||
if (replyIdErr) return rej('invalid replyId');
|
||||
|
||||
let reply: IPost = null;
|
||||
if (replyId !== undefined) {
|
||||
|
@ -141,14 +141,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
// 返信対象が引用でないRepostだったらエラー
|
||||
if (reply.repost_id && !reply.text && !reply.media_ids) {
|
||||
if (reply.repostId && !reply.text && !reply.mediaIds) {
|
||||
return rej('cannot reply to repost');
|
||||
}
|
||||
}
|
||||
|
||||
// Get 'channel_id' parameter
|
||||
const [channelId, channelIdErr] = $(params.channel_id).optional.id().$;
|
||||
if (channelIdErr) return rej('invalid channel_id');
|
||||
// Get 'channelId' parameter
|
||||
const [channelId, channelIdErr] = $(params.channelId).optional.id().$;
|
||||
if (channelIdErr) return rej('invalid channelId');
|
||||
|
||||
let channel: IChannel = null;
|
||||
if (channelId !== undefined) {
|
||||
|
@ -162,12 +162,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
// 返信対象の投稿がこのチャンネルじゃなかったらダメ
|
||||
if (reply && !channelId.equals(reply.channel_id)) {
|
||||
if (reply && !channelId.equals(reply.channelId)) {
|
||||
return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
|
||||
}
|
||||
|
||||
// Repost対象の投稿がこのチャンネルじゃなかったらダメ
|
||||
if (repost && !channelId.equals(repost.channel_id)) {
|
||||
if (repost && !channelId.equals(repost.channelId)) {
|
||||
return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません');
|
||||
}
|
||||
|
||||
|
@ -177,12 +177,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
} else {
|
||||
// 返信対象の投稿がチャンネルへの投稿だったらダメ
|
||||
if (reply && reply.channel_id != null) {
|
||||
if (reply && reply.channelId != null) {
|
||||
return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
|
||||
}
|
||||
|
||||
// Repost対象の投稿がチャンネルへの投稿だったらダメ
|
||||
if (repost && repost.channel_id != null) {
|
||||
if (repost && repost.channelId != null) {
|
||||
return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
|
||||
// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
|
||||
if (text === undefined && files === null && repost === null && poll === undefined) {
|
||||
return rej('text, media_ids, repost_id or poll is required');
|
||||
return rej('text, mediaIds, repostId or poll is required');
|
||||
}
|
||||
|
||||
// 直近の投稿と重複してたらエラー
|
||||
|
@ -214,14 +214,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
if (user.latest_post) {
|
||||
if (deepEqual({
|
||||
text: user.latest_post.text,
|
||||
reply: user.latest_post.reply_id ? user.latest_post.reply_id.toString() : null,
|
||||
repost: user.latest_post.repost_id ? user.latest_post.repost_id.toString() : null,
|
||||
media_ids: (user.latest_post.media_ids || []).map(id => id.toString())
|
||||
reply: user.latest_post.replyId ? user.latest_post.replyId.toString() : null,
|
||||
repost: user.latest_post.repostId ? user.latest_post.repostId.toString() : null,
|
||||
mediaIds: (user.latest_post.mediaIds || []).map(id => id.toString())
|
||||
}, {
|
||||
text: text,
|
||||
reply: reply ? reply._id.toString() : null,
|
||||
repost: repost ? repost._id.toString() : null,
|
||||
media_ids: (files || []).map(file => file._id.toString())
|
||||
mediaIds: (files || []).map(file => file._id.toString())
|
||||
})) {
|
||||
return rej('duplicate');
|
||||
}
|
||||
|
@ -246,23 +246,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
|
||||
// 投稿を作成
|
||||
const post = await Post.insert({
|
||||
created_at: new Date(),
|
||||
channel_id: channel ? channel._id : undefined,
|
||||
createdAt: new Date(),
|
||||
channelId: channel ? channel._id : undefined,
|
||||
index: channel ? channel.index + 1 : undefined,
|
||||
media_ids: files ? files.map(file => file._id) : undefined,
|
||||
reply_id: reply ? reply._id : undefined,
|
||||
repost_id: repost ? repost._id : undefined,
|
||||
mediaIds: files ? files.map(file => file._id) : undefined,
|
||||
replyId: reply ? reply._id : undefined,
|
||||
repostId: repost ? repost._id : undefined,
|
||||
poll: poll,
|
||||
text: text,
|
||||
tags: tags,
|
||||
user_id: user._id,
|
||||
app_id: app ? app._id : null,
|
||||
via_mobile: viaMobile,
|
||||
userId: user._id,
|
||||
appId: app ? app._id : null,
|
||||
viaMobile: viaMobile,
|
||||
geo,
|
||||
|
||||
// 以下非正規化データ
|
||||
_reply: reply ? { user_id: reply.user_id } : undefined,
|
||||
_repost: repost ? { user_id: repost.user_id } : undefined,
|
||||
_reply: reply ? { userId: reply.userId } : undefined,
|
||||
_repost: repost ? { userId: repost.userId } : undefined,
|
||||
});
|
||||
|
||||
// Serialize
|
||||
|
@ -293,10 +293,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
// Publish event
|
||||
if (!user._id.equals(mentionee)) {
|
||||
const mentioneeMutes = await Mute.find({
|
||||
muter_id: mentionee,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: mentionee,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mentioneesMutedUserIds = mentioneeMutes.map(m => m.mutee_id.toString());
|
||||
const mentioneesMutedUserIds = mentioneeMutes.map(m => m.muteeId.toString());
|
||||
if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
|
||||
event(mentionee, reason, postObj);
|
||||
pushSw(mentionee, reason, postObj);
|
||||
|
@ -312,17 +312,17 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
// Fetch all followers
|
||||
const followers = await Following
|
||||
.find({
|
||||
followee_id: user._id,
|
||||
followeeId: user._id,
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
follower_id: true,
|
||||
followerId: true,
|
||||
_id: false
|
||||
});
|
||||
|
||||
// Publish event to followers stream
|
||||
followers.forEach(following =>
|
||||
event(following.follower_id, 'post', postObj));
|
||||
event(following.followerId, 'post', postObj));
|
||||
}
|
||||
|
||||
// チャンネルへの投稿
|
||||
|
@ -339,21 +339,21 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
|
||||
// Get channel watchers
|
||||
const watches = await ChannelWatching.find({
|
||||
channel_id: channel._id,
|
||||
channelId: channel._id,
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
// チャンネルの視聴者(のタイムライン)に配信
|
||||
watches.forEach(w => {
|
||||
event(w.user_id, 'post', postObj);
|
||||
event(w.userId, 'post', postObj);
|
||||
});
|
||||
}
|
||||
|
||||
// Increment my posts count
|
||||
User.update({ _id: user._id }, {
|
||||
$inc: {
|
||||
posts_count: 1
|
||||
postsCount: 1
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -367,26 +367,26 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
});
|
||||
|
||||
// 自分自身へのリプライでない限りは通知を作成
|
||||
notify(reply.user_id, user._id, 'reply', {
|
||||
post_id: post._id
|
||||
notify(reply.userId, user._id, 'reply', {
|
||||
postId: post._id
|
||||
});
|
||||
|
||||
// Fetch watchers
|
||||
Watching
|
||||
.find({
|
||||
post_id: reply._id,
|
||||
user_id: { $ne: user._id },
|
||||
postId: reply._id,
|
||||
userId: { $ne: user._id },
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
fields: {
|
||||
user_id: true
|
||||
userId: true
|
||||
}
|
||||
})
|
||||
.then(watchers => {
|
||||
watchers.forEach(watcher => {
|
||||
notify(watcher.user_id, user._id, 'reply', {
|
||||
post_id: post._id
|
||||
notify(watcher.userId, user._id, 'reply', {
|
||||
postId: post._id
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -397,33 +397,33 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
// Add mention
|
||||
addMention(reply.user_id, 'reply');
|
||||
addMention(reply.userId, 'reply');
|
||||
}
|
||||
|
||||
// If it is repost
|
||||
if (repost) {
|
||||
// Notify
|
||||
const type = text ? 'quote' : 'repost';
|
||||
notify(repost.user_id, user._id, type, {
|
||||
post_id: post._id
|
||||
notify(repost.userId, user._id, type, {
|
||||
postId: post._id
|
||||
});
|
||||
|
||||
// Fetch watchers
|
||||
Watching
|
||||
.find({
|
||||
post_id: repost._id,
|
||||
user_id: { $ne: user._id },
|
||||
postId: repost._id,
|
||||
userId: { $ne: user._id },
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
fields: {
|
||||
user_id: true
|
||||
userId: true
|
||||
}
|
||||
})
|
||||
.then(watchers => {
|
||||
watchers.forEach(watcher => {
|
||||
notify(watcher.user_id, user._id, type, {
|
||||
post_id: post._id
|
||||
notify(watcher.userId, user._id, type, {
|
||||
postId: post._id
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -436,18 +436,18 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
// If it is quote repost
|
||||
if (text) {
|
||||
// Add mention
|
||||
addMention(repost.user_id, 'quote');
|
||||
addMention(repost.userId, 'quote');
|
||||
} else {
|
||||
// Publish event
|
||||
if (!user._id.equals(repost.user_id)) {
|
||||
event(repost.user_id, 'repost', postObj);
|
||||
if (!user._id.equals(repost.userId)) {
|
||||
event(repost.userId, 'repost', postObj);
|
||||
}
|
||||
}
|
||||
|
||||
// 今までで同じ投稿をRepostしているか
|
||||
const existRepost = await Post.findOne({
|
||||
user_id: user._id,
|
||||
repost_id: repost._id,
|
||||
userId: user._id,
|
||||
repostId: repost._id,
|
||||
_id: {
|
||||
$ne: post._id
|
||||
}
|
||||
|
@ -494,15 +494,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
|||
if (mentionee == null) return;
|
||||
|
||||
// 既に言及されたユーザーに対する返信や引用repostの場合も無視
|
||||
if (reply && reply.user_id.equals(mentionee._id)) return;
|
||||
if (repost && repost.user_id.equals(mentionee._id)) return;
|
||||
if (reply && reply.userId.equals(mentionee._id)) return;
|
||||
if (repost && repost.userId.equals(mentionee._id)) return;
|
||||
|
||||
// Add mention
|
||||
addMention(mentionee._id, 'mention');
|
||||
|
||||
// Create notification
|
||||
notify(mentionee._id, user._id, 'mention', {
|
||||
post_id: post._id
|
||||
postId: post._id
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
|
@ -13,9 +13,9 @@ import Post from '../../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get favoritee
|
||||
const post = await Post.findOne({
|
||||
|
@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// if already favorited
|
||||
const exist = await Favorite.findOne({
|
||||
post_id: post._id,
|
||||
user_id: user._id
|
||||
postId: post._id,
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -38,9 +38,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create favorite
|
||||
await Favorite.insert({
|
||||
created_at: new Date(),
|
||||
post_id: post._id,
|
||||
user_id: user._id
|
||||
createdAt: new Date(),
|
||||
postId: post._id,
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
// Send response
|
||||
|
|
|
@ -13,9 +13,9 @@ import Post from '../../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get favoritee
|
||||
const post = await Post.findOne({
|
||||
|
@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// if already favorited
|
||||
const exist = await Favorite.findOne({
|
||||
post_id: post._id,
|
||||
user_id: user._id
|
||||
postId: post._id,
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
|
|
|
@ -48,7 +48,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (following) {
|
||||
const followingIds = await getFriends(user._id);
|
||||
|
||||
query.user_id = {
|
||||
query.userId = {
|
||||
$in: followingIds
|
||||
};
|
||||
}
|
||||
|
|
|
@ -23,22 +23,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Get votes
|
||||
const votes = await Vote.find({
|
||||
user_id: user._id
|
||||
userId: user._id
|
||||
}, {
|
||||
fields: {
|
||||
_id: false,
|
||||
post_id: true
|
||||
postId: true
|
||||
}
|
||||
});
|
||||
|
||||
const nin = votes && votes.length != 0 ? votes.map(v => v.post_id) : [];
|
||||
const nin = votes && votes.length != 0 ? votes.map(v => v.postId) : [];
|
||||
|
||||
const posts = await Post
|
||||
.find({
|
||||
_id: {
|
||||
$nin: nin
|
||||
},
|
||||
user_id: {
|
||||
userId: {
|
||||
$ne: user._id
|
||||
},
|
||||
poll: {
|
||||
|
|
|
@ -17,9 +17,9 @@ import { publishPostStream } from '../../../event';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get votee
|
||||
const post = await Post.findOne({
|
||||
|
@ -43,8 +43,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// if already voted
|
||||
const exist = await Vote.findOne({
|
||||
post_id: post._id,
|
||||
user_id: user._id
|
||||
postId: post._id,
|
||||
userId: user._id
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create vote
|
||||
await Vote.insert({
|
||||
created_at: new Date(),
|
||||
post_id: post._id,
|
||||
user_id: user._id,
|
||||
createdAt: new Date(),
|
||||
postId: post._id,
|
||||
userId: user._id,
|
||||
choice: choice
|
||||
});
|
||||
|
||||
|
@ -73,27 +73,27 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
publishPostStream(post._id, 'poll_voted');
|
||||
|
||||
// Notify
|
||||
notify(post.user_id, user._id, 'poll_vote', {
|
||||
post_id: post._id,
|
||||
notify(post.userId, user._id, 'poll_vote', {
|
||||
postId: post._id,
|
||||
choice: choice
|
||||
});
|
||||
|
||||
// Fetch watchers
|
||||
Watching
|
||||
.find({
|
||||
post_id: post._id,
|
||||
user_id: { $ne: user._id },
|
||||
postId: post._id,
|
||||
userId: { $ne: user._id },
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
fields: {
|
||||
user_id: true
|
||||
userId: true
|
||||
}
|
||||
})
|
||||
.then(watchers => {
|
||||
watchers.forEach(watcher => {
|
||||
notify(watcher.user_id, user._id, 'poll_vote', {
|
||||
post_id: post._id,
|
||||
notify(watcher.userId, user._id, 'poll_vote', {
|
||||
postId: post._id,
|
||||
choice: choice
|
||||
});
|
||||
});
|
||||
|
|
|
@ -13,9 +13,9 @@ import Reaction, { pack } from '../../models/post-reaction';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
|
@ -41,8 +41,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Issue query
|
||||
const reactions = await Reaction
|
||||
.find({
|
||||
post_id: post._id,
|
||||
deleted_at: { $exists: false }
|
||||
postId: post._id,
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
|
|
|
@ -18,9 +18,9 @@ import { publishPostStream, pushSw } from '../../../event';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get 'reaction' parameter
|
||||
const [reaction, reactionErr] = $(params.reaction).string().or([
|
||||
|
@ -46,15 +46,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
}
|
||||
|
||||
// Myself
|
||||
if (post.user_id.equals(user._id)) {
|
||||
if (post.userId.equals(user._id)) {
|
||||
return rej('cannot react to my post');
|
||||
}
|
||||
|
||||
// if already reacted
|
||||
const exist = await Reaction.findOne({
|
||||
post_id: post._id,
|
||||
user_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
postId: post._id,
|
||||
userId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -63,9 +63,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Create reaction
|
||||
await Reaction.insert({
|
||||
created_at: new Date(),
|
||||
post_id: post._id,
|
||||
user_id: user._id,
|
||||
createdAt: new Date(),
|
||||
postId: post._id,
|
||||
userId: user._id,
|
||||
reaction: reaction
|
||||
});
|
||||
|
||||
|
@ -83,33 +83,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
publishPostStream(post._id, 'reacted');
|
||||
|
||||
// Notify
|
||||
notify(post.user_id, user._id, 'reaction', {
|
||||
post_id: post._id,
|
||||
notify(post.userId, user._id, 'reaction', {
|
||||
postId: post._id,
|
||||
reaction: reaction
|
||||
});
|
||||
|
||||
pushSw(post.user_id, 'reaction', {
|
||||
user: await packUser(user, post.user_id),
|
||||
post: await packPost(post, post.user_id),
|
||||
pushSw(post.userId, 'reaction', {
|
||||
user: await packUser(user, post.userId),
|
||||
post: await packPost(post, post.userId),
|
||||
reaction: reaction
|
||||
});
|
||||
|
||||
// Fetch watchers
|
||||
Watching
|
||||
.find({
|
||||
post_id: post._id,
|
||||
user_id: { $ne: user._id },
|
||||
postId: post._id,
|
||||
userId: { $ne: user._id },
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
}, {
|
||||
fields: {
|
||||
user_id: true
|
||||
userId: true
|
||||
}
|
||||
})
|
||||
.then(watchers => {
|
||||
watchers.forEach(watcher => {
|
||||
notify(watcher.user_id, user._id, 'reaction', {
|
||||
post_id: post._id,
|
||||
notify(watcher.userId, user._id, 'reaction', {
|
||||
postId: post._id,
|
||||
reaction: reaction
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,9 +14,9 @@ import Post from '../../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Fetch unreactee
|
||||
const post = await Post.findOne({
|
||||
|
@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// if already unreacted
|
||||
const exist = await Reaction.findOne({
|
||||
post_id: post._id,
|
||||
user_id: user._id,
|
||||
deleted_at: { $exists: false }
|
||||
postId: post._id,
|
||||
userId: user._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist === null) {
|
||||
|
@ -43,7 +43,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: exist._id
|
||||
}, {
|
||||
$set: {
|
||||
deleted_at: new Date()
|
||||
deletedAt: new Date()
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
|
@ -39,7 +39,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
// Issue query
|
||||
const replies = await Post
|
||||
.find({ reply_id: post._id }, {
|
||||
.find({ replyId: post._id }, {
|
||||
limit: limit,
|
||||
skip: offset,
|
||||
sort: {
|
||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get 'limit' parameter
|
||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||
|
@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
_id: -1
|
||||
};
|
||||
const query = {
|
||||
repost_id: post._id
|
||||
repostId: post._id
|
||||
} as any;
|
||||
if (sinceId) {
|
||||
sort._id = 1;
|
||||
|
|
|
@ -21,13 +21,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
const [text, textError] = $(params.text).optional.string().$;
|
||||
if (textError) return rej('invalid text param');
|
||||
|
||||
// Get 'include_user_ids' parameter
|
||||
const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$;
|
||||
if (includeUserIdsErr) return rej('invalid include_user_ids param');
|
||||
// Get 'include_userIds' parameter
|
||||
const [includeUserIds = [], includeUserIdsErr] = $(params.include_userIds).optional.array('id').$;
|
||||
if (includeUserIdsErr) return rej('invalid include_userIds param');
|
||||
|
||||
// Get 'exclude_user_ids' parameter
|
||||
const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_user_ids).optional.array('id').$;
|
||||
if (excludeUserIdsErr) return rej('invalid exclude_user_ids param');
|
||||
// Get 'exclude_userIds' parameter
|
||||
const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_userIds).optional.array('id').$;
|
||||
if (excludeUserIdsErr) return rej('invalid exclude_userIds param');
|
||||
|
||||
// Get 'include_user_usernames' parameter
|
||||
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
|
||||
|
@ -81,7 +81,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (includeUserUsernames != null) {
|
||||
const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
|
||||
const _user = await User.findOne({
|
||||
username_lower: username.toLowerCase()
|
||||
usernameLower: username.toLowerCase()
|
||||
});
|
||||
return _user ? _user._id : null;
|
||||
}))).filter(id => id != null);
|
||||
|
@ -92,7 +92,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
|||
if (excludeUserUsernames != null) {
|
||||
const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
|
||||
const _user = await User.findOne({
|
||||
username_lower: username.toLowerCase()
|
||||
usernameLower: username.toLowerCase()
|
||||
});
|
||||
return _user ? _user._id : null;
|
||||
}))).filter(id => id != null);
|
||||
|
@ -143,13 +143,13 @@ async function search(
|
|||
|
||||
if (includeUserIds && includeUserIds.length != 0) {
|
||||
push({
|
||||
user_id: {
|
||||
userId: {
|
||||
$in: includeUserIds
|
||||
}
|
||||
});
|
||||
} else if (excludeUserIds && excludeUserIds.length != 0) {
|
||||
push({
|
||||
user_id: {
|
||||
userId: {
|
||||
$nin: excludeUserIds
|
||||
}
|
||||
});
|
||||
|
@ -158,7 +158,7 @@ async function search(
|
|||
if (following != null && me != null) {
|
||||
const ids = await getFriends(me._id, false);
|
||||
push({
|
||||
user_id: following ? {
|
||||
userId: following ? {
|
||||
$in: ids
|
||||
} : {
|
||||
$nin: ids.concat(me._id)
|
||||
|
@ -168,45 +168,45 @@ async function search(
|
|||
|
||||
if (me != null) {
|
||||
const mutes = await Mute.find({
|
||||
muter_id: me._id,
|
||||
deleted_at: { $exists: false }
|
||||
muterId: me._id,
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
const mutedUserIds = mutes.map(m => m.mutee_id);
|
||||
const mutedUserIds = mutes.map(m => m.muteeId);
|
||||
|
||||
switch (mute) {
|
||||
case 'mute_all':
|
||||
push({
|
||||
user_id: {
|
||||
userId: {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
'_reply.user_id': {
|
||||
'_reply.userId': {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
'_repost.user_id': {
|
||||
'_repost.userId': {
|
||||
$nin: mutedUserIds
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'mute_related':
|
||||
push({
|
||||
'_reply.user_id': {
|
||||
'_reply.userId': {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
'_repost.user_id': {
|
||||
'_repost.userId': {
|
||||
$nin: mutedUserIds
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'mute_direct':
|
||||
push({
|
||||
user_id: {
|
||||
userId: {
|
||||
$nin: mutedUserIds
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'direct_only':
|
||||
push({
|
||||
user_id: {
|
||||
userId: {
|
||||
$in: mutedUserIds
|
||||
}
|
||||
});
|
||||
|
@ -214,11 +214,11 @@ async function search(
|
|||
case 'related_only':
|
||||
push({
|
||||
$or: [{
|
||||
'_reply.user_id': {
|
||||
'_reply.userId': {
|
||||
$in: mutedUserIds
|
||||
}
|
||||
}, {
|
||||
'_repost.user_id': {
|
||||
'_repost.userId': {
|
||||
$in: mutedUserIds
|
||||
}
|
||||
}]
|
||||
|
@ -227,15 +227,15 @@ async function search(
|
|||
case 'all_only':
|
||||
push({
|
||||
$or: [{
|
||||
user_id: {
|
||||
userId: {
|
||||
$in: mutedUserIds
|
||||
}
|
||||
}, {
|
||||
'_reply.user_id': {
|
||||
'_reply.userId': {
|
||||
$in: mutedUserIds
|
||||
}
|
||||
}, {
|
||||
'_repost.user_id': {
|
||||
'_repost.userId': {
|
||||
$in: mutedUserIds
|
||||
}
|
||||
}]
|
||||
|
@ -247,7 +247,7 @@ async function search(
|
|||
if (reply != null) {
|
||||
if (reply) {
|
||||
push({
|
||||
reply_id: {
|
||||
replyId: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
|
@ -255,11 +255,11 @@ async function search(
|
|||
} else {
|
||||
push({
|
||||
$or: [{
|
||||
reply_id: {
|
||||
replyId: {
|
||||
$exists: false
|
||||
}
|
||||
}, {
|
||||
reply_id: null
|
||||
replyId: null
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ async function search(
|
|||
if (repost != null) {
|
||||
if (repost) {
|
||||
push({
|
||||
repost_id: {
|
||||
repostId: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
|
@ -276,11 +276,11 @@ async function search(
|
|||
} else {
|
||||
push({
|
||||
$or: [{
|
||||
repost_id: {
|
||||
repostId: {
|
||||
$exists: false
|
||||
}
|
||||
}, {
|
||||
repost_id: null
|
||||
repostId: null
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ async function search(
|
|||
if (media != null) {
|
||||
if (media) {
|
||||
push({
|
||||
media_ids: {
|
||||
mediaIds: {
|
||||
$exists: true,
|
||||
$ne: null
|
||||
}
|
||||
|
@ -297,11 +297,11 @@ async function search(
|
|||
} else {
|
||||
push({
|
||||
$or: [{
|
||||
media_ids: {
|
||||
mediaIds: {
|
||||
$exists: false
|
||||
}
|
||||
}, {
|
||||
media_ids: null
|
||||
mediaIds: null
|
||||
}]
|
||||
});
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ async function search(
|
|||
|
||||
if (sinceDate) {
|
||||
push({
|
||||
created_at: {
|
||||
createdAt: {
|
||||
$gt: new Date(sinceDate)
|
||||
}
|
||||
});
|
||||
|
@ -338,7 +338,7 @@ async function search(
|
|||
|
||||
if (untilDate) {
|
||||
push({
|
||||
created_at: {
|
||||
createdAt: {
|
||||
$lt: new Date(untilDate)
|
||||
}
|
||||
});
|
||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
|||
* @return {Promise<any>}
|
||||
*/
|
||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||
// Get 'post_id' parameter
|
||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
||||
if (postIdErr) return rej('invalid post_id param');
|
||||
// Get 'postId' parameter
|
||||
const [postId, postIdErr] = $(params.postId).id().$;
|
||||
if (postIdErr) return rej('invalid postId param');
|
||||
|
||||
// Get post
|
||||
const post = await Post.findOne({
|
||||
|
|
|
@ -49,17 +49,17 @@ module.exports = async (params, user, app) => {
|
|||
|
||||
// Watchしているチャンネルを取得
|
||||
watchingChannelIds: ChannelWatching.find({
|
||||
user_id: user._id,
|
||||
userId: user._id,
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
}).then(watches => watches.map(w => w.channel_id)),
|
||||
deletedAt: { $exists: false }
|
||||
}).then(watches => watches.map(w => w.channelId)),
|
||||
|
||||
// ミュートしているユーザーを取得
|
||||
mutedUserIds: Mute.find({
|
||||
muter_id: user._id,
|
||||
muterId: user._id,
|
||||
// 削除されたドキュメントは除く
|
||||
deleted_at: { $exists: false }
|
||||
}).then(ms => ms.map(m => m.mutee_id))
|
||||
deletedAt: { $exists: false }
|
||||
}).then(ms => ms.map(m => m.muteeId))
|
||||
});
|
||||
|
||||
//#region Construct query
|
||||
|
@ -70,31 +70,31 @@ module.exports = async (params, user, app) => {
|
|||
const query = {
|
||||
$or: [{
|
||||
// フォローしている人のタイムラインへの投稿
|
||||
user_id: {
|
||||
userId: {
|
||||
$in: followingIds
|
||||
},
|
||||
// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
|
||||
$or: [{
|
||||
channel_id: {
|
||||
channelId: {
|
||||
$exists: false
|
||||
}
|
||||
}, {
|
||||
channel_id: null
|
||||
channelId: null
|
||||
}]
|
||||
}, {
|
||||
// Watchしているチャンネルへの投稿
|
||||
channel_id: {
|
||||
channelId: {
|
||||
$in: watchingChannelIds
|
||||
}
|
||||
}],
|
||||
// mute
|
||||
user_id: {
|
||||
userId: {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
'_reply.user_id': {
|
||||
'_reply.userId': {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
'_repost.user_id': {
|
||||
'_repost.userId': {
|
||||
$nin: mutedUserIds
|
||||
},
|
||||
} as any;
|
||||
|
@ -110,11 +110,11 @@ module.exports = async (params, user, app) => {
|
|||
};
|
||||
} else if (sinceDate) {
|
||||
sort._id = 1;
|
||||
query.created_at = {
|
||||
query.createdAt = {
|
||||
$gt: new Date(sinceDate)
|
||||
};
|
||||
} else if (untilDate) {
|
||||
query.created_at = {
|
||||
query.createdAt = {
|
||||
$lt: new Date(untilDate)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
if (pollErr) return rej('invalid poll param');
|
||||
|
||||
const query = {
|
||||
created_at: {
|
||||
createdAt: {
|
||||
$gte: new Date(Date.now() - ms('1days'))
|
||||
},
|
||||
repost_count: {
|
||||
|
@ -47,15 +47,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
} as any;
|
||||
|
||||
if (reply != undefined) {
|
||||
query.reply_id = reply ? { $exists: true, $ne: null } : null;
|
||||
query.replyId = reply ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (repost != undefined) {
|
||||
query.repost_id = repost ? { $exists: true, $ne: null } : null;
|
||||
query.repostId = repost ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (media != undefined) {
|
||||
query.media_ids = media ? { $exists: true, $ne: null } : null;
|
||||
query.mediaIds = media ? { $exists: true, $ne: null } : null;
|
||||
}
|
||||
|
||||
if (poll != undefined) {
|
||||
|
|
|
@ -15,7 +15,7 @@ import User from '../models/user';
|
|||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* posts_count:
|
||||
* postsCount:
|
||||
* description: count of all posts of misskey
|
||||
* type: number
|
||||
* users_count:
|
||||
|
@ -42,7 +42,7 @@ module.exports = params => new Promise(async (res, rej) => {
|
|||
.count();
|
||||
|
||||
res({
|
||||
posts_count: postsCount,
|
||||
postsCount: postsCount,
|
||||
users_count: usersCount
|
||||
});
|
||||
});
|
||||
|
|
|
@ -28,11 +28,11 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
|||
|
||||
// if already subscribed
|
||||
const exist = await Subscription.findOne({
|
||||
user_id: user._id,
|
||||
userId: user._id,
|
||||
endpoint: endpoint,
|
||||
auth: auth,
|
||||
publickey: publickey,
|
||||
deleted_at: { $exists: false }
|
||||
deletedAt: { $exists: false }
|
||||
});
|
||||
|
||||
if (exist !== null) {
|
||||
|
@ -40,7 +40,7 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
|||
}
|
||||
|
||||
await Subscription.insert({
|
||||
user_id: user._id,
|
||||
userId: user._id,
|
||||
endpoint: endpoint,
|
||||
auth: auth,
|
||||
publickey: publickey
|
||||
|
|
|
@ -20,7 +20,7 @@ module.exports = async (params) => new Promise(async (res, rej) => {
|
|||
const exist = await User
|
||||
.count({
|
||||
host: null,
|
||||
username_lower: username.toLowerCase()
|
||||
usernameLower: username.toLowerCase()
|
||||
}, {
|
||||
limit: 1
|
||||
});
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue