mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-10 08:23:09 +02:00
Merge pull request #1324 from syuilo/#1288-2
snake_case を camelCase にするなどした
This commit is contained in:
commit
46e530ef41
284 changed files with 2210 additions and 1878 deletions
|
@ -55,10 +55,10 @@ export default (req: express.Request) => new Promise<IAuthContext>(async (resolv
|
||||||
}
|
}
|
||||||
|
|
||||||
const app = await App
|
const app = await App
|
||||||
.findOne({ _id: accessToken.app_id });
|
.findOne({ _id: accessToken.appId });
|
||||||
|
|
||||||
const user = await User
|
const user = await User
|
||||||
.findOne({ _id: accessToken.user_id });
|
.findOne({ _id: accessToken.userId });
|
||||||
|
|
||||||
return resolve({
|
return resolve({
|
||||||
app: app,
|
app: app,
|
||||||
|
|
|
@ -208,7 +208,7 @@ class SigninContext extends Context {
|
||||||
if (this.temporaryUser == null) {
|
if (this.temporaryUser == null) {
|
||||||
// Fetch user
|
// Fetch user
|
||||||
const user: IUser = await User.findOne({
|
const user: IUser = await User.findOne({
|
||||||
username_lower: query.toLowerCase(),
|
usernameLower: query.toLowerCase(),
|
||||||
host: null
|
host: null
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
|
@ -297,7 +297,7 @@ class TlContext extends Context {
|
||||||
private async getTl() {
|
private async getTl() {
|
||||||
const tl = await require('../endpoints/posts/timeline')({
|
const tl = await require('../endpoints/posts/timeline')({
|
||||||
limit: 5,
|
limit: 5,
|
||||||
until_id: this.next ? this.next : undefined
|
untilId: this.next ? this.next : undefined
|
||||||
}, this.bot.user);
|
}, this.bot.user);
|
||||||
|
|
||||||
if (tl.length > 0) {
|
if (tl.length > 0) {
|
||||||
|
@ -349,7 +349,7 @@ class NotificationsContext extends Context {
|
||||||
private async getNotifications() {
|
private async getNotifications() {
|
||||||
const notifications = await require('../endpoints/i/notifications')({
|
const notifications = await require('../endpoints/i/notifications')({
|
||||||
limit: 5,
|
limit: 5,
|
||||||
until_id: this.next ? this.next : undefined
|
untilId: this.next ? this.next : undefined
|
||||||
}, this.bot.user);
|
}, this.bot.user);
|
||||||
|
|
||||||
if (notifications.length > 0) {
|
if (notifications.length > 0) {
|
||||||
|
|
|
@ -115,7 +115,7 @@ class LineBot extends BotCore {
|
||||||
actions.push({
|
actions.push({
|
||||||
type: 'uri',
|
type: 'uri',
|
||||||
label: 'Twitterアカウントを見る',
|
label: 'Twitterアカウントを見る',
|
||||||
uri: `https://twitter.com/${user.account.twitter.screen_name}`
|
uri: `https://twitter.com/${user.account.twitter.screenName}`
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ class LineBot extends BotCore {
|
||||||
altText: await super.showUserCommand(q),
|
altText: await super.showUserCommand(q),
|
||||||
template: {
|
template: {
|
||||||
type: 'buttons',
|
type: 'buttons',
|
||||||
thumbnailImageUrl: `${user.avatar_url}?thumbnail&size=1024`,
|
thumbnailImageUrl: `${user.avatarUrl}?thumbnail&size=1024`,
|
||||||
title: `${user.name} (@${acct})`,
|
title: `${user.name} (@${acct})`,
|
||||||
text: user.description || '(no description)',
|
text: user.description || '(no description)',
|
||||||
actions: actions
|
actions: actions
|
||||||
|
@ -142,7 +142,7 @@ class LineBot extends BotCore {
|
||||||
|
|
||||||
public async showUserTimelinePostback(userId: string) {
|
public async showUserTimelinePostback(userId: string) {
|
||||||
const tl = await require('../../endpoints/users/posts')({
|
const tl = await require('../../endpoints/users/posts')({
|
||||||
user_id: userId,
|
userId: userId,
|
||||||
limit: 5
|
limit: 5
|
||||||
}, this.user);
|
}, this.user);
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ module.exports = async (app: express.Application) => {
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
host: null,
|
host: null,
|
||||||
'account.line': {
|
'account.line': {
|
||||||
user_id: sourceId
|
userId: sourceId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ module.exports = async (app: express.Application) => {
|
||||||
User.update(user._id, {
|
User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
'account.line': {
|
'account.line': {
|
||||||
user_id: sourceId
|
userId: sourceId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -194,7 +194,7 @@ module.exports = async (app: express.Application) => {
|
||||||
User.update(user._id, {
|
User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
'account.line': {
|
'account.line': {
|
||||||
user_id: null
|
userId: null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -100,7 +100,7 @@ const addFile = async (
|
||||||
// Check if there is a file with the same hash
|
// Check if there is a file with the same hash
|
||||||
const much = await DriveFile.findOne({
|
const much = await DriveFile.findOne({
|
||||||
md5: hash,
|
md5: hash,
|
||||||
'metadata.user_id': user._id
|
'metadata.userId': user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (much !== null) {
|
if (much !== null) {
|
||||||
|
@ -172,7 +172,7 @@ const addFile = async (
|
||||||
}
|
}
|
||||||
const driveFolder = await DriveFolder.findOne({
|
const driveFolder = await DriveFolder.findOne({
|
||||||
_id: folderId,
|
_id: folderId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
if (!driveFolder) {
|
if (!driveFolder) {
|
||||||
throw 'folder-not-found';
|
throw 'folder-not-found';
|
||||||
|
@ -184,7 +184,7 @@ const addFile = async (
|
||||||
// Calculate drive usage
|
// Calculate drive usage
|
||||||
const usage = await DriveFile
|
const usage = await DriveFile
|
||||||
.aggregate([{
|
.aggregate([{
|
||||||
$match: { 'metadata.user_id': user._id }
|
$match: { 'metadata.userId': user._id }
|
||||||
}, {
|
}, {
|
||||||
$project: {
|
$project: {
|
||||||
length: true
|
length: true
|
||||||
|
@ -205,7 +205,7 @@ const addFile = async (
|
||||||
log(`drive usage is ${usage}`);
|
log(`drive usage is ${usage}`);
|
||||||
|
|
||||||
// If usage limit exceeded
|
// If usage limit exceeded
|
||||||
if (usage + size > user.drive_capacity) {
|
if (usage + size > user.driveCapacity) {
|
||||||
throw 'no-free-space';
|
throw 'no-free-space';
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
@ -221,12 +221,12 @@ const addFile = async (
|
||||||
}
|
}
|
||||||
|
|
||||||
if (averageColor) {
|
if (averageColor) {
|
||||||
properties['average_color'] = averageColor;
|
properties['avgColor'] = averageColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return addToGridFS(detectedName, readable, mime, {
|
return addToGridFS(detectedName, readable, mime, {
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
folder_id: folder !== null ? folder._id : null,
|
folderId: folder !== null ? folder._id : null,
|
||||||
comment: comment,
|
comment: comment,
|
||||||
properties: properties
|
properties: properties
|
||||||
});
|
});
|
||||||
|
@ -297,7 +297,7 @@ export default (user: any, file: string | stream.Readable, ...args) => new Promi
|
||||||
id: file._id.toString(),
|
id: file._id.toString(),
|
||||||
body: {
|
body: {
|
||||||
name: file.name,
|
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
|
// SELECT followee
|
||||||
const myfollowing = await Following
|
const myfollowing = await Following
|
||||||
.find({
|
.find({
|
||||||
follower_id: me,
|
followerId: me,
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
followee_id: true
|
followeeId: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// ID list of other users who the I follows
|
// 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) {
|
if (includeMe) {
|
||||||
myfollowingIds.push(me);
|
myfollowingIds.push(me);
|
||||||
|
|
|
@ -16,11 +16,11 @@ export default (
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
const notification = await Notification.insert(Object.assign({
|
const notification = await Notification.insert(Object.assign({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
notifiee_id: notifiee,
|
notifieeId: notifiee,
|
||||||
notifier_id: notifier,
|
notifierId: notifier,
|
||||||
type: type,
|
type: type,
|
||||||
is_read: false
|
isRead: false
|
||||||
}, content));
|
}, content));
|
||||||
|
|
||||||
resolve(notification);
|
resolve(notification);
|
||||||
|
@ -31,14 +31,14 @@ export default (
|
||||||
|
|
||||||
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
|
// 3秒経っても(今回作成した)通知が既読にならなかったら「未読の通知がありますよ」イベントを発行する
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const fresh = await Notification.findOne({ _id: notification._id }, { is_read: true });
|
const fresh = await Notification.findOne({ _id: notification._id }, { isRead: true });
|
||||||
if (!fresh.is_read) {
|
if (!fresh.isRead) {
|
||||||
//#region ただしミュートしているユーザーからの通知なら無視
|
//#region ただしミュートしているユーザーからの通知なら無視
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
muter_id: notifiee,
|
muterId: notifiee,
|
||||||
deleted_at: { $exists: false }
|
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) {
|
if (mutedUserIds.indexOf(notifier.toString()) != -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
|
||||||
|
|
||||||
// Fetch
|
// Fetch
|
||||||
const subscriptions = await Subscription.find({
|
const subscriptions = await Subscription.find({
|
||||||
user_id: userId
|
userId: userId
|
||||||
});
|
});
|
||||||
|
|
||||||
subscriptions.forEach(subscription => {
|
subscriptions.forEach(subscription => {
|
||||||
|
@ -41,7 +41,7 @@ export default async function(userId: mongo.ObjectID | string, type, body?) {
|
||||||
|
|
||||||
if (err.statusCode == 410) {
|
if (err.statusCode == 410) {
|
||||||
Subscription.remove({
|
Subscription.remove({
|
||||||
user_id: userId,
|
userId: userId,
|
||||||
endpoint: subscription.endpoint,
|
endpoint: subscription.endpoint,
|
||||||
auth: subscription.auth,
|
auth: subscription.auth,
|
||||||
publickey: subscription.publickey
|
publickey: subscription.publickey
|
||||||
|
|
|
@ -37,12 +37,12 @@ export default (
|
||||||
// Update documents
|
// Update documents
|
||||||
await Message.update({
|
await Message.update({
|
||||||
_id: { $in: ids },
|
_id: { $in: ids },
|
||||||
user_id: otherpartyId,
|
userId: otherpartyId,
|
||||||
recipient_id: userId,
|
recipientId: userId,
|
||||||
is_read: false
|
isRead: false
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
is_read: true
|
isRead: true
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
multi: true
|
multi: true
|
||||||
|
@ -55,8 +55,8 @@ export default (
|
||||||
// Calc count of my unread messages
|
// Calc count of my unread messages
|
||||||
const count = await Message
|
const count = await Message
|
||||||
.count({
|
.count({
|
||||||
recipient_id: userId,
|
recipientId: userId,
|
||||||
is_read: false
|
isRead: false
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|
|
@ -29,10 +29,10 @@ export default (
|
||||||
// Update documents
|
// Update documents
|
||||||
await Notification.update({
|
await Notification.update({
|
||||||
_id: { $in: ids },
|
_id: { $in: ids },
|
||||||
is_read: false
|
isRead: false
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
is_read: true
|
isRead: true
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
multi: true
|
multi: true
|
||||||
|
@ -41,8 +41,8 @@ export default (
|
||||||
// Calc count of my unread notifications
|
// Calc count of my unread notifications
|
||||||
const count = await Notification
|
const count = await Notification
|
||||||
.count({
|
.count({
|
||||||
notifiee_id: userId,
|
notifieeId: userId,
|
||||||
is_read: false
|
isRead: false
|
||||||
});
|
});
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
|
|
|
@ -3,15 +3,15 @@ import Watching from '../models/post-watching';
|
||||||
|
|
||||||
export default async (me: mongodb.ObjectID, post: object) => {
|
export default async (me: mongodb.ObjectID, post: object) => {
|
||||||
// 自分の投稿はwatchできない
|
// 自分の投稿はwatchできない
|
||||||
if (me.equals((post as any).user_id)) {
|
if (me.equals((post as any).userId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if watching now
|
// if watching now
|
||||||
const exist = await Watching.findOne({
|
const exist = await Watching.findOne({
|
||||||
post_id: (post as any)._id,
|
postId: (post as any)._id,
|
||||||
user_id: me,
|
userId: me,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -19,8 +19,8 @@ export default async (me: mongodb.ObjectID, post: object) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Watching.insert({
|
await Watching.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
post_id: (post as any)._id,
|
postId: (post as any)._id,
|
||||||
user_id: me
|
userId: me
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -289,7 +289,7 @@ const endpoints: Endpoint[] = [
|
||||||
kind: 'notification-write'
|
kind: 'notification-write'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'notifications/mark_as_read_all',
|
name: 'notifications/markAsRead_all',
|
||||||
withCredential: true,
|
withCredential: true,
|
||||||
kind: 'notification-write'
|
kind: 'notification-write'
|
||||||
},
|
},
|
||||||
|
|
|
@ -18,23 +18,23 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||||
const datas = await Post
|
const datas = await Post
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $project: {
|
{ $project: {
|
||||||
repost_id: '$repost_id',
|
repostId: '$repostId',
|
||||||
reply_id: '$reply_id',
|
replyId: '$replyId',
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
$cond: {
|
$cond: {
|
||||||
if: { $ne: ['$repost_id', null] },
|
if: { $ne: ['$repostId', null] },
|
||||||
then: 'repost',
|
then: 'repost',
|
||||||
else: {
|
else: {
|
||||||
$cond: {
|
$cond: {
|
||||||
if: { $ne: ['$reply_id', null] },
|
if: { $ne: ['$replyId', null] },
|
||||||
then: 'reply',
|
then: 'reply',
|
||||||
else: 'post'
|
else: 'post'
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Lookup post
|
// Lookup post
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -27,15 +27,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const datas = await Reaction
|
const datas = await Reaction
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { post_id: post._id } },
|
{ $match: { postId: post._id } },
|
||||||
{ $project: {
|
{ $project: {
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{ $group: {
|
{ $group: {
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Lookup post
|
// Lookup post
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -29,10 +29,10 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const reactions = await Reaction
|
const reactions = await Reaction
|
||||||
.find({
|
.find({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
$or: [
|
$or: [
|
||||||
{ deleted_at: { $exists: false } },
|
{ deletedAt: { $exists: false } },
|
||||||
{ deleted_at: { $gt: startTime } }
|
{ deletedAt: { $gt: startTime } }
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
sort: {
|
sort: {
|
||||||
|
@ -40,7 +40,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
},
|
},
|
||||||
fields: {
|
fields: {
|
||||||
_id: false,
|
_id: false,
|
||||||
post_id: false
|
postId: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// day = day.getTime();
|
// day = day.getTime();
|
||||||
|
|
||||||
const count = reactions.filter(r =>
|
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;
|
).length;
|
||||||
|
|
||||||
graph.push({
|
graph.push({
|
||||||
|
|
|
@ -11,9 +11,9 @@ import Post from '../../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Lookup post
|
// Lookup post
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -28,13 +28,13 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { reply: post._id } },
|
{ $match: { reply: post._id } },
|
||||||
{ $project: {
|
{ $project: {
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{ $group: {
|
{ $group: {
|
||||||
|
|
|
@ -11,9 +11,9 @@ import Post from '../../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Lookup post
|
// Lookup post
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -26,15 +26,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const datas = await Post
|
const datas = await Post
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { repost_id: post._id } },
|
{ $match: { repostId: post._id } },
|
||||||
{ $project: {
|
{ $project: {
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{ $group: {
|
{ $group: {
|
||||||
|
|
|
@ -22,8 +22,8 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||||
},
|
},
|
||||||
fields: {
|
fields: {
|
||||||
_id: false,
|
_id: false,
|
||||||
created_at: true,
|
createdAt: true,
|
||||||
deleted_at: true
|
deletedAt: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -44,11 +44,11 @@ module.exports = params => new Promise(async (res, rej) => {
|
||||||
// day = day.getTime();
|
// day = day.getTime();
|
||||||
|
|
||||||
const total = users.filter(u =>
|
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;
|
).length;
|
||||||
|
|
||||||
const created = users.filter(u =>
|
const created = users.filter(u =>
|
||||||
u.created_at < dayEnd && u.created_at > dayStart
|
u.createdAt < dayEnd && u.createdAt > dayStart
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
graph.push({
|
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).$;
|
const [limit = 365, limitErr] = $(params.limit).optional.number().range(1, 365).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
|
@ -37,25 +37,25 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const datas = await Post
|
const datas = await Post
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { user_id: user._id } },
|
{ $match: { userId: user._id } },
|
||||||
{ $project: {
|
{ $project: {
|
||||||
repost_id: '$repost_id',
|
repostId: '$repostId',
|
||||||
reply_id: '$reply_id',
|
replyId: '$replyId',
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
$cond: {
|
$cond: {
|
||||||
if: { $ne: ['$repost_id', null] },
|
if: { $ne: ['$repostId', null] },
|
||||||
then: 'repost',
|
then: 'repost',
|
||||||
else: {
|
else: {
|
||||||
$cond: {
|
$cond: {
|
||||||
if: { $ne: ['$reply_id', null] },
|
if: { $ne: ['$replyId', null] },
|
||||||
then: 'reply',
|
then: 'reply',
|
||||||
else: 'post'
|
else: 'post'
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Following from '../../../models/following';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
|
@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const following = await Following
|
const following = await Following
|
||||||
.find({
|
.find({
|
||||||
followee_id: user._id,
|
followeeId: user._id,
|
||||||
$or: [
|
$or: [
|
||||||
{ deleted_at: { $exists: false } },
|
{ deletedAt: { $exists: false } },
|
||||||
{ deleted_at: { $gt: startTime } }
|
{ deletedAt: { $gt: startTime } }
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
_id: false,
|
_id: false,
|
||||||
follower_id: false,
|
followerId: false,
|
||||||
followee_id: false
|
followeeId: false
|
||||||
}, {
|
}, {
|
||||||
sort: { created_at: -1 }
|
sort: { createdAt: -1 }
|
||||||
});
|
});
|
||||||
|
|
||||||
const graph = [];
|
const graph = [];
|
||||||
|
@ -57,7 +57,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// day = day.getTime();
|
// day = day.getTime();
|
||||||
|
|
||||||
const count = following.filter(f =>
|
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;
|
).length;
|
||||||
|
|
||||||
graph.push({
|
graph.push({
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Following from '../../../models/following';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
|
@ -33,17 +33,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const following = await Following
|
const following = await Following
|
||||||
.find({
|
.find({
|
||||||
follower_id: user._id,
|
followerId: user._id,
|
||||||
$or: [
|
$or: [
|
||||||
{ deleted_at: { $exists: false } },
|
{ deletedAt: { $exists: false } },
|
||||||
{ deleted_at: { $gt: startTime } }
|
{ deletedAt: { $gt: startTime } }
|
||||||
]
|
]
|
||||||
}, {
|
}, {
|
||||||
_id: false,
|
_id: false,
|
||||||
follower_id: false,
|
followerId: false,
|
||||||
followee_id: false
|
followeeId: false
|
||||||
}, {
|
}, {
|
||||||
sort: { created_at: -1 }
|
sort: { createdAt: -1 }
|
||||||
});
|
});
|
||||||
|
|
||||||
const graph = [];
|
const graph = [];
|
||||||
|
@ -56,7 +56,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
day = new Date(day.setHours(23));
|
day = new Date(day.setHours(23));
|
||||||
|
|
||||||
const count = following.filter(f =>
|
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;
|
).length;
|
||||||
|
|
||||||
graph.push({
|
graph.push({
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Post from '../../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
|
@ -31,25 +31,25 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const datas = await Post
|
const datas = await Post
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { user_id: user._id } },
|
{ $match: { userId: user._id } },
|
||||||
{ $project: {
|
{ $project: {
|
||||||
repost_id: '$repost_id',
|
repostId: '$repostId',
|
||||||
reply_id: '$reply_id',
|
replyId: '$replyId',
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
},
|
},
|
||||||
type: {
|
type: {
|
||||||
$cond: {
|
$cond: {
|
||||||
if: { $ne: ['$repost_id', null] },
|
if: { $ne: ['$repostId', null] },
|
||||||
then: 'repost',
|
then: 'repost',
|
||||||
else: {
|
else: {
|
||||||
$cond: {
|
$cond: {
|
||||||
if: { $ne: ['$reply_id', null] },
|
if: { $ne: ['$replyId', null] },
|
||||||
then: 'reply',
|
then: 'reply',
|
||||||
else: 'post'
|
else: 'post'
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Reaction from '../../../models/post-reaction';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Lookup user
|
// Lookup user
|
||||||
const user = await User.findOne({
|
const user = await User.findOne({
|
||||||
|
@ -31,15 +31,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
const datas = await Reaction
|
const datas = await Reaction
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { user_id: user._id } },
|
{ $match: { userId: user._id } },
|
||||||
{ $project: {
|
{ $project: {
|
||||||
created_at: { $add: ['$created_at', 9 * 60 * 60 * 1000] } // Convert into JST
|
createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST
|
||||||
}},
|
}},
|
||||||
{ $project: {
|
{ $project: {
|
||||||
date: {
|
date: {
|
||||||
year: { $year: '$created_at' },
|
year: { $year: '$createdAt' },
|
||||||
month: { $month: '$created_at' },
|
month: { $month: '$createdAt' },
|
||||||
day: { $dayOfMonth: '$created_at' }
|
day: { $dayOfMonth: '$createdAt' }
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{ $group: {
|
{ $group: {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import App, { isValidNameId, pack } from '../../models/app';
|
||||||
* parameters:
|
* parameters:
|
||||||
* - $ref: "#/parameters/AccessToken"
|
* - $ref: "#/parameters/AccessToken"
|
||||||
* -
|
* -
|
||||||
* name: name_id
|
* name: nameId
|
||||||
* description: Application unique name
|
* description: Application unique name
|
||||||
* in: formData
|
* in: formData
|
||||||
* required: true
|
* required: true
|
||||||
|
@ -40,7 +40,7 @@ import App, { isValidNameId, pack } from '../../models/app';
|
||||||
* type: string
|
* type: string
|
||||||
* collectionFormat: csv
|
* collectionFormat: csv
|
||||||
* -
|
* -
|
||||||
* name: callback_url
|
* name: callbackUrl
|
||||||
* description: URL called back after authentication
|
* description: URL called back after authentication
|
||||||
* in: formData
|
* in: formData
|
||||||
* required: false
|
* required: false
|
||||||
|
@ -66,9 +66,9 @@ import App, { isValidNameId, pack } from '../../models/app';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'name_id' parameter
|
// Get 'nameId' parameter
|
||||||
const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
|
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
|
||||||
if (nameIdErr) return rej('invalid name_id param');
|
if (nameIdErr) return rej('invalid nameId param');
|
||||||
|
|
||||||
// Get 'name' parameter
|
// Get 'name' parameter
|
||||||
const [name, nameErr] = $(params.name).string().$;
|
const [name, nameErr] = $(params.name).string().$;
|
||||||
|
@ -82,24 +82,24 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
const [permission, permissionErr] = $(params.permission).array('string').unique().$;
|
const [permission, permissionErr] = $(params.permission).array('string').unique().$;
|
||||||
if (permissionErr) return rej('invalid permission param');
|
if (permissionErr) return rej('invalid permission param');
|
||||||
|
|
||||||
// Get 'callback_url' parameter
|
// Get 'callbackUrl' parameter
|
||||||
// TODO: Check it is valid url
|
// TODO: Check it is valid url
|
||||||
const [callbackUrl = null, callbackUrlErr] = $(params.callback_url).optional.nullable.string().$;
|
const [callbackUrl = null, callbackUrlErr] = $(params.callbackUrl).optional.nullable.string().$;
|
||||||
if (callbackUrlErr) return rej('invalid callback_url param');
|
if (callbackUrlErr) return rej('invalid callbackUrl param');
|
||||||
|
|
||||||
// Generate secret
|
// Generate secret
|
||||||
const secret = rndstr('a-zA-Z0-9', 32);
|
const secret = rndstr('a-zA-Z0-9', 32);
|
||||||
|
|
||||||
// Create account
|
// Create account
|
||||||
const app = await App.insert({
|
const app = await App.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
name: name,
|
name: name,
|
||||||
name_id: nameId,
|
nameId: nameId,
|
||||||
name_id_lower: nameId.toLowerCase(),
|
nameIdLower: nameId.toLowerCase(),
|
||||||
description: description,
|
description: description,
|
||||||
permission: permission,
|
permission: permission,
|
||||||
callback_url: callbackUrl,
|
callbackUrl: callbackUrl,
|
||||||
secret: secret
|
secret: secret
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,12 @@ import { isValidNameId } from '../../../models/app';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @swagger
|
* @swagger
|
||||||
* /app/name_id/available:
|
* /app/nameId/available:
|
||||||
* post:
|
* post:
|
||||||
* summary: Check available name_id on creation an application
|
* summary: Check available nameId on creation an application
|
||||||
* parameters:
|
* parameters:
|
||||||
* -
|
* -
|
||||||
* name: name_id
|
* name: nameId
|
||||||
* description: Application unique name
|
* description: Application unique name
|
||||||
* in: formData
|
* in: formData
|
||||||
* required: true
|
* required: true
|
||||||
|
@ -25,7 +25,7 @@ import { isValidNameId } from '../../../models/app';
|
||||||
* type: object
|
* type: object
|
||||||
* properties:
|
* properties:
|
||||||
* available:
|
* available:
|
||||||
* description: Whether name_id is available
|
* description: Whether nameId is available
|
||||||
* type: boolean
|
* type: boolean
|
||||||
*
|
*
|
||||||
* default:
|
* default:
|
||||||
|
@ -35,20 +35,20 @@ import { isValidNameId } from '../../../models/app';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check available name_id of app
|
* Check available nameId of app
|
||||||
*
|
*
|
||||||
* @param {any} params
|
* @param {any} params
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async (params) => new Promise(async (res, rej) => {
|
module.exports = async (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'name_id' parameter
|
// Get 'nameId' parameter
|
||||||
const [nameId, nameIdErr] = $(params.name_id).string().pipe(isValidNameId).$;
|
const [nameId, nameIdErr] = $(params.nameId).string().pipe(isValidNameId).$;
|
||||||
if (nameIdErr) return rej('invalid name_id param');
|
if (nameIdErr) return rej('invalid nameId param');
|
||||||
|
|
||||||
// Get exist
|
// Get exist
|
||||||
const exist = await App
|
const exist = await App
|
||||||
.count({
|
.count({
|
||||||
name_id_lower: nameId.toLowerCase()
|
nameIdLower: nameId.toLowerCase()
|
||||||
}, {
|
}, {
|
||||||
limit: 1
|
limit: 1
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,15 +9,15 @@ import App, { pack } from '../../models/app';
|
||||||
* /app/show:
|
* /app/show:
|
||||||
* post:
|
* post:
|
||||||
* summary: Show an application's information
|
* summary: Show an application's information
|
||||||
* description: Require app_id or name_id
|
* description: Require appId or nameId
|
||||||
* parameters:
|
* parameters:
|
||||||
* -
|
* -
|
||||||
* name: app_id
|
* name: appId
|
||||||
* description: Application ID
|
* description: Application ID
|
||||||
* in: formData
|
* in: formData
|
||||||
* type: string
|
* type: string
|
||||||
* -
|
* -
|
||||||
* name: name_id
|
* name: nameId
|
||||||
* description: Application unique name
|
* description: Application unique name
|
||||||
* in: formData
|
* in: formData
|
||||||
* type: string
|
* type: string
|
||||||
|
@ -44,22 +44,22 @@ import App, { pack } from '../../models/app';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) => {
|
||||||
// Get 'app_id' parameter
|
// Get 'appId' parameter
|
||||||
const [appId, appIdErr] = $(params.app_id).optional.id().$;
|
const [appId, appIdErr] = $(params.appId).optional.id().$;
|
||||||
if (appIdErr) return rej('invalid app_id param');
|
if (appIdErr) return rej('invalid appId param');
|
||||||
|
|
||||||
// Get 'name_id' parameter
|
// Get 'nameId' parameter
|
||||||
const [nameId, nameIdErr] = $(params.name_id).optional.string().$;
|
const [nameId, nameIdErr] = $(params.nameId).optional.string().$;
|
||||||
if (nameIdErr) return rej('invalid name_id param');
|
if (nameIdErr) return rej('invalid nameId param');
|
||||||
|
|
||||||
if (appId === undefined && nameId === undefined) {
|
if (appId === undefined && nameId === undefined) {
|
||||||
return rej('app_id or name_id is required');
|
return rej('appId or nameId is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup app
|
// Lookup app
|
||||||
const app = appId !== undefined
|
const app = appId !== undefined
|
||||||
? await App.findOne({ _id: appId })
|
? await App.findOne({ _id: appId })
|
||||||
: await App.findOne({ name_id_lower: nameId.toLowerCase() });
|
: await App.findOne({ nameIdLower: nameId.toLowerCase() });
|
||||||
|
|
||||||
if (app === null) {
|
if (app === null) {
|
||||||
return rej('app not found');
|
return rej('app not found');
|
||||||
|
@ -67,6 +67,6 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
res(await pack(app, user, {
|
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
|
// Fetch exist access token
|
||||||
const exist = await AccessToken.findOne({
|
const exist = await AccessToken.findOne({
|
||||||
app_id: session.app_id,
|
appId: session.appId,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist === null) {
|
if (exist === null) {
|
||||||
// Lookup app
|
// Lookup app
|
||||||
const app = await App.findOne({
|
const app = await App.findOne({
|
||||||
_id: session.app_id
|
_id: session.appId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Generate Hash
|
// Generate Hash
|
||||||
|
@ -73,9 +73,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Insert access token doc
|
// Insert access token doc
|
||||||
await AccessToken.insert({
|
await AccessToken.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
app_id: session.app_id,
|
appId: session.appId,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
token: accessToken,
|
token: accessToken,
|
||||||
hash: hash
|
hash: hash
|
||||||
});
|
});
|
||||||
|
@ -84,7 +84,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Update session
|
// Update session
|
||||||
await AuthSess.update(session._id, {
|
await AuthSess.update(session._id, {
|
||||||
$set: {
|
$set: {
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import config from '../../../../conf';
|
||||||
* summary: Generate a session
|
* summary: Generate a session
|
||||||
* parameters:
|
* parameters:
|
||||||
* -
|
* -
|
||||||
* name: app_secret
|
* name: appSecret
|
||||||
* description: App Secret
|
* description: App Secret
|
||||||
* in: formData
|
* in: formData
|
||||||
* required: true
|
* required: true
|
||||||
|
@ -45,9 +45,9 @@ import config from '../../../../conf';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'app_secret' parameter
|
// Get 'appSecret' parameter
|
||||||
const [appSecret, appSecretErr] = $(params.app_secret).string().$;
|
const [appSecret, appSecretErr] = $(params.appSecret).string().$;
|
||||||
if (appSecretErr) return rej('invalid app_secret param');
|
if (appSecretErr) return rej('invalid appSecret param');
|
||||||
|
|
||||||
// Lookup app
|
// Lookup app
|
||||||
const app = await App.findOne({
|
const app = await App.findOne({
|
||||||
|
@ -63,8 +63,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create session token document
|
// Create session token document
|
||||||
const doc = await AuthSess.insert({
|
const doc = await AuthSess.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
app_id: app._id,
|
appId: app._id,
|
||||||
token: token
|
token: token
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -23,17 +23,17 @@ import AuthSess, { pack } from '../../../models/auth-session';
|
||||||
* schema:
|
* schema:
|
||||||
* type: object
|
* type: object
|
||||||
* properties:
|
* properties:
|
||||||
* created_at:
|
* createdAt:
|
||||||
* type: string
|
* type: string
|
||||||
* format: date-time
|
* format: date-time
|
||||||
* description: Date and time of the session creation
|
* description: Date and time of the session creation
|
||||||
* app_id:
|
* appId:
|
||||||
* type: string
|
* type: string
|
||||||
* description: Application ID
|
* description: Application ID
|
||||||
* token:
|
* token:
|
||||||
* type: string
|
* type: string
|
||||||
* description: Session Token
|
* description: Session Token
|
||||||
* user_id:
|
* userId:
|
||||||
* type: string
|
* type: string
|
||||||
* description: ID of user who create the session
|
* description: ID of user who create the session
|
||||||
* app:
|
* app:
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { pack } from '../../../models/user';
|
||||||
* summary: Get an access token(userkey)
|
* summary: Get an access token(userkey)
|
||||||
* parameters:
|
* parameters:
|
||||||
* -
|
* -
|
||||||
* name: app_secret
|
* name: appSecret
|
||||||
* description: App Secret
|
* description: App Secret
|
||||||
* in: formData
|
* in: formData
|
||||||
* required: true
|
* required: true
|
||||||
|
@ -50,9 +50,9 @@ import { pack } from '../../../models/user';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params) => new Promise(async (res, rej) => {
|
module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
// Get 'app_secret' parameter
|
// Get 'appSecret' parameter
|
||||||
const [appSecret, appSecretErr] = $(params.app_secret).string().$;
|
const [appSecret, appSecretErr] = $(params.appSecret).string().$;
|
||||||
if (appSecretErr) return rej('invalid app_secret param');
|
if (appSecretErr) return rej('invalid appSecret param');
|
||||||
|
|
||||||
// Lookup app
|
// Lookup app
|
||||||
const app = await App.findOne({
|
const app = await App.findOne({
|
||||||
|
@ -71,21 +71,21 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
const session = await AuthSess
|
const session = await AuthSess
|
||||||
.findOne({
|
.findOne({
|
||||||
token: token,
|
token: token,
|
||||||
app_id: app._id
|
appId: app._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (session === null) {
|
if (session === null) {
|
||||||
return rej('session not found');
|
return rej('session not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.user_id == null) {
|
if (session.userId == null) {
|
||||||
return rej('this session is not allowed yet');
|
return rej('this session is not allowed yet');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup access token
|
// Lookup access token
|
||||||
const accessToken = await AccessToken.findOne({
|
const accessToken = await AccessToken.findOne({
|
||||||
app_id: app._id,
|
appId: app._id,
|
||||||
user_id: session.user_id
|
userId: session.userId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete session
|
// Delete session
|
||||||
|
@ -101,8 +101,8 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Response
|
// Response
|
||||||
res({
|
res({
|
||||||
access_token: accessToken.token,
|
accessToken: accessToken.token,
|
||||||
user: await pack(session.user_id, null, {
|
user: await pack(session.userId, null, {
|
||||||
detail: true
|
detail: true
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
|
@ -16,17 +16,17 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
|
|
@ -20,11 +20,11 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create a channel
|
// Create a channel
|
||||||
const channel = await Channel.insert({
|
const channel = await Channel.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
title: title,
|
title: title,
|
||||||
index: 0,
|
index: 0,
|
||||||
watching_count: 1
|
watchingCount: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
// Response
|
// Response
|
||||||
|
@ -32,8 +32,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create Watching
|
// Create Watching
|
||||||
await Watching.insert({
|
await Watching.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
channel_id: channel._id
|
channelId: channel._id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,22 +17,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [limit = 1000, limitErr] = $(params.limit).optional.number().range(1, 1000).$;
|
const [limit = 1000, limitErr] = $(params.limit).optional.number().range(1, 1000).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'channel_id' parameter
|
// Get 'channelId' parameter
|
||||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||||
if (channelIdErr) return rej('invalid channel_id param');
|
if (channelIdErr) return rej('invalid channelId param');
|
||||||
|
|
||||||
// Fetch channel
|
// Fetch channel
|
||||||
const channel: IChannel = await Channel.findOne({
|
const channel: IChannel = await Channel.findOne({
|
||||||
|
@ -49,7 +49,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
channel_id: channel._id
|
channelId: channel._id
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
if (sinceId) {
|
if (sinceId) {
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Channel, { IChannel, pack } from '../../models/channel';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'channel_id' parameter
|
// Get 'channelId' parameter
|
||||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||||
if (channelIdErr) return rej('invalid channel_id param');
|
if (channelIdErr) return rej('invalid channelId param');
|
||||||
|
|
||||||
// Fetch channel
|
// Fetch channel
|
||||||
const channel: IChannel = await Channel.findOne({
|
const channel: IChannel = await Channel.findOne({
|
||||||
|
|
|
@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'channel_id' parameter
|
// Get 'channelId' parameter
|
||||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||||
if (channelIdErr) return rej('invalid channel_id param');
|
if (channelIdErr) return rej('invalid channelId param');
|
||||||
|
|
||||||
//#region Fetch channel
|
//#region Fetch channel
|
||||||
const channel = await Channel.findOne({
|
const channel = await Channel.findOne({
|
||||||
|
@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
//#region Check whether not watching
|
//#region Check whether not watching
|
||||||
const exist = await Watching.findOne({
|
const exist = await Watching.findOne({
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
channel_id: channel._id,
|
channelId: channel._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist === null) {
|
if (exist === null) {
|
||||||
|
@ -44,7 +44,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: exist._id
|
_id: exist._id
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
deleted_at: new Date()
|
deletedAt: new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Decrement watching count
|
// Decrement watching count
|
||||||
Channel.update(channel._id, {
|
Channel.update(channel._id, {
|
||||||
$inc: {
|
$inc: {
|
||||||
watching_count: -1
|
watchingCount: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,9 +13,9 @@ import Watching from '../../models/channel-watching';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'channel_id' parameter
|
// Get 'channelId' parameter
|
||||||
const [channelId, channelIdErr] = $(params.channel_id).id().$;
|
const [channelId, channelIdErr] = $(params.channelId).id().$;
|
||||||
if (channelIdErr) return rej('invalid channel_id param');
|
if (channelIdErr) return rej('invalid channelId param');
|
||||||
|
|
||||||
//#region Fetch channel
|
//#region Fetch channel
|
||||||
const channel = await Channel.findOne({
|
const channel = await Channel.findOne({
|
||||||
|
@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
//#region Check whether already watching
|
//#region Check whether already watching
|
||||||
const exist = await Watching.findOne({
|
const exist = await Watching.findOne({
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
channel_id: channel._id,
|
channelId: channel._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create Watching
|
// Create Watching
|
||||||
await Watching.insert({
|
await Watching.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
channel_id: channel._id
|
channelId: channel._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
|
@ -52,7 +52,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Increment watching count
|
// Increment watching count
|
||||||
Channel.update(channel._id, {
|
Channel.update(channel._id, {
|
||||||
$inc: {
|
$inc: {
|
||||||
watching_count: 1
|
watchingCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,7 +14,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Calculate drive usage
|
// Calculate drive usage
|
||||||
const usage = ((await DriveFile
|
const usage = ((await DriveFile
|
||||||
.aggregate([
|
.aggregate([
|
||||||
{ $match: { 'metadata.user_id': user._id } },
|
{ $match: { 'metadata.userId': user._id } },
|
||||||
{
|
{
|
||||||
$project: {
|
$project: {
|
||||||
length: true
|
length: true
|
||||||
|
@ -31,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
}).usage;
|
}).usage;
|
||||||
|
|
||||||
res({
|
res({
|
||||||
capacity: user.drive_capacity,
|
capacity: user.driveCapacity,
|
||||||
usage: usage
|
usage: usage
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,22 +17,22 @@ module.exports = async (params, user, app) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) throw 'invalid limit param';
|
if (limitErr) throw 'invalid limit param';
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) throw 'invalid since_id param';
|
if (sinceIdErr) throw 'invalid sinceId param';
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) throw 'invalid until_id param';
|
if (untilIdErr) throw 'invalid untilId param';
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
throw 'cannot set since_id and until_id';
|
throw 'cannot set sinceId and untilId';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||||
if (folderIdErr) throw 'invalid folder_id param';
|
if (folderIdErr) throw 'invalid folderId param';
|
||||||
|
|
||||||
// Get 'type' parameter
|
// Get 'type' parameter
|
||||||
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$;
|
const [type, typeErr] = $(params.type).optional.string().match(/^[a-zA-Z\/\-\*]+$/).$;
|
||||||
|
@ -43,8 +43,8 @@ module.exports = async (params, user, app) => {
|
||||||
_id: -1
|
_id: -1
|
||||||
};
|
};
|
||||||
const query = {
|
const query = {
|
||||||
'metadata.user_id': user._id,
|
'metadata.userId': user._id,
|
||||||
'metadata.folder_id': folderId
|
'metadata.folderId': folderId
|
||||||
} as any;
|
} as any;
|
||||||
if (sinceId) {
|
if (sinceId) {
|
||||||
sort._id = 1;
|
sort._id = 1;
|
||||||
|
|
|
@ -33,9 +33,9 @@ module.exports = async (file, params, user): Promise<any> => {
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||||
if (folderIdErr) throw 'invalid folder_id param';
|
if (folderIdErr) throw 'invalid folderId param';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Create file
|
// Create file
|
||||||
|
|
|
@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [name, nameErr] = $(params.name).string().$;
|
const [name, nameErr] = $(params.name).string().$;
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||||
if (folderIdErr) return rej('invalid folder_id param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
// Issue query
|
// Issue query
|
||||||
const files = await DriveFile
|
const files = await DriveFile
|
||||||
.find({
|
.find({
|
||||||
filename: name,
|
filename: name,
|
||||||
'metadata.user_id': user._id,
|
'metadata.userId': user._id,
|
||||||
'metadata.folder_id': folderId
|
'metadata.folderId': folderId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
|
|
@ -12,15 +12,15 @@ import DriveFile, { pack } from '../../../models/drive-file';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async (params, user) => {
|
module.exports = async (params, user) => {
|
||||||
// Get 'file_id' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $(params.file_id).id().$;
|
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
||||||
if (fileIdErr) throw 'invalid file_id param';
|
if (fileIdErr) throw 'invalid fileId param';
|
||||||
|
|
||||||
// Fetch file
|
// Fetch file
|
||||||
const file = await DriveFile
|
const file = await DriveFile
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: fileId,
|
_id: fileId,
|
||||||
'metadata.user_id': user._id
|
'metadata.userId': user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (file === null) {
|
if (file === null) {
|
||||||
|
|
|
@ -14,15 +14,15 @@ import { publishDriveStream } from '../../../event';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'file_id' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $(params.file_id).id().$;
|
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
||||||
if (fileIdErr) return rej('invalid file_id param');
|
if (fileIdErr) return rej('invalid fileId param');
|
||||||
|
|
||||||
// Fetch file
|
// Fetch file
|
||||||
const file = await DriveFile
|
const file = await DriveFile
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: fileId,
|
_id: fileId,
|
||||||
'metadata.user_id': user._id
|
'metadata.userId': user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (file === null) {
|
if (file === null) {
|
||||||
|
@ -34,33 +34,33 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
if (name) file.filename = name;
|
if (name) file.filename = name;
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||||
if (folderIdErr) return rej('invalid folder_id param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
if (folderId !== undefined) {
|
if (folderId !== undefined) {
|
||||||
if (folderId === null) {
|
if (folderId === null) {
|
||||||
file.metadata.folder_id = null;
|
file.metadata.folderId = null;
|
||||||
} else {
|
} else {
|
||||||
// Fetch folder
|
// Fetch folder
|
||||||
const folder = await DriveFolder
|
const folder = await DriveFolder
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: folderId,
|
_id: folderId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (folder === null) {
|
if (folder === null) {
|
||||||
return rej('folder-not-found');
|
return rej('folder-not-found');
|
||||||
}
|
}
|
||||||
|
|
||||||
file.metadata.folder_id = folder._id;
|
file.metadata.folderId = folder._id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await DriveFile.update(file._id, {
|
await DriveFile.update(file._id, {
|
||||||
$set: {
|
$set: {
|
||||||
filename: file.filename,
|
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().$;
|
const [url, urlErr] = $(params.url).string().$;
|
||||||
if (urlErr) throw 'invalid url param';
|
if (urlErr) throw 'invalid url param';
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||||
if (folderIdErr) throw 'invalid folder_id param';
|
if (folderIdErr) throw 'invalid folderId param';
|
||||||
|
|
||||||
return pack(await uploadFromUrl(url, user, folderId));
|
return pack(await uploadFromUrl(url, user, folderId));
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,30 +17,30 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId = null, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
const [folderId = null, folderIdErr] = $(params.folderId).optional.nullable.id().$;
|
||||||
if (folderIdErr) return rej('invalid folder_id param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
const sort = {
|
const sort = {
|
||||||
_id: -1
|
_id: -1
|
||||||
};
|
};
|
||||||
const query = {
|
const query = {
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
parent_id: folderId
|
parentId: folderId
|
||||||
} as any;
|
} as any;
|
||||||
if (sinceId) {
|
if (sinceId) {
|
||||||
sort._id = 1;
|
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).$;
|
const [name = '無題のフォルダー', nameErr] = $(params.name).optional.string().pipe(isValidFolderName).$;
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'parent_id' parameter
|
// Get 'parentId' parameter
|
||||||
const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||||
if (parentIdErr) return rej('invalid parent_id param');
|
if (parentIdErr) return rej('invalid parentId param');
|
||||||
|
|
||||||
// If the parent folder is specified
|
// If the parent folder is specified
|
||||||
let parent = null;
|
let parent = null;
|
||||||
|
@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
parent = await DriveFolder
|
parent = await DriveFolder
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: parentId,
|
_id: parentId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parent === null) {
|
if (parent === null) {
|
||||||
|
@ -38,10 +38,10 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create folder
|
// Create folder
|
||||||
const folder = await DriveFolder.insert({
|
const folder = await DriveFolder.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
name: name,
|
name: name,
|
||||||
parent_id: parent !== null ? parent._id : null,
|
parentId: parent !== null ? parent._id : null,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
|
|
@ -16,16 +16,16 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [name, nameErr] = $(params.name).string().$;
|
const [name, nameErr] = $(params.name).string().$;
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
|
|
||||||
// Get 'parent_id' parameter
|
// Get 'parentId' parameter
|
||||||
const [parentId = null, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
const [parentId = null, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||||
if (parentIdErr) return rej('invalid parent_id param');
|
if (parentIdErr) return rej('invalid parentId param');
|
||||||
|
|
||||||
// Issue query
|
// Issue query
|
||||||
const folders = await DriveFolder
|
const folders = await DriveFolder
|
||||||
.find({
|
.find({
|
||||||
name: name,
|
name: name,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
parent_id: parentId
|
parentId: parentId
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
|
|
@ -12,15 +12,15 @@ import DriveFolder, { pack } from '../../../models/drive-folder';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId, folderIdErr] = $(params.folder_id).id().$;
|
const [folderId, folderIdErr] = $(params.folderId).id().$;
|
||||||
if (folderIdErr) return rej('invalid folder_id param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
// Get folder
|
// Get folder
|
||||||
const folder = await DriveFolder
|
const folder = await DriveFolder
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: folderId,
|
_id: folderId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (folder === null) {
|
if (folder === null) {
|
||||||
|
|
|
@ -13,15 +13,15 @@ import { publishDriveStream } from '../../../event';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'folder_id' parameter
|
// Get 'folderId' parameter
|
||||||
const [folderId, folderIdErr] = $(params.folder_id).id().$;
|
const [folderId, folderIdErr] = $(params.folderId).id().$;
|
||||||
if (folderIdErr) return rej('invalid folder_id param');
|
if (folderIdErr) return rej('invalid folderId param');
|
||||||
|
|
||||||
// Fetch folder
|
// Fetch folder
|
||||||
const folder = await DriveFolder
|
const folder = await DriveFolder
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: folderId,
|
_id: folderId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (folder === null) {
|
if (folder === null) {
|
||||||
|
@ -33,18 +33,18 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
if (nameErr) return rej('invalid name param');
|
if (nameErr) return rej('invalid name param');
|
||||||
if (name) folder.name = name;
|
if (name) folder.name = name;
|
||||||
|
|
||||||
// Get 'parent_id' parameter
|
// Get 'parentId' parameter
|
||||||
const [parentId, parentIdErr] = $(params.parent_id).optional.nullable.id().$;
|
const [parentId, parentIdErr] = $(params.parentId).optional.nullable.id().$;
|
||||||
if (parentIdErr) return rej('invalid parent_id param');
|
if (parentIdErr) return rej('invalid parentId param');
|
||||||
if (parentId !== undefined) {
|
if (parentId !== undefined) {
|
||||||
if (parentId === null) {
|
if (parentId === null) {
|
||||||
folder.parent_id = null;
|
folder.parentId = null;
|
||||||
} else {
|
} else {
|
||||||
// Get parent folder
|
// Get parent folder
|
||||||
const parent = await DriveFolder
|
const parent = await DriveFolder
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: parentId,
|
_id: parentId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (parent === null) {
|
if (parent === null) {
|
||||||
|
@ -58,25 +58,25 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: folderId
|
_id: folderId
|
||||||
}, {
|
}, {
|
||||||
_id: true,
|
_id: true,
|
||||||
parent_id: true
|
parentId: true
|
||||||
});
|
});
|
||||||
|
|
||||||
if (folder2._id.equals(folder._id)) {
|
if (folder2._id.equals(folder._id)) {
|
||||||
return true;
|
return true;
|
||||||
} else if (folder2.parent_id) {
|
} else if (folder2.parentId) {
|
||||||
return await checkCircle(folder2.parent_id);
|
return await checkCircle(folder2.parentId);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parent.parent_id !== null) {
|
if (parent.parentId !== null) {
|
||||||
if (await checkCircle(parent.parent_id)) {
|
if (await checkCircle(parent.parentId)) {
|
||||||
return rej('detected-circular-definition');
|
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, {
|
DriveFolder.update(folder._id, {
|
||||||
$set: {
|
$set: {
|
||||||
name: folder.name,
|
name: folder.name,
|
||||||
parent_id: folder.parent_id
|
parentId: folder.parentId
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,17 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'type' parameter
|
// Get 'type' parameter
|
||||||
|
@ -38,7 +38,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: -1
|
_id: -1
|
||||||
};
|
};
|
||||||
const query = {
|
const query = {
|
||||||
'metadata.user_id': user._id
|
'metadata.userId': user._id
|
||||||
} as any;
|
} as any;
|
||||||
if (sinceId) {
|
if (sinceId) {
|
||||||
sort._id = 1;
|
sort._id = 1;
|
||||||
|
|
|
@ -17,9 +17,9 @@ import event from '../../event';
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const follower = user;
|
const follower = user;
|
||||||
|
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// 自分自身
|
// 自分自身
|
||||||
if (user._id.equals(userId)) {
|
if (user._id.equals(userId)) {
|
||||||
|
@ -42,9 +42,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Check if already following
|
// Check if already following
|
||||||
const exist = await Following.findOne({
|
const exist = await Following.findOne({
|
||||||
follower_id: follower._id,
|
followerId: follower._id,
|
||||||
followee_id: followee._id,
|
followeeId: followee._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create following
|
// Create following
|
||||||
await Following.insert({
|
await Following.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
follower_id: follower._id,
|
followerId: follower._id,
|
||||||
followee_id: followee._id
|
followeeId: followee._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
|
@ -64,14 +64,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Increment following count
|
// Increment following count
|
||||||
User.update(follower._id, {
|
User.update(follower._id, {
|
||||||
$inc: {
|
$inc: {
|
||||||
following_count: 1
|
followingCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Increment followers count
|
// Increment followers count
|
||||||
User.update({ _id: followee._id }, {
|
User.update({ _id: followee._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
followers_count: 1
|
followersCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@ import event from '../../event';
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const follower = user;
|
const follower = user;
|
||||||
|
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Check if the followee is yourself
|
// Check if the followee is yourself
|
||||||
if (user._id.equals(userId)) {
|
if (user._id.equals(userId)) {
|
||||||
|
@ -41,9 +41,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Check not following
|
// Check not following
|
||||||
const exist = await Following.findOne({
|
const exist = await Following.findOne({
|
||||||
follower_id: follower._id,
|
followerId: follower._id,
|
||||||
followee_id: followee._id,
|
followeeId: followee._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist === null) {
|
if (exist === null) {
|
||||||
|
@ -55,7 +55,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: exist._id
|
_id: exist._id
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
deleted_at: new Date()
|
deletedAt: new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -65,14 +65,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Decrement following count
|
// Decrement following count
|
||||||
User.update({ _id: follower._id }, {
|
User.update({ _id: follower._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
following_count: -1
|
followingCount: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Decrement followers count
|
// Decrement followers count
|
||||||
User.update({ _id: followee._id }, {
|
User.update({ _id: followee._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
followers_count: -1
|
followersCount: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = (params, user, _, isSecure) => new Promise(async (res, rej) =>
|
||||||
// Update lastUsedAt
|
// Update lastUsedAt
|
||||||
User.update({ _id: user._id }, {
|
User.update({ _id: user._id }, {
|
||||||
$set: {
|
$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, '');
|
const _token = token.replace(/\s/g, '');
|
||||||
|
|
||||||
if (user.two_factor_temp_secret == null) {
|
if (user.twoFactorTempSecret == null) {
|
||||||
return rej('二段階認証の設定が開始されていません');
|
return rej('二段階認証の設定が開始されていません');
|
||||||
}
|
}
|
||||||
|
|
||||||
const verified = (speakeasy as any).totp.verify({
|
const verified = (speakeasy as any).totp.verify({
|
||||||
secret: user.two_factor_temp_secret,
|
secret: user.twoFactorTempSecret,
|
||||||
encoding: 'base32',
|
encoding: 'base32',
|
||||||
token: _token
|
token: _token
|
||||||
});
|
});
|
||||||
|
@ -28,8 +28,8 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
'account.two_factor_secret': user.two_factor_temp_secret,
|
'account.twoFactorSecret': user.twoFactorTempSecret,
|
||||||
'account.two_factor_enabled': true
|
'account.twoFactorEnabled': true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$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, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
'account.two_factor_secret': null,
|
'account.twoFactorSecret': null,
|
||||||
'account.two_factor_enabled': false
|
'account.twoFactorEnabled': false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||||
select[`data.${key}`] = true;
|
select[`data.${key}`] = true;
|
||||||
}
|
}
|
||||||
const appdata = await Appdata.findOne({
|
const appdata = await Appdata.findOne({
|
||||||
app_id: app._id,
|
appId: app._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, {
|
}, {
|
||||||
fields: select
|
fields: select
|
||||||
});
|
});
|
||||||
|
|
|
@ -43,11 +43,11 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
await Appdata.update({
|
await Appdata.update({
|
||||||
app_id: app._id,
|
appId: app._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, Object.assign({
|
}, Object.assign({
|
||||||
app_id: app._id,
|
appId: app._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, {
|
}, {
|
||||||
$set: set
|
$set: set
|
||||||
}), {
|
}), {
|
||||||
|
|
|
@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get tokens
|
// Get tokens
|
||||||
const tokens = await AccessToken
|
const tokens = await AccessToken
|
||||||
.find({
|
.find({
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, {
|
}, {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
|
@ -39,5 +39,5 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await Promise.all(tokens.map(async token =>
|
res(await Promise.all(tokens.map(async token =>
|
||||||
await pack(token.app_id))));
|
await pack(token.appId))));
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,13 +13,13 @@ import User from '../../models/user';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'current_password' parameter
|
// Get 'currentPasword' parameter
|
||||||
const [currentPassword, currentPasswordErr] = $(params.current_password).string().$;
|
const [currentPassword, currentPasswordErr] = $(params.currentPasword).string().$;
|
||||||
if (currentPasswordErr) return rej('invalid current_password param');
|
if (currentPasswordErr) return rej('invalid currentPasword param');
|
||||||
|
|
||||||
// Get 'new_password' parameter
|
// Get 'newPassword' parameter
|
||||||
const [newPassword, newPasswordErr] = $(params.new_password).string().$;
|
const [newPassword, newPasswordErr] = $(params.newPassword).string().$;
|
||||||
if (newPasswordErr) return rej('invalid new_password param');
|
if (newPasswordErr) return rej('invalid newPassword param');
|
||||||
|
|
||||||
// Compare password
|
// Compare password
|
||||||
const same = await bcrypt.compare(currentPassword, user.account.password);
|
const same = await bcrypt.compare(currentPassword, user.account.password);
|
||||||
|
|
|
@ -28,7 +28,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get favorites
|
// Get favorites
|
||||||
const favorites = await Favorite
|
const favorites = await Favorite
|
||||||
.find({
|
.find({
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, {
|
}, {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
|
|
|
@ -21,9 +21,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
$(params.following).optional.boolean().$;
|
$(params.following).optional.boolean().$;
|
||||||
if (followingError) return rej('invalid following param');
|
if (followingError) return rej('invalid following param');
|
||||||
|
|
||||||
// Get 'mark_as_read' parameter
|
// Get 'markAsRead' parameter
|
||||||
const [markAsRead = true, markAsReadErr] = $(params.mark_as_read).optional.boolean().$;
|
const [markAsRead = true, markAsReadErr] = $(params.markAsRead).optional.boolean().$;
|
||||||
if (markAsReadErr) return rej('invalid mark_as_read param');
|
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||||
|
|
||||||
// Get 'type' parameter
|
// Get 'type' parameter
|
||||||
const [type, typeErr] = $(params.type).optional.array('string').unique().$;
|
const [type, typeErr] = $(params.type).optional.array('string').unique().$;
|
||||||
|
@ -33,29 +33,29 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
muter_id: user._id,
|
muterId: user._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
notifiee_id: user._id,
|
notifieeId: user._id,
|
||||||
$and: [{
|
$and: [{
|
||||||
notifier_id: {
|
notifierId: {
|
||||||
$nin: mute.map(m => m.mutee_id)
|
$nin: mute.map(m => m.muteeId)
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
} as any;
|
} as any;
|
||||||
|
@ -69,7 +69,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const followingIds = await getFriends(user._id);
|
const followingIds = await getFriends(user._id);
|
||||||
|
|
||||||
query.$and.push({
|
query.$and.push({
|
||||||
notifier_id: {
|
notifierId: {
|
||||||
$in: followingIds
|
$in: followingIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,14 +14,14 @@ import { pack } from '../../models/user';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Fetch pinee
|
// Fetch pinee
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
_id: postId,
|
_id: postId,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (post === null) {
|
if (post === null) {
|
||||||
|
@ -30,7 +30,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
pinned_post_id: post._id
|
pinnedPostId: post._id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,21 +16,21 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
const sort = {
|
const sort = {
|
||||||
|
|
|
@ -36,34 +36,34 @@ module.exports = async (params, user, _, isSecure) => new Promise(async (res, re
|
||||||
if (birthdayErr) return rej('invalid birthday param');
|
if (birthdayErr) return rej('invalid birthday param');
|
||||||
if (birthday !== undefined) user.account.profile.birthday = birthday;
|
if (birthday !== undefined) user.account.profile.birthday = birthday;
|
||||||
|
|
||||||
// Get 'avatar_id' parameter
|
// Get 'avatarId' parameter
|
||||||
const [avatarId, avatarIdErr] = $(params.avatar_id).optional.id().$;
|
const [avatarId, avatarIdErr] = $(params.avatarId).optional.id().$;
|
||||||
if (avatarIdErr) return rej('invalid avatar_id param');
|
if (avatarIdErr) return rej('invalid avatarId param');
|
||||||
if (avatarId) user.avatar_id = avatarId;
|
if (avatarId) user.avatarId = avatarId;
|
||||||
|
|
||||||
// Get 'banner_id' parameter
|
// Get 'bannerId' parameter
|
||||||
const [bannerId, bannerIdErr] = $(params.banner_id).optional.id().$;
|
const [bannerId, bannerIdErr] = $(params.bannerId).optional.id().$;
|
||||||
if (bannerIdErr) return rej('invalid banner_id param');
|
if (bannerIdErr) return rej('invalid bannerId param');
|
||||||
if (bannerId) user.banner_id = bannerId;
|
if (bannerId) user.bannerId = bannerId;
|
||||||
|
|
||||||
// Get 'is_bot' parameter
|
// Get 'isBot' parameter
|
||||||
const [isBot, isBotErr] = $(params.is_bot).optional.boolean().$;
|
const [isBot, isBotErr] = $(params.isBot).optional.boolean().$;
|
||||||
if (isBotErr) return rej('invalid is_bot param');
|
if (isBotErr) return rej('invalid isBot param');
|
||||||
if (isBot != null) user.account.is_bot = isBot;
|
if (isBot != null) user.account.isBot = isBot;
|
||||||
|
|
||||||
// Get 'auto_watch' parameter
|
// Get 'autoWatch' parameter
|
||||||
const [autoWatch, autoWatchErr] = $(params.auto_watch).optional.boolean().$;
|
const [autoWatch, autoWatchErr] = $(params.autoWatch).optional.boolean().$;
|
||||||
if (autoWatchErr) return rej('invalid auto_watch param');
|
if (autoWatchErr) return rej('invalid autoWatch param');
|
||||||
if (autoWatch != null) user.account.settings.auto_watch = autoWatch;
|
if (autoWatch != null) user.account.settings.autoWatch = autoWatch;
|
||||||
|
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$set: {
|
||||||
name: user.name,
|
name: user.name,
|
||||||
description: user.description,
|
description: user.description,
|
||||||
avatar_id: user.avatar_id,
|
avatarId: user.avatarId,
|
||||||
banner_id: user.banner_id,
|
bannerId: user.bannerId,
|
||||||
'account.profile': user.account.profile,
|
'account.profile': user.account.profile,
|
||||||
'account.is_bot': user.account.is_bot,
|
'account.isBot': user.account.isBot,
|
||||||
'account.settings': user.account.settings
|
'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');
|
if (valueErr) return rej('invalid value param');
|
||||||
|
|
||||||
const x = {};
|
const x = {};
|
||||||
x[`account.client_settings.${name}`] = value;
|
x[`account.clientSettings.${name}`] = value;
|
||||||
|
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: x
|
$set: x
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
user.account.client_settings[name] = value;
|
user.account.clientSettings[name] = value;
|
||||||
const iObj = await pack(user, user, {
|
const iObj = await pack(user, user, {
|
||||||
detail: true,
|
detail: true,
|
||||||
includeSecrets: true
|
includeSecrets: true
|
||||||
|
|
|
@ -26,7 +26,7 @@ module.exports = async (params, user) => new Promise(async (res, rej) => {
|
||||||
if (home) {
|
if (home) {
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$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 {
|
} else {
|
||||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
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);
|
const widget = _home.find(w => w.id == id);
|
||||||
|
|
||||||
if (widget == null) return rej('widget not found');
|
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, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$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) {
|
if (home) {
|
||||||
await User.update(user._id, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$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 {
|
} else {
|
||||||
if (id == null && data == null) return rej('you need to set id and data params if home param unset');
|
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);
|
const widget = _home.find(w => w.id == id);
|
||||||
|
|
||||||
if (widget == null) return rej('widget not found');
|
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, {
|
await User.update(user._id, {
|
||||||
$set: {
|
$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');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
muter_id: user._id,
|
muterId: user._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Get history
|
// Get history
|
||||||
const history = await History
|
const history = await History
|
||||||
.find({
|
.find({
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
partner: {
|
partnerId: {
|
||||||
$nin: mute.map(m => m.mutee_id)
|
$nin: mute.map(m => m.muteeId)
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
sort: {
|
sort: {
|
||||||
updated_at: -1
|
updatedAt: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
res(await Promise.all(history.map(async h =>
|
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>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [recipientId, recipientIdErr] = $(params.user_id).id().$;
|
const [recipientId, recipientIdErr] = $(params.userId).id().$;
|
||||||
if (recipientIdErr) return rej('invalid user_id param');
|
if (recipientIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Fetch recipient
|
// Fetch recipient
|
||||||
const recipient = await User.findOne({
|
const recipient = await User.findOne({
|
||||||
|
@ -32,34 +32,34 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
return rej('user not found');
|
return rej('user not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'mark_as_read' parameter
|
// Get 'markAsRead' parameter
|
||||||
const [markAsRead = true, markAsReadErr] = $(params.mark_as_read).optional.boolean().$;
|
const [markAsRead = true, markAsReadErr] = $(params.markAsRead).optional.boolean().$;
|
||||||
if (markAsReadErr) return rej('invalid mark_as_read param');
|
if (markAsReadErr) return rej('invalid markAsRead param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
$or: [{
|
$or: [{
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
recipient_id: recipient._id
|
recipientId: recipient._id
|
||||||
}, {
|
}, {
|
||||||
user_id: recipient._id,
|
userId: recipient._id,
|
||||||
recipient_id: user._id
|
recipientId: user._id
|
||||||
}]
|
}]
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,9 @@ import config from '../../../../conf';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [recipientId, recipientIdErr] = $(params.user_id).id().$;
|
const [recipientId, recipientIdErr] = $(params.userId).id().$;
|
||||||
if (recipientIdErr) return rej('invalid user_id param');
|
if (recipientIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Myself
|
// Myself
|
||||||
if (recipientId.equals(user._id)) {
|
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).$;
|
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
|
||||||
if (textErr) return rej('invalid text');
|
if (textErr) return rej('invalid text');
|
||||||
|
|
||||||
// Get 'file_id' parameter
|
// Get 'fileId' parameter
|
||||||
const [fileId, fileIdErr] = $(params.file_id).optional.id().$;
|
const [fileId, fileIdErr] = $(params.fileId).optional.id().$;
|
||||||
if (fileIdErr) return rej('invalid file_id param');
|
if (fileIdErr) return rej('invalid fileId param');
|
||||||
|
|
||||||
let file = null;
|
let file = null;
|
||||||
if (fileId !== undefined) {
|
if (fileId !== undefined) {
|
||||||
file = await DriveFile.findOne({
|
file = await DriveFile.findOne({
|
||||||
_id: fileId,
|
_id: fileId,
|
||||||
'metadata.user_id': user._id
|
'metadata.userId': user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (file === null) {
|
if (file === null) {
|
||||||
|
@ -70,12 +70,12 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// メッセージを作成
|
// メッセージを作成
|
||||||
const message = await Message.insert({
|
const message = await Message.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
file_id: file ? file._id : undefined,
|
fileId: file ? file._id : undefined,
|
||||||
recipient_id: recipient._id,
|
recipientId: recipient._id,
|
||||||
text: text ? text : undefined,
|
text: text ? text : undefined,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
is_read: false
|
isRead: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
@ -85,32 +85,32 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
res(messageObj);
|
res(messageObj);
|
||||||
|
|
||||||
// 自分のストリーム
|
// 自分のストリーム
|
||||||
publishMessagingStream(message.user_id, message.recipient_id, 'message', messageObj);
|
publishMessagingStream(message.userId, message.recipientId, 'message', messageObj);
|
||||||
publishMessagingIndexStream(message.user_id, 'message', messageObj);
|
publishMessagingIndexStream(message.userId, 'message', messageObj);
|
||||||
publishUserStream(message.user_id, 'messaging_message', messageObj);
|
publishUserStream(message.userId, 'messaging_message', messageObj);
|
||||||
|
|
||||||
// 相手のストリーム
|
// 相手のストリーム
|
||||||
publishMessagingStream(message.recipient_id, message.user_id, 'message', messageObj);
|
publishMessagingStream(message.recipientId, message.userId, 'message', messageObj);
|
||||||
publishMessagingIndexStream(message.recipient_id, 'message', messageObj);
|
publishMessagingIndexStream(message.recipientId, 'message', messageObj);
|
||||||
publishUserStream(message.recipient_id, 'messaging_message', messageObj);
|
publishUserStream(message.recipientId, 'messaging_message', messageObj);
|
||||||
|
|
||||||
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
|
// 3秒経っても(今回作成した)メッセージが既読にならなかったら「未読のメッセージがありますよ」イベントを発行する
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
const freshMessage = await Message.findOne({ _id: message._id }, { is_read: true });
|
const freshMessage = await Message.findOne({ _id: message._id }, { isRead: true });
|
||||||
if (!freshMessage.is_read) {
|
if (!freshMessage.isRead) {
|
||||||
//#region ただしミュートされているなら発行しない
|
//#region ただしミュートされているなら発行しない
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
muter_id: recipient._id,
|
muterId: recipient._id,
|
||||||
deleted_at: { $exists: false }
|
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) {
|
if (mutedUserIds.indexOf(user._id.toString()) != -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
publishUserStream(message.recipient_id, 'unread_messaging_message', messageObj);
|
publishUserStream(message.recipientId, 'unread_messaging_message', messageObj);
|
||||||
pushSw(message.recipient_id, 'unread_messaging_message', messageObj);
|
pushSw(message.recipientId, 'unread_messaging_message', messageObj);
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
|
@ -130,26 +130,26 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// 履歴作成(自分)
|
// 履歴作成(自分)
|
||||||
History.update({
|
History.update({
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
partner: recipient._id
|
partnerId: recipient._id
|
||||||
}, {
|
}, {
|
||||||
updated_at: new Date(),
|
updatedAt: new Date(),
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
partner: recipient._id,
|
partnerId: recipient._id,
|
||||||
message: message._id
|
messageId: message._id
|
||||||
}, {
|
}, {
|
||||||
upsert: true
|
upsert: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// 履歴作成(相手)
|
// 履歴作成(相手)
|
||||||
History.update({
|
History.update({
|
||||||
user_id: recipient._id,
|
userId: recipient._id,
|
||||||
partner: user._id
|
partnerId: user._id
|
||||||
}, {
|
}, {
|
||||||
updated_at: new Date(),
|
updatedAt: new Date(),
|
||||||
user_id: recipient._id,
|
userId: recipient._id,
|
||||||
partner: user._id,
|
partnerId: user._id,
|
||||||
message: message._id
|
messageId: message._id
|
||||||
}, {
|
}, {
|
||||||
upsert: true
|
upsert: true
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,18 +13,18 @@ import Mute from '../../models/mute';
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
muter_id: user._id,
|
muterId: user._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
const mutedUserIds = mute.map(m => m.mutee_id);
|
const mutedUserIds = mute.map(m => m.muteeId);
|
||||||
|
|
||||||
const count = await Message
|
const count = await Message
|
||||||
.count({
|
.count({
|
||||||
user_id: {
|
userId: {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
recipient_id: user._id,
|
recipientId: user._id,
|
||||||
is_read: false
|
isRead: false
|
||||||
});
|
});
|
||||||
|
|
||||||
res({
|
res({
|
||||||
|
|
|
@ -53,7 +53,6 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
model: os.cpus()[0].model,
|
model: os.cpus()[0].model,
|
||||||
cores: os.cpus().length
|
cores: os.cpus().length
|
||||||
},
|
},
|
||||||
top_image: meta.top_image,
|
|
||||||
broadcasts: meta.broadcasts
|
broadcasts: meta.broadcasts
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -15,9 +15,9 @@ import Mute from '../../models/mute';
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const muter = user;
|
const muter = user;
|
||||||
|
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// 自分自身
|
// 自分自身
|
||||||
if (user._id.equals(userId)) {
|
if (user._id.equals(userId)) {
|
||||||
|
@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Check if already muting
|
// Check if already muting
|
||||||
const exist = await Mute.findOne({
|
const exist = await Mute.findOne({
|
||||||
muter_id: muter._id,
|
muterId: muter._id,
|
||||||
mutee_id: mutee._id,
|
muteeId: mutee._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -51,9 +51,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create mute
|
// Create mute
|
||||||
await Mute.insert({
|
await Mute.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
muter_id: muter._id,
|
muterId: muter._id,
|
||||||
mutee_id: mutee._id,
|
muteeId: mutee._id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
|
|
|
@ -15,9 +15,9 @@ import Mute from '../../models/mute';
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const muter = user;
|
const muter = user;
|
||||||
|
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [userId, userIdErr] = $(params.user_id).id().$;
|
const [userId, userIdErr] = $(params.userId).id().$;
|
||||||
if (userIdErr) return rej('invalid user_id param');
|
if (userIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Check if the mutee is yourself
|
// Check if the mutee is yourself
|
||||||
if (user._id.equals(userId)) {
|
if (user._id.equals(userId)) {
|
||||||
|
@ -40,9 +40,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Check not muting
|
// Check not muting
|
||||||
const exist = await Mute.findOne({
|
const exist = await Mute.findOne({
|
||||||
muter_id: muter._id,
|
muterId: muter._id,
|
||||||
mutee_id: mutee._id,
|
muteeId: mutee._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist === null) {
|
if (exist === null) {
|
||||||
|
@ -54,7 +54,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: exist._id
|
_id: exist._id
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
deleted_at: new Date()
|
deletedAt: new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,15 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
const query = {
|
const query = {
|
||||||
muter_id: me._id,
|
muterId: me._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
if (iknow) {
|
if (iknow) {
|
||||||
// Get my friends
|
// Get my friends
|
||||||
const myFriends = await getFriends(me._id);
|
const myFriends = await getFriends(me._id);
|
||||||
|
|
||||||
query.mutee_id = {
|
query.muteeId = {
|
||||||
$in: myFriends
|
$in: myFriends
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
const users = await Promise.all(mutes.map(async m =>
|
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
|
// Response
|
||||||
res({
|
res({
|
||||||
|
|
|
@ -21,7 +21,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
if (offsetErr) return rej('invalid offset param');
|
if (offsetErr) return rej('invalid offset param');
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
};
|
};
|
||||||
|
|
||||||
// Execute query
|
// Execute query
|
||||||
|
|
|
@ -13,18 +13,18 @@ import Mute from '../../models/mute';
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const mute = await Mute.find({
|
const mute = await Mute.find({
|
||||||
muter_id: user._id,
|
muterId: user._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
const mutedUserIds = mute.map(m => m.mutee_id);
|
const mutedUserIds = mute.map(m => m.muteeId);
|
||||||
|
|
||||||
const count = await Notification
|
const count = await Notification
|
||||||
.count({
|
.count({
|
||||||
notifiee_id: user._id,
|
notifieeId: user._id,
|
||||||
notifier_id: {
|
notifierId: {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
is_read: false
|
isRead: false
|
||||||
});
|
});
|
||||||
|
|
||||||
res({
|
res({
|
||||||
|
|
|
@ -14,11 +14,11 @@ import event from '../../event';
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Update documents
|
// Update documents
|
||||||
await Notification.update({
|
await Notification.update({
|
||||||
notifiee_id: user._id,
|
notifieeId: user._id,
|
||||||
is_read: false
|
isRead: false
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
is_read: true
|
isRead: true
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
multi: true
|
multi: true
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import Game, { pack } from '../../models/othello-game';
|
import OthelloGame, { pack } from '../../models/othello-game';
|
||||||
|
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'my' parameter
|
// Get 'my' parameter
|
||||||
|
@ -10,28 +10,28 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
const q: any = my ? {
|
const q: any = my ? {
|
||||||
is_started: true,
|
isStarted: true,
|
||||||
$or: [{
|
$or: [{
|
||||||
user1_id: user._id
|
user1Id: user._id
|
||||||
}, {
|
}, {
|
||||||
user2_id: user._id
|
user2Id: user._id
|
||||||
}]
|
}]
|
||||||
} : {
|
} : {
|
||||||
is_started: true
|
isStarted: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const sort = {
|
const sort = {
|
||||||
|
@ -50,7 +50,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch games
|
// Fetch games
|
||||||
const games = await Game.find(q, {
|
const games = await OthelloGame.find(q, {
|
||||||
sort,
|
sort,
|
||||||
limit
|
limit
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import Game, { pack } from '../../../models/othello-game';
|
import OthelloGame, { pack } from '../../../models/othello-game';
|
||||||
import Othello from '../../../../common/othello/core';
|
import Othello from '../../../../common/othello/core';
|
||||||
|
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'game_id' parameter
|
// Get 'gameId' parameter
|
||||||
const [gameId, gameIdErr] = $(params.game_id).id().$;
|
const [gameId, gameIdErr] = $(params.gameId).id().$;
|
||||||
if (gameIdErr) return rej('invalid game_id param');
|
if (gameIdErr) return rej('invalid gameId param');
|
||||||
|
|
||||||
const game = await Game.findOne({ _id: gameId });
|
const game = await OthelloGame.findOne({ _id: gameId });
|
||||||
|
|
||||||
if (game == null) {
|
if (game == null) {
|
||||||
return rej('game not found');
|
return rej('game not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const o = new Othello(game.settings.map, {
|
const o = new Othello(game.settings.map, {
|
||||||
isLlotheo: game.settings.is_llotheo,
|
isLlotheo: game.settings.isLlotheo,
|
||||||
canPutEverywhere: game.settings.can_put_everywhere,
|
canPutEverywhere: game.settings.canPutEverywhere,
|
||||||
loopedBoard: game.settings.looped_board
|
loopedBoard: game.settings.loopedBoard
|
||||||
});
|
});
|
||||||
|
|
||||||
game.logs.forEach(log => {
|
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) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Find session
|
// Find session
|
||||||
const invitations = await Matching.find({
|
const invitations = await Matching.find({
|
||||||
child_id: user._id
|
childId: user._id
|
||||||
}, {
|
}, {
|
||||||
sort: {
|
sort: {
|
||||||
_id: -1
|
_id: -1
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
import $ from 'cafy';
|
import $ from 'cafy';
|
||||||
import Matching, { pack as packMatching } from '../../models/othello-matching';
|
import Matching, { pack as packMatching } from '../../models/othello-matching';
|
||||||
import Game, { pack as packGame } from '../../models/othello-game';
|
import OthelloGame, { pack as packGame } from '../../models/othello-game';
|
||||||
import User from '../../models/user';
|
import User from '../../models/user';
|
||||||
import publishUserStream, { publishOthelloStream } from '../../event';
|
import publishUserStream, { publishOthelloStream } from '../../event';
|
||||||
import { eighteight } from '../../../common/othello/maps';
|
import { eighteight } from '../../../common/othello/maps';
|
||||||
|
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'user_id' parameter
|
// Get 'userId' parameter
|
||||||
const [childId, childIdErr] = $(params.user_id).id().$;
|
const [childId, childIdErr] = $(params.userId).id().$;
|
||||||
if (childIdErr) return rej('invalid user_id param');
|
if (childIdErr) return rej('invalid userId param');
|
||||||
|
|
||||||
// Myself
|
// Myself
|
||||||
if (childId.equals(user._id)) {
|
if (childId.equals(user._id)) {
|
||||||
return rej('invalid user_id param');
|
return rej('invalid userId param');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find session
|
// Find session
|
||||||
const exist = await Matching.findOne({
|
const exist = await Matching.findOne({
|
||||||
parent_id: childId,
|
parentId: childId,
|
||||||
child_id: user._id
|
childId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist) {
|
if (exist) {
|
||||||
|
@ -28,29 +28,29 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create game
|
// Create game
|
||||||
const game = await Game.insert({
|
const game = await OthelloGame.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
user1_id: exist.parent_id,
|
user1Id: exist.parentId,
|
||||||
user2_id: user._id,
|
user2Id: user._id,
|
||||||
user1_accepted: false,
|
user1Accepted: false,
|
||||||
user2_accepted: false,
|
user2Accepted: false,
|
||||||
is_started: false,
|
isStarted: false,
|
||||||
is_ended: false,
|
isEnded: false,
|
||||||
logs: [],
|
logs: [],
|
||||||
settings: {
|
settings: {
|
||||||
map: eighteight.data,
|
map: eighteight.data,
|
||||||
bw: 'random',
|
bw: 'random',
|
||||||
is_llotheo: false
|
isLlotheo: false
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reponse
|
// Reponse
|
||||||
res(await packGame(game, user));
|
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({
|
const other = await Matching.count({
|
||||||
child_id: user._id
|
childId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (other == 0) {
|
if (other == 0) {
|
||||||
|
@ -72,14 +72,14 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// 以前のセッションはすべて削除しておく
|
// 以前のセッションはすべて削除しておく
|
||||||
await Matching.remove({
|
await Matching.remove({
|
||||||
parent_id: user._id
|
parentId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// セッションを作成
|
// セッションを作成
|
||||||
const matching = await Matching.insert({
|
const matching = await Matching.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
parent_id: user._id,
|
parentId: user._id,
|
||||||
child_id: child._id
|
childId: child._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Reponse
|
// Reponse
|
||||||
|
|
|
@ -2,7 +2,7 @@ import Matching from '../../../models/othello-matching';
|
||||||
|
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
await Matching.remove({
|
await Matching.remove({
|
||||||
parent_id: user._id
|
parentId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
res();
|
res();
|
||||||
|
|
|
@ -35,17 +35,17 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
@ -65,15 +65,15 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reply != undefined) {
|
if (reply != undefined) {
|
||||||
query.reply_id = reply ? { $exists: true, $ne: null } : null;
|
query.replyId = reply ? { $exists: true, $ne: null } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repost != undefined) {
|
if (repost != undefined) {
|
||||||
query.repost_id = repost ? { $exists: true, $ne: null } : null;
|
query.repostId = repost ? { $exists: true, $ne: null } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (media != undefined) {
|
if (media != undefined) {
|
||||||
query.media_ids = media ? { $exists: true, $ne: null } : null;
|
query.mediaIds = media ? { $exists: true, $ne: null } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll != undefined) {
|
if (poll != undefined) {
|
||||||
|
@ -82,7 +82,7 @@ module.exports = (params) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
//if (bot != undefined) {
|
//if (bot != undefined) {
|
||||||
// query.is_bot = bot;
|
// query.isBot = bot;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Issue query
|
// Issue query
|
||||||
|
|
|
@ -12,13 +12,13 @@ import Post from '../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
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');
|
return rej('This endpoint is available only from a Pro account');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get categorizee
|
// Get categorizee
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.reply_id) {
|
if (p.replyId) {
|
||||||
await get(p.reply_id);
|
await get(p.replyId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (post.reply_id) {
|
if (post.replyId) {
|
||||||
await get(post.reply_id);
|
await get(post.replyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize
|
// 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).$;
|
const [text, textErr] = $(params.text).optional.string().pipe(isValidText).$;
|
||||||
if (textErr) return rej('invalid text');
|
if (textErr) return rej('invalid text');
|
||||||
|
|
||||||
// Get 'via_mobile' parameter
|
// Get 'viaMobile' parameter
|
||||||
const [viaMobile = false, viaMobileErr] = $(params.via_mobile).optional.boolean().$;
|
const [viaMobile = false, viaMobileErr] = $(params.viaMobile).optional.boolean().$;
|
||||||
if (viaMobileErr) return rej('invalid via_mobile');
|
if (viaMobileErr) return rej('invalid viaMobile');
|
||||||
|
|
||||||
// Get 'tags' parameter
|
// Get 'tags' parameter
|
||||||
const [tags = [], tagsErr] = $(params.tags).optional.array('string').unique().eachQ(t => t.range(1, 32)).$;
|
const [tags = [], tagsErr] = $(params.tags).optional.array('string').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');
|
if (geoErr) return rej('invalid geo');
|
||||||
|
|
||||||
// Get 'media_ids' parameter
|
// Get 'mediaIds' parameter
|
||||||
const [mediaIds, mediaIdsErr] = $(params.media_ids).optional.array('id').unique().range(1, 4).$;
|
const [mediaIds, mediaIdsErr] = $(params.mediaIds).optional.array('id').unique().range(1, 4).$;
|
||||||
if (mediaIdsErr) return rej('invalid media_ids');
|
if (mediaIdsErr) return rej('invalid mediaIds');
|
||||||
|
|
||||||
let files = [];
|
let files = [];
|
||||||
if (mediaIds !== undefined) {
|
if (mediaIds !== undefined) {
|
||||||
|
@ -67,7 +67,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
// SELECT _id
|
// SELECT _id
|
||||||
const entity = await DriveFile.findOne({
|
const entity = await DriveFile.findOne({
|
||||||
_id: mediaId,
|
_id: mediaId,
|
||||||
'metadata.user_id': user._id
|
'metadata.userId': user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (entity === null) {
|
if (entity === null) {
|
||||||
|
@ -80,9 +80,9 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
files = null;
|
files = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'repost_id' parameter
|
// Get 'repostId' parameter
|
||||||
const [repostId, repostIdErr] = $(params.repost_id).optional.id().$;
|
const [repostId, repostIdErr] = $(params.repostId).optional.id().$;
|
||||||
if (repostIdErr) return rej('invalid repost_id');
|
if (repostIdErr) return rej('invalid repostId');
|
||||||
|
|
||||||
let repost: IPost = null;
|
let repost: IPost = null;
|
||||||
let isQuote = false;
|
let isQuote = false;
|
||||||
|
@ -94,13 +94,13 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
if (repost == null) {
|
if (repost == null) {
|
||||||
return rej('repostee is not found');
|
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');
|
return rej('cannot repost to repost');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch recently post
|
// Fetch recently post
|
||||||
const latestPost = await Post.findOne({
|
const latestPost = await Post.findOne({
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, {
|
}, {
|
||||||
sort: {
|
sort: {
|
||||||
_id: -1
|
_id: -1
|
||||||
|
@ -111,8 +111,8 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// 直近と同じRepost対象かつ引用じゃなかったらエラー
|
// 直近と同じRepost対象かつ引用じゃなかったらエラー
|
||||||
if (latestPost &&
|
if (latestPost &&
|
||||||
latestPost.repost_id &&
|
latestPost.repostId &&
|
||||||
latestPost.repost_id.equals(repost._id) &&
|
latestPost.repostId.equals(repost._id) &&
|
||||||
!isQuote) {
|
!isQuote) {
|
||||||
return rej('cannot repost same post that already reposted in your latest post');
|
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
|
// Get 'replyId' parameter
|
||||||
const [replyId, replyIdErr] = $(params.reply_id).optional.id().$;
|
const [replyId, replyIdErr] = $(params.replyId).optional.id().$;
|
||||||
if (replyIdErr) return rej('invalid reply_id');
|
if (replyIdErr) return rej('invalid replyId');
|
||||||
|
|
||||||
let reply: IPost = null;
|
let reply: IPost = null;
|
||||||
if (replyId !== undefined) {
|
if (replyId !== undefined) {
|
||||||
|
@ -141,14 +141,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返信対象が引用でないRepostだったらエラー
|
// 返信対象が引用でないRepostだったらエラー
|
||||||
if (reply.repost_id && !reply.text && !reply.media_ids) {
|
if (reply.repostId && !reply.text && !reply.mediaIds) {
|
||||||
return rej('cannot reply to repost');
|
return rej('cannot reply to repost');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get 'channel_id' parameter
|
// Get 'channelId' parameter
|
||||||
const [channelId, channelIdErr] = $(params.channel_id).optional.id().$;
|
const [channelId, channelIdErr] = $(params.channelId).optional.id().$;
|
||||||
if (channelIdErr) return rej('invalid channel_id');
|
if (channelIdErr) return rej('invalid channelId');
|
||||||
|
|
||||||
let channel: IChannel = null;
|
let channel: IChannel = null;
|
||||||
if (channelId !== undefined) {
|
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('チャンネル内部からチャンネル外部の投稿に返信することはできません');
|
return rej('チャンネル内部からチャンネル外部の投稿に返信することはできません');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repost対象の投稿がこのチャンネルじゃなかったらダメ
|
// Repost対象の投稿がこのチャンネルじゃなかったらダメ
|
||||||
if (repost && !channelId.equals(repost.channel_id)) {
|
if (repost && !channelId.equals(repost.channelId)) {
|
||||||
return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません');
|
return rej('チャンネル内部からチャンネル外部の投稿をRepostすることはできません');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,12 +177,12 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 返信対象の投稿がチャンネルへの投稿だったらダメ
|
// 返信対象の投稿がチャンネルへの投稿だったらダメ
|
||||||
if (reply && reply.channel_id != null) {
|
if (reply && reply.channelId != null) {
|
||||||
return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
|
return rej('チャンネル外部からチャンネル内部の投稿に返信することはできません');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repost対象の投稿がチャンネルへの投稿だったらダメ
|
// Repost対象の投稿がチャンネルへの投稿だったらダメ
|
||||||
if (repost && repost.channel_id != null) {
|
if (repost && repost.channelId != null) {
|
||||||
return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
|
return rej('チャンネル外部からチャンネル内部の投稿をRepostすることはできません');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,22 +206,22 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
|
// テキストが無いかつ添付ファイルが無いかつRepostも無いかつ投票も無かったらエラー
|
||||||
if (text === undefined && files === null && repost === null && poll === undefined) {
|
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');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 直近の投稿と重複してたらエラー
|
// 直近の投稿と重複してたらエラー
|
||||||
// TODO: 直近の投稿が一日前くらいなら重複とは見なさない
|
// TODO: 直近の投稿が一日前くらいなら重複とは見なさない
|
||||||
if (user.latest_post) {
|
if (user.latestPost) {
|
||||||
if (deepEqual({
|
if (deepEqual({
|
||||||
text: user.latest_post.text,
|
text: user.latestPost.text,
|
||||||
reply: user.latest_post.reply_id ? user.latest_post.reply_id.toString() : null,
|
reply: user.latestPost.replyId ? user.latestPost.replyId.toString() : null,
|
||||||
repost: user.latest_post.repost_id ? user.latest_post.repost_id.toString() : null,
|
repost: user.latestPost.repostId ? user.latestPost.repostId.toString() : null,
|
||||||
media_ids: (user.latest_post.media_ids || []).map(id => id.toString())
|
mediaIds: (user.latestPost.mediaIds || []).map(id => id.toString())
|
||||||
}, {
|
}, {
|
||||||
text: text,
|
text: text,
|
||||||
reply: reply ? reply._id.toString() : null,
|
reply: reply ? reply._id.toString() : null,
|
||||||
repost: repost ? repost._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');
|
return rej('duplicate');
|
||||||
}
|
}
|
||||||
|
@ -246,23 +246,23 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// 投稿を作成
|
// 投稿を作成
|
||||||
const post = await Post.insert({
|
const post = await Post.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
channel_id: channel ? channel._id : undefined,
|
channelId: channel ? channel._id : undefined,
|
||||||
index: channel ? channel.index + 1 : undefined,
|
index: channel ? channel.index + 1 : undefined,
|
||||||
media_ids: files ? files.map(file => file._id) : undefined,
|
mediaIds: files ? files.map(file => file._id) : undefined,
|
||||||
reply_id: reply ? reply._id : undefined,
|
replyId: reply ? reply._id : undefined,
|
||||||
repost_id: repost ? repost._id : undefined,
|
repostId: repost ? repost._id : undefined,
|
||||||
poll: poll,
|
poll: poll,
|
||||||
text: text,
|
text: text,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
app_id: app ? app._id : null,
|
appId: app ? app._id : null,
|
||||||
via_mobile: viaMobile,
|
viaMobile: viaMobile,
|
||||||
geo,
|
geo,
|
||||||
|
|
||||||
// 以下非正規化データ
|
// 以下非正規化データ
|
||||||
_reply: reply ? { user_id: reply.user_id } : undefined,
|
_reply: reply ? { userId: reply.userId } : undefined,
|
||||||
_repost: repost ? { user_id: repost.user_id } : undefined,
|
_repost: repost ? { userId: repost.userId } : undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
@ -270,14 +270,14 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Reponse
|
// Reponse
|
||||||
res({
|
res({
|
||||||
created_post: postObj
|
createdPost: postObj
|
||||||
});
|
});
|
||||||
|
|
||||||
//#region Post processes
|
//#region Post processes
|
||||||
|
|
||||||
User.update({ _id: user._id }, {
|
User.update({ _id: user._id }, {
|
||||||
$set: {
|
$set: {
|
||||||
latest_post: post
|
latestPost: post
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -293,10 +293,10 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
// Publish event
|
// Publish event
|
||||||
if (!user._id.equals(mentionee)) {
|
if (!user._id.equals(mentionee)) {
|
||||||
const mentioneeMutes = await Mute.find({
|
const mentioneeMutes = await Mute.find({
|
||||||
muter_id: mentionee,
|
muterId: mentionee,
|
||||||
deleted_at: { $exists: false }
|
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) {
|
if (mentioneesMutedUserIds.indexOf(user._id.toString()) == -1) {
|
||||||
event(mentionee, reason, postObj);
|
event(mentionee, reason, postObj);
|
||||||
pushSw(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
|
// Fetch all followers
|
||||||
const followers = await Following
|
const followers = await Following
|
||||||
.find({
|
.find({
|
||||||
followee_id: user._id,
|
followeeId: user._id,
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
follower_id: true,
|
followerId: true,
|
||||||
_id: false
|
_id: false
|
||||||
});
|
});
|
||||||
|
|
||||||
// Publish event to followers stream
|
// Publish event to followers stream
|
||||||
followers.forEach(following =>
|
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
|
// Get channel watchers
|
||||||
const watches = await ChannelWatching.find({
|
const watches = await ChannelWatching.find({
|
||||||
channel_id: channel._id,
|
channelId: channel._id,
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
// チャンネルの視聴者(のタイムライン)に配信
|
// チャンネルの視聴者(のタイムライン)に配信
|
||||||
watches.forEach(w => {
|
watches.forEach(w => {
|
||||||
event(w.user_id, 'post', postObj);
|
event(w.userId, 'post', postObj);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment my posts count
|
// Increment my posts count
|
||||||
User.update({ _id: user._id }, {
|
User.update({ _id: user._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
posts_count: 1
|
postsCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -362,68 +362,68 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
// Increment replies count
|
// Increment replies count
|
||||||
Post.update({ _id: reply._id }, {
|
Post.update({ _id: reply._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
replies_count: 1
|
repliesCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 自分自身へのリプライでない限りは通知を作成
|
// 自分自身へのリプライでない限りは通知を作成
|
||||||
notify(reply.user_id, user._id, 'reply', {
|
notify(reply.userId, user._id, 'reply', {
|
||||||
post_id: post._id
|
postId: post._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch watchers
|
// Fetch watchers
|
||||||
Watching
|
Watching
|
||||||
.find({
|
.find({
|
||||||
post_id: reply._id,
|
postId: reply._id,
|
||||||
user_id: { $ne: user._id },
|
userId: { $ne: user._id },
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
user_id: true
|
userId: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(watchers => {
|
.then(watchers => {
|
||||||
watchers.forEach(watcher => {
|
watchers.forEach(watcher => {
|
||||||
notify(watcher.user_id, user._id, 'reply', {
|
notify(watcher.userId, user._id, 'reply', {
|
||||||
post_id: post._id
|
postId: post._id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// この投稿をWatchする
|
// この投稿をWatchする
|
||||||
if ((user.account as ILocalAccount).settings.auto_watch !== false) {
|
if ((user.account as ILocalAccount).settings.autoWatch !== false) {
|
||||||
watch(user._id, reply);
|
watch(user._id, reply);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add mention
|
// Add mention
|
||||||
addMention(reply.user_id, 'reply');
|
addMention(reply.userId, 'reply');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it is repost
|
// If it is repost
|
||||||
if (repost) {
|
if (repost) {
|
||||||
// Notify
|
// Notify
|
||||||
const type = text ? 'quote' : 'repost';
|
const type = text ? 'quote' : 'repost';
|
||||||
notify(repost.user_id, user._id, type, {
|
notify(repost.userId, user._id, type, {
|
||||||
post_id: post._id
|
postId: post._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch watchers
|
// Fetch watchers
|
||||||
Watching
|
Watching
|
||||||
.find({
|
.find({
|
||||||
post_id: repost._id,
|
postId: repost._id,
|
||||||
user_id: { $ne: user._id },
|
userId: { $ne: user._id },
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
user_id: true
|
userId: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(watchers => {
|
.then(watchers => {
|
||||||
watchers.forEach(watcher => {
|
watchers.forEach(watcher => {
|
||||||
notify(watcher.user_id, user._id, type, {
|
notify(watcher.userId, user._id, type, {
|
||||||
post_id: post._id
|
postId: post._id
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -436,18 +436,18 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
// If it is quote repost
|
// If it is quote repost
|
||||||
if (text) {
|
if (text) {
|
||||||
// Add mention
|
// Add mention
|
||||||
addMention(repost.user_id, 'quote');
|
addMention(repost.userId, 'quote');
|
||||||
} else {
|
} else {
|
||||||
// Publish event
|
// Publish event
|
||||||
if (!user._id.equals(repost.user_id)) {
|
if (!user._id.equals(repost.userId)) {
|
||||||
event(repost.user_id, 'repost', postObj);
|
event(repost.userId, 'repost', postObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 今までで同じ投稿をRepostしているか
|
// 今までで同じ投稿をRepostしているか
|
||||||
const existRepost = await Post.findOne({
|
const existRepost = await Post.findOne({
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
repost_id: repost._id,
|
repostId: repost._id,
|
||||||
_id: {
|
_id: {
|
||||||
$ne: post._id
|
$ne: post._id
|
||||||
}
|
}
|
||||||
|
@ -457,7 +457,7 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
// Update repostee status
|
// Update repostee status
|
||||||
Post.update({ _id: repost._id }, {
|
Post.update({ _id: repost._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
repost_count: 1
|
repostCount: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -494,15 +494,15 @@ module.exports = (params, user: IUser, app) => new Promise(async (res, rej) => {
|
||||||
if (mentionee == null) return;
|
if (mentionee == null) return;
|
||||||
|
|
||||||
// 既に言及されたユーザーに対する返信や引用repostの場合も無視
|
// 既に言及されたユーザーに対する返信や引用repostの場合も無視
|
||||||
if (reply && reply.user_id.equals(mentionee._id)) return;
|
if (reply && reply.userId.equals(mentionee._id)) return;
|
||||||
if (repost && repost.user_id.equals(mentionee._id)) return;
|
if (repost && repost.userId.equals(mentionee._id)) return;
|
||||||
|
|
||||||
// Add mention
|
// Add mention
|
||||||
addMention(mentionee._id, 'mention');
|
addMention(mentionee._id, 'mention');
|
||||||
|
|
||||||
// Create notification
|
// Create notification
|
||||||
notify(mentionee._id, user._id, 'mention', {
|
notify(mentionee._id, user._id, 'mention', {
|
||||||
post_id: post._id
|
postId: post._id
|
||||||
});
|
});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -13,9 +13,9 @@ import Post from '../../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get favoritee
|
// Get favoritee
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// if already favorited
|
// if already favorited
|
||||||
const exist = await Favorite.findOne({
|
const exist = await Favorite.findOne({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -38,9 +38,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create favorite
|
// Create favorite
|
||||||
await Favorite.insert({
|
await Favorite.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Send response
|
// Send response
|
||||||
|
|
|
@ -13,9 +13,9 @@ import Post from '../../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get favoritee
|
// Get favoritee
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -28,8 +28,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// if already favorited
|
// if already favorited
|
||||||
const exist = await Favorite.findOne({
|
const exist = await Favorite.findOne({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist === null) {
|
if (exist === null) {
|
||||||
|
|
|
@ -23,17 +23,17 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct query
|
// Construct query
|
||||||
|
@ -48,7 +48,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
if (following) {
|
if (following) {
|
||||||
const followingIds = await getFriends(user._id);
|
const followingIds = await getFriends(user._id);
|
||||||
|
|
||||||
query.user_id = {
|
query.userId = {
|
||||||
$in: followingIds
|
$in: followingIds
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,22 +23,22 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Get votes
|
// Get votes
|
||||||
const votes = await Vote.find({
|
const votes = await Vote.find({
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
_id: false,
|
_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
|
const posts = await Post
|
||||||
.find({
|
.find({
|
||||||
_id: {
|
_id: {
|
||||||
$nin: nin
|
$nin: nin
|
||||||
},
|
},
|
||||||
user_id: {
|
userId: {
|
||||||
$ne: user._id
|
$ne: user._id
|
||||||
},
|
},
|
||||||
poll: {
|
poll: {
|
||||||
|
|
|
@ -17,9 +17,9 @@ import { publishPostStream } from '../../../event';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get votee
|
// Get votee
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -43,8 +43,8 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// if already voted
|
// if already voted
|
||||||
const exist = await Vote.findOne({
|
const exist = await Vote.findOne({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id
|
userId: user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -53,9 +53,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create vote
|
// Create vote
|
||||||
await Vote.insert({
|
await Vote.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
choice: choice
|
choice: choice
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -73,34 +73,34 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
publishPostStream(post._id, 'poll_voted');
|
publishPostStream(post._id, 'poll_voted');
|
||||||
|
|
||||||
// Notify
|
// Notify
|
||||||
notify(post.user_id, user._id, 'poll_vote', {
|
notify(post.userId, user._id, 'poll_vote', {
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
choice: choice
|
choice: choice
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch watchers
|
// Fetch watchers
|
||||||
Watching
|
Watching
|
||||||
.find({
|
.find({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: { $ne: user._id },
|
userId: { $ne: user._id },
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
user_id: true
|
userId: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(watchers => {
|
.then(watchers => {
|
||||||
watchers.forEach(watcher => {
|
watchers.forEach(watcher => {
|
||||||
notify(watcher.user_id, user._id, 'poll_vote', {
|
notify(watcher.userId, user._id, 'poll_vote', {
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
choice: choice
|
choice: choice
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// この投稿をWatchする
|
// この投稿をWatchする
|
||||||
if (user.account.settings.auto_watch !== false) {
|
if (user.account.settings.autoWatch !== false) {
|
||||||
watch(user._id, post);
|
watch(user._id, post);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -13,9 +13,9 @@ import Reaction, { pack } from '../../models/post-reaction';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
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
|
// Issue query
|
||||||
const reactions = await Reaction
|
const reactions = await Reaction
|
||||||
.find({
|
.find({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
|
|
|
@ -18,9 +18,9 @@ import { publishPostStream, pushSw } from '../../../event';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get 'reaction' parameter
|
// Get 'reaction' parameter
|
||||||
const [reaction, reactionErr] = $(params.reaction).string().or([
|
const [reaction, reactionErr] = $(params.reaction).string().or([
|
||||||
|
@ -46,15 +46,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Myself
|
// Myself
|
||||||
if (post.user_id.equals(user._id)) {
|
if (post.userId.equals(user._id)) {
|
||||||
return rej('cannot react to my post');
|
return rej('cannot react to my post');
|
||||||
}
|
}
|
||||||
|
|
||||||
// if already reacted
|
// if already reacted
|
||||||
const exist = await Reaction.findOne({
|
const exist = await Reaction.findOne({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist !== null) {
|
if (exist !== null) {
|
||||||
|
@ -63,9 +63,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// Create reaction
|
// Create reaction
|
||||||
await Reaction.insert({
|
await Reaction.insert({
|
||||||
created_at: new Date(),
|
createdAt: new Date(),
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
reaction: reaction
|
reaction: reaction
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
res();
|
res();
|
||||||
|
|
||||||
const inc = {};
|
const inc = {};
|
||||||
inc[`reaction_counts.${reaction}`] = 1;
|
inc[`reactionCounts.${reaction}`] = 1;
|
||||||
|
|
||||||
// Increment reactions count
|
// Increment reactions count
|
||||||
await Post.update({ _id: post._id }, {
|
await Post.update({ _id: post._id }, {
|
||||||
|
@ -83,40 +83,40 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
publishPostStream(post._id, 'reacted');
|
publishPostStream(post._id, 'reacted');
|
||||||
|
|
||||||
// Notify
|
// Notify
|
||||||
notify(post.user_id, user._id, 'reaction', {
|
notify(post.userId, user._id, 'reaction', {
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
reaction: reaction
|
reaction: reaction
|
||||||
});
|
});
|
||||||
|
|
||||||
pushSw(post.user_id, 'reaction', {
|
pushSw(post.userId, 'reaction', {
|
||||||
user: await packUser(user, post.user_id),
|
user: await packUser(user, post.userId),
|
||||||
post: await packPost(post, post.user_id),
|
post: await packPost(post, post.userId),
|
||||||
reaction: reaction
|
reaction: reaction
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch watchers
|
// Fetch watchers
|
||||||
Watching
|
Watching
|
||||||
.find({
|
.find({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: { $ne: user._id },
|
userId: { $ne: user._id },
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}, {
|
}, {
|
||||||
fields: {
|
fields: {
|
||||||
user_id: true
|
userId: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(watchers => {
|
.then(watchers => {
|
||||||
watchers.forEach(watcher => {
|
watchers.forEach(watcher => {
|
||||||
notify(watcher.user_id, user._id, 'reaction', {
|
notify(watcher.userId, user._id, 'reaction', {
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
reaction: reaction
|
reaction: reaction
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// この投稿をWatchする
|
// この投稿をWatchする
|
||||||
if (user.account.settings.auto_watch !== false) {
|
if (user.account.settings.autoWatch !== false) {
|
||||||
watch(user._id, post);
|
watch(user._id, post);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,9 +14,9 @@ import Post from '../../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Fetch unreactee
|
// Fetch unreactee
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
@ -29,9 +29,9 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
|
|
||||||
// if already unreacted
|
// if already unreacted
|
||||||
const exist = await Reaction.findOne({
|
const exist = await Reaction.findOne({
|
||||||
post_id: post._id,
|
postId: post._id,
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (exist === null) {
|
if (exist === null) {
|
||||||
|
@ -43,7 +43,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: exist._id
|
_id: exist._id
|
||||||
}, {
|
}, {
|
||||||
$set: {
|
$set: {
|
||||||
deleted_at: new Date()
|
deletedAt: new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
res();
|
res();
|
||||||
|
|
||||||
const dec = {};
|
const dec = {};
|
||||||
dec[`reaction_counts.${exist.reaction}`] = -1;
|
dec[`reactionCounts.${exist.reaction}`] = -1;
|
||||||
|
|
||||||
// Decrement reactions count
|
// Decrement reactions count
|
||||||
Post.update({ _id: post._id }, {
|
Post.update({ _id: post._id }, {
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
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
|
// Issue query
|
||||||
const replies = await Post
|
const replies = await Post
|
||||||
.find({ reply_id: post._id }, {
|
.find({ replyId: post._id }, {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
sort: {
|
sort: {
|
||||||
|
|
|
@ -12,25 +12,25 @@ import Post, { pack } from '../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get 'limit' parameter
|
// Get 'limit' parameter
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) return rej('invalid limit param');
|
if (limitErr) return rej('invalid limit param');
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) return rej('invalid since_id param');
|
if (sinceIdErr) return rej('invalid sinceId param');
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) return rej('invalid until_id param');
|
if (untilIdErr) return rej('invalid untilId param');
|
||||||
|
|
||||||
// Check if both of since_id and until_id is specified
|
// Check if both of sinceId and untilId is specified
|
||||||
if (sinceId && untilId) {
|
if (sinceId && untilId) {
|
||||||
return rej('cannot set since_id and until_id');
|
return rej('cannot set sinceId and untilId');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup post
|
// Lookup post
|
||||||
|
@ -47,7 +47,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
_id: -1
|
_id: -1
|
||||||
};
|
};
|
||||||
const query = {
|
const query = {
|
||||||
repost_id: post._id
|
repostId: post._id
|
||||||
} as any;
|
} as any;
|
||||||
if (sinceId) {
|
if (sinceId) {
|
||||||
sort._id = 1;
|
sort._id = 1;
|
||||||
|
|
|
@ -21,21 +21,21 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
const [text, textError] = $(params.text).optional.string().$;
|
const [text, textError] = $(params.text).optional.string().$;
|
||||||
if (textError) return rej('invalid text param');
|
if (textError) return rej('invalid text param');
|
||||||
|
|
||||||
// Get 'include_user_ids' parameter
|
// Get 'includeUserIds' parameter
|
||||||
const [includeUserIds = [], includeUserIdsErr] = $(params.include_user_ids).optional.array('id').$;
|
const [includeUserIds = [], includeUserIdsErr] = $(params.includeUserIds).optional.array('id').$;
|
||||||
if (includeUserIdsErr) return rej('invalid include_user_ids param');
|
if (includeUserIdsErr) return rej('invalid includeUserIds param');
|
||||||
|
|
||||||
// Get 'exclude_user_ids' parameter
|
// Get 'excludeUserIds' parameter
|
||||||
const [excludeUserIds = [], excludeUserIdsErr] = $(params.exclude_user_ids).optional.array('id').$;
|
const [excludeUserIds = [], excludeUserIdsErr] = $(params.excludeUserIds).optional.array('id').$;
|
||||||
if (excludeUserIdsErr) return rej('invalid exclude_user_ids param');
|
if (excludeUserIdsErr) return rej('invalid excludeUserIds param');
|
||||||
|
|
||||||
// Get 'include_user_usernames' parameter
|
// Get 'includeUserUsernames' parameter
|
||||||
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.include_user_usernames).optional.array('string').$;
|
const [includeUserUsernames = [], includeUserUsernamesErr] = $(params.includeUserUsernames).optional.array('string').$;
|
||||||
if (includeUserUsernamesErr) return rej('invalid include_user_usernames param');
|
if (includeUserUsernamesErr) return rej('invalid includeUserUsernames param');
|
||||||
|
|
||||||
// Get 'exclude_user_usernames' parameter
|
// Get 'excludeUserUsernames' parameter
|
||||||
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.exclude_user_usernames).optional.array('string').$;
|
const [excludeUserUsernames = [], excludeUserUsernamesErr] = $(params.excludeUserUsernames).optional.array('string').$;
|
||||||
if (excludeUserUsernamesErr) return rej('invalid exclude_user_usernames param');
|
if (excludeUserUsernamesErr) return rej('invalid excludeUserUsernames param');
|
||||||
|
|
||||||
// Get 'following' parameter
|
// Get 'following' parameter
|
||||||
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
|
const [following = null, followingErr] = $(params.following).optional.nullable.boolean().$;
|
||||||
|
@ -61,13 +61,13 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
const [poll = null, pollErr] = $(params.poll).optional.nullable.boolean().$;
|
const [poll = null, pollErr] = $(params.poll).optional.nullable.boolean().$;
|
||||||
if (pollErr) return rej('invalid poll param');
|
if (pollErr) return rej('invalid poll param');
|
||||||
|
|
||||||
// Get 'since_date' parameter
|
// Get 'sinceDate' parameter
|
||||||
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
|
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().$;
|
||||||
if (sinceDateErr) throw 'invalid since_date param';
|
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||||
|
|
||||||
// Get 'until_date' parameter
|
// Get 'untilDate' parameter
|
||||||
const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
|
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().$;
|
||||||
if (untilDateErr) throw 'invalid until_date param';
|
if (untilDateErr) throw 'invalid untilDate param';
|
||||||
|
|
||||||
// Get 'offset' parameter
|
// Get 'offset' parameter
|
||||||
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
|
const [offset = 0, offsetErr] = $(params.offset).optional.number().min(0).$;
|
||||||
|
@ -81,7 +81,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
if (includeUserUsernames != null) {
|
if (includeUserUsernames != null) {
|
||||||
const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
|
const ids = (await Promise.all(includeUserUsernames.map(async (username) => {
|
||||||
const _user = await User.findOne({
|
const _user = await User.findOne({
|
||||||
username_lower: username.toLowerCase()
|
usernameLower: username.toLowerCase()
|
||||||
});
|
});
|
||||||
return _user ? _user._id : null;
|
return _user ? _user._id : null;
|
||||||
}))).filter(id => id != null);
|
}))).filter(id => id != null);
|
||||||
|
@ -92,7 +92,7 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
|
||||||
if (excludeUserUsernames != null) {
|
if (excludeUserUsernames != null) {
|
||||||
const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
|
const ids = (await Promise.all(excludeUserUsernames.map(async (username) => {
|
||||||
const _user = await User.findOne({
|
const _user = await User.findOne({
|
||||||
username_lower: username.toLowerCase()
|
usernameLower: username.toLowerCase()
|
||||||
});
|
});
|
||||||
return _user ? _user._id : null;
|
return _user ? _user._id : null;
|
||||||
}))).filter(id => id != null);
|
}))).filter(id => id != null);
|
||||||
|
@ -143,13 +143,13 @@ async function search(
|
||||||
|
|
||||||
if (includeUserIds && includeUserIds.length != 0) {
|
if (includeUserIds && includeUserIds.length != 0) {
|
||||||
push({
|
push({
|
||||||
user_id: {
|
userId: {
|
||||||
$in: includeUserIds
|
$in: includeUserIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (excludeUserIds && excludeUserIds.length != 0) {
|
} else if (excludeUserIds && excludeUserIds.length != 0) {
|
||||||
push({
|
push({
|
||||||
user_id: {
|
userId: {
|
||||||
$nin: excludeUserIds
|
$nin: excludeUserIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -158,7 +158,7 @@ async function search(
|
||||||
if (following != null && me != null) {
|
if (following != null && me != null) {
|
||||||
const ids = await getFriends(me._id, false);
|
const ids = await getFriends(me._id, false);
|
||||||
push({
|
push({
|
||||||
user_id: following ? {
|
userId: following ? {
|
||||||
$in: ids
|
$in: ids
|
||||||
} : {
|
} : {
|
||||||
$nin: ids.concat(me._id)
|
$nin: ids.concat(me._id)
|
||||||
|
@ -168,45 +168,45 @@ async function search(
|
||||||
|
|
||||||
if (me != null) {
|
if (me != null) {
|
||||||
const mutes = await Mute.find({
|
const mutes = await Mute.find({
|
||||||
muter_id: me._id,
|
muterId: me._id,
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
});
|
});
|
||||||
const mutedUserIds = mutes.map(m => m.mutee_id);
|
const mutedUserIds = mutes.map(m => m.muteeId);
|
||||||
|
|
||||||
switch (mute) {
|
switch (mute) {
|
||||||
case 'mute_all':
|
case 'mute_all':
|
||||||
push({
|
push({
|
||||||
user_id: {
|
userId: {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
'_reply.user_id': {
|
'_reply.userId': {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
'_repost.user_id': {
|
'_repost.userId': {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'mute_related':
|
case 'mute_related':
|
||||||
push({
|
push({
|
||||||
'_reply.user_id': {
|
'_reply.userId': {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
'_repost.user_id': {
|
'_repost.userId': {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'mute_direct':
|
case 'mute_direct':
|
||||||
push({
|
push({
|
||||||
user_id: {
|
userId: {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'direct_only':
|
case 'direct_only':
|
||||||
push({
|
push({
|
||||||
user_id: {
|
userId: {
|
||||||
$in: mutedUserIds
|
$in: mutedUserIds
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -214,11 +214,11 @@ async function search(
|
||||||
case 'related_only':
|
case 'related_only':
|
||||||
push({
|
push({
|
||||||
$or: [{
|
$or: [{
|
||||||
'_reply.user_id': {
|
'_reply.userId': {
|
||||||
$in: mutedUserIds
|
$in: mutedUserIds
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'_repost.user_id': {
|
'_repost.userId': {
|
||||||
$in: mutedUserIds
|
$in: mutedUserIds
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -227,15 +227,15 @@ async function search(
|
||||||
case 'all_only':
|
case 'all_only':
|
||||||
push({
|
push({
|
||||||
$or: [{
|
$or: [{
|
||||||
user_id: {
|
userId: {
|
||||||
$in: mutedUserIds
|
$in: mutedUserIds
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'_reply.user_id': {
|
'_reply.userId': {
|
||||||
$in: mutedUserIds
|
$in: mutedUserIds
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
'_repost.user_id': {
|
'_repost.userId': {
|
||||||
$in: mutedUserIds
|
$in: mutedUserIds
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
@ -247,7 +247,7 @@ async function search(
|
||||||
if (reply != null) {
|
if (reply != null) {
|
||||||
if (reply) {
|
if (reply) {
|
||||||
push({
|
push({
|
||||||
reply_id: {
|
replyId: {
|
||||||
$exists: true,
|
$exists: true,
|
||||||
$ne: null
|
$ne: null
|
||||||
}
|
}
|
||||||
|
@ -255,11 +255,11 @@ async function search(
|
||||||
} else {
|
} else {
|
||||||
push({
|
push({
|
||||||
$or: [{
|
$or: [{
|
||||||
reply_id: {
|
replyId: {
|
||||||
$exists: false
|
$exists: false
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
reply_id: null
|
replyId: null
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ async function search(
|
||||||
if (repost != null) {
|
if (repost != null) {
|
||||||
if (repost) {
|
if (repost) {
|
||||||
push({
|
push({
|
||||||
repost_id: {
|
repostId: {
|
||||||
$exists: true,
|
$exists: true,
|
||||||
$ne: null
|
$ne: null
|
||||||
}
|
}
|
||||||
|
@ -276,11 +276,11 @@ async function search(
|
||||||
} else {
|
} else {
|
||||||
push({
|
push({
|
||||||
$or: [{
|
$or: [{
|
||||||
repost_id: {
|
repostId: {
|
||||||
$exists: false
|
$exists: false
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
repost_id: null
|
repostId: null
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -289,7 +289,7 @@ async function search(
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
if (media) {
|
if (media) {
|
||||||
push({
|
push({
|
||||||
media_ids: {
|
mediaIds: {
|
||||||
$exists: true,
|
$exists: true,
|
||||||
$ne: null
|
$ne: null
|
||||||
}
|
}
|
||||||
|
@ -297,11 +297,11 @@ async function search(
|
||||||
} else {
|
} else {
|
||||||
push({
|
push({
|
||||||
$or: [{
|
$or: [{
|
||||||
media_ids: {
|
mediaIds: {
|
||||||
$exists: false
|
$exists: false
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
media_ids: null
|
mediaIds: null
|
||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -330,7 +330,7 @@ async function search(
|
||||||
|
|
||||||
if (sinceDate) {
|
if (sinceDate) {
|
||||||
push({
|
push({
|
||||||
created_at: {
|
createdAt: {
|
||||||
$gt: new Date(sinceDate)
|
$gt: new Date(sinceDate)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -338,7 +338,7 @@ async function search(
|
||||||
|
|
||||||
if (untilDate) {
|
if (untilDate) {
|
||||||
push({
|
push({
|
||||||
created_at: {
|
createdAt: {
|
||||||
$lt: new Date(untilDate)
|
$lt: new Date(untilDate)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,9 +12,9 @@ import Post, { pack } from '../../models/post';
|
||||||
* @return {Promise<any>}
|
* @return {Promise<any>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) => new Promise(async (res, rej) => {
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
// Get 'post_id' parameter
|
// Get 'postId' parameter
|
||||||
const [postId, postIdErr] = $(params.post_id).id().$;
|
const [postId, postIdErr] = $(params.postId).id().$;
|
||||||
if (postIdErr) return rej('invalid post_id param');
|
if (postIdErr) return rej('invalid postId param');
|
||||||
|
|
||||||
// Get post
|
// Get post
|
||||||
const post = await Post.findOne({
|
const post = await Post.findOne({
|
||||||
|
|
|
@ -22,25 +22,25 @@ module.exports = async (params, user, app) => {
|
||||||
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
const [limit = 10, limitErr] = $(params.limit).optional.number().range(1, 100).$;
|
||||||
if (limitErr) throw 'invalid limit param';
|
if (limitErr) throw 'invalid limit param';
|
||||||
|
|
||||||
// Get 'since_id' parameter
|
// Get 'sinceId' parameter
|
||||||
const [sinceId, sinceIdErr] = $(params.since_id).optional.id().$;
|
const [sinceId, sinceIdErr] = $(params.sinceId).optional.id().$;
|
||||||
if (sinceIdErr) throw 'invalid since_id param';
|
if (sinceIdErr) throw 'invalid sinceId param';
|
||||||
|
|
||||||
// Get 'until_id' parameter
|
// Get 'untilId' parameter
|
||||||
const [untilId, untilIdErr] = $(params.until_id).optional.id().$;
|
const [untilId, untilIdErr] = $(params.untilId).optional.id().$;
|
||||||
if (untilIdErr) throw 'invalid until_id param';
|
if (untilIdErr) throw 'invalid untilId param';
|
||||||
|
|
||||||
// Get 'since_date' parameter
|
// Get 'sinceDate' parameter
|
||||||
const [sinceDate, sinceDateErr] = $(params.since_date).optional.number().$;
|
const [sinceDate, sinceDateErr] = $(params.sinceDate).optional.number().$;
|
||||||
if (sinceDateErr) throw 'invalid since_date param';
|
if (sinceDateErr) throw 'invalid sinceDate param';
|
||||||
|
|
||||||
// Get 'until_date' parameter
|
// Get 'untilDate' parameter
|
||||||
const [untilDate, untilDateErr] = $(params.until_date).optional.number().$;
|
const [untilDate, untilDateErr] = $(params.untilDate).optional.number().$;
|
||||||
if (untilDateErr) throw 'invalid until_date param';
|
if (untilDateErr) throw 'invalid untilDate param';
|
||||||
|
|
||||||
// Check if only one of since_id, until_id, since_date, until_date specified
|
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
|
||||||
if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
|
if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
|
||||||
throw 'only one of since_id, until_id, since_date, until_date can be specified';
|
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
|
||||||
}
|
}
|
||||||
|
|
||||||
const { followingIds, watchingChannelIds, mutedUserIds } = await rap({
|
const { followingIds, watchingChannelIds, mutedUserIds } = await rap({
|
||||||
|
@ -49,17 +49,17 @@ module.exports = async (params, user, app) => {
|
||||||
|
|
||||||
// Watchしているチャンネルを取得
|
// Watchしているチャンネルを取得
|
||||||
watchingChannelIds: ChannelWatching.find({
|
watchingChannelIds: ChannelWatching.find({
|
||||||
user_id: user._id,
|
userId: user._id,
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}).then(watches => watches.map(w => w.channel_id)),
|
}).then(watches => watches.map(w => w.channelId)),
|
||||||
|
|
||||||
// ミュートしているユーザーを取得
|
// ミュートしているユーザーを取得
|
||||||
mutedUserIds: Mute.find({
|
mutedUserIds: Mute.find({
|
||||||
muter_id: user._id,
|
muterId: user._id,
|
||||||
// 削除されたドキュメントは除く
|
// 削除されたドキュメントは除く
|
||||||
deleted_at: { $exists: false }
|
deletedAt: { $exists: false }
|
||||||
}).then(ms => ms.map(m => m.mutee_id))
|
}).then(ms => ms.map(m => m.muteeId))
|
||||||
});
|
});
|
||||||
|
|
||||||
//#region Construct query
|
//#region Construct query
|
||||||
|
@ -70,31 +70,31 @@ module.exports = async (params, user, app) => {
|
||||||
const query = {
|
const query = {
|
||||||
$or: [{
|
$or: [{
|
||||||
// フォローしている人のタイムラインへの投稿
|
// フォローしている人のタイムラインへの投稿
|
||||||
user_id: {
|
userId: {
|
||||||
$in: followingIds
|
$in: followingIds
|
||||||
},
|
},
|
||||||
// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
|
// 「タイムラインへの」投稿に限定するためにチャンネルが指定されていないもののみに限る
|
||||||
$or: [{
|
$or: [{
|
||||||
channel_id: {
|
channelId: {
|
||||||
$exists: false
|
$exists: false
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
channel_id: null
|
channelId: null
|
||||||
}]
|
}]
|
||||||
}, {
|
}, {
|
||||||
// Watchしているチャンネルへの投稿
|
// Watchしているチャンネルへの投稿
|
||||||
channel_id: {
|
channelId: {
|
||||||
$in: watchingChannelIds
|
$in: watchingChannelIds
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
// mute
|
// mute
|
||||||
user_id: {
|
userId: {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
'_reply.user_id': {
|
'_reply.userId': {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
'_repost.user_id': {
|
'_repost.userId': {
|
||||||
$nin: mutedUserIds
|
$nin: mutedUserIds
|
||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
|
@ -110,11 +110,11 @@ module.exports = async (params, user, app) => {
|
||||||
};
|
};
|
||||||
} else if (sinceDate) {
|
} else if (sinceDate) {
|
||||||
sort._id = 1;
|
sort._id = 1;
|
||||||
query.created_at = {
|
query.createdAt = {
|
||||||
$gt: new Date(sinceDate)
|
$gt: new Date(sinceDate)
|
||||||
};
|
};
|
||||||
} else if (untilDate) {
|
} else if (untilDate) {
|
||||||
query.created_at = {
|
query.createdAt = {
|
||||||
$lt: new Date(untilDate)
|
$lt: new Date(untilDate)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,24 +38,24 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
if (pollErr) return rej('invalid poll param');
|
if (pollErr) return rej('invalid poll param');
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
created_at: {
|
createdAt: {
|
||||||
$gte: new Date(Date.now() - ms('1days'))
|
$gte: new Date(Date.now() - ms('1days'))
|
||||||
},
|
},
|
||||||
repost_count: {
|
repostCount: {
|
||||||
$gt: 0
|
$gt: 0
|
||||||
}
|
}
|
||||||
} as any;
|
} as any;
|
||||||
|
|
||||||
if (reply != undefined) {
|
if (reply != undefined) {
|
||||||
query.reply_id = reply ? { $exists: true, $ne: null } : null;
|
query.replyId = reply ? { $exists: true, $ne: null } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (repost != undefined) {
|
if (repost != undefined) {
|
||||||
query.repost_id = repost ? { $exists: true, $ne: null } : null;
|
query.repostId = repost ? { $exists: true, $ne: null } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (media != undefined) {
|
if (media != undefined) {
|
||||||
query.media_ids = media ? { $exists: true, $ne: null } : null;
|
query.mediaIds = media ? { $exists: true, $ne: null } : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poll != undefined) {
|
if (poll != undefined) {
|
||||||
|
@ -68,7 +68,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
||||||
limit: limit,
|
limit: limit,
|
||||||
skip: offset,
|
skip: offset,
|
||||||
sort: {
|
sort: {
|
||||||
repost_count: -1,
|
repostCount: -1,
|
||||||
_id: -1
|
_id: -1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue