From caeba1197c4b66e10614ffbddce0a2e98b0b5ef3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 24 May 2017 20:50:17 +0900 Subject: Refactoring --- src/api/endpoints/aggregation/posts/reaction.ts | 2 +- src/api/endpoints/aggregation/posts/reply.ts | 2 +- src/api/endpoints/aggregation/posts/repost.ts | 2 +- src/api/endpoints/aggregation/users/activity.ts | 2 +- src/api/endpoints/aggregation/users/post.ts | 2 +- src/api/endpoints/aggregation/users/reaction.ts | 2 +- src/api/endpoints/i/appdata/set.ts | 2 +- src/api/endpoints/posts/create.ts | 6 ++---- src/api/event.ts | 16 ++++++++-------- 9 files changed, 17 insertions(+), 19 deletions(-) (limited to 'src/api') diff --git a/src/api/endpoints/aggregation/posts/reaction.ts b/src/api/endpoints/aggregation/posts/reaction.ts index e4ca680c33..eb99b9d088 100644 --- a/src/api/endpoints/aggregation/posts/reaction.ts +++ b/src/api/endpoints/aggregation/posts/reaction.ts @@ -52,7 +52,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; for (let i = 0; i < 30; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); + const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() diff --git a/src/api/endpoints/aggregation/posts/reply.ts b/src/api/endpoints/aggregation/posts/reply.ts index c7ba413311..02a60c8969 100644 --- a/src/api/endpoints/aggregation/posts/reply.ts +++ b/src/api/endpoints/aggregation/posts/reply.ts @@ -51,7 +51,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; for (let i = 0; i < 30; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); + const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() diff --git a/src/api/endpoints/aggregation/posts/repost.ts b/src/api/endpoints/aggregation/posts/repost.ts index 88d21243f8..217159caa7 100644 --- a/src/api/endpoints/aggregation/posts/repost.ts +++ b/src/api/endpoints/aggregation/posts/repost.ts @@ -51,7 +51,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; for (let i = 0; i < 30; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); + const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() diff --git a/src/api/endpoints/aggregation/users/activity.ts b/src/api/endpoints/aggregation/users/activity.ts index 6c5efff4b3..5d2ce995f7 100644 --- a/src/api/endpoints/aggregation/users/activity.ts +++ b/src/api/endpoints/aggregation/users/activity.ts @@ -86,7 +86,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; for (let i = 0; i < 365; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); + const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() diff --git a/src/api/endpoints/aggregation/users/post.ts b/src/api/endpoints/aggregation/users/post.ts index cb6bae4970..c964815a0c 100644 --- a/src/api/endpoints/aggregation/users/post.ts +++ b/src/api/endpoints/aggregation/users/post.ts @@ -84,7 +84,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; for (let i = 0; i < 30; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); + const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() diff --git a/src/api/endpoints/aggregation/users/reaction.ts b/src/api/endpoints/aggregation/users/reaction.ts index 8f1919fa69..0a082ed1b7 100644 --- a/src/api/endpoints/aggregation/users/reaction.ts +++ b/src/api/endpoints/aggregation/users/reaction.ts @@ -56,7 +56,7 @@ module.exports = (params) => new Promise(async (res, rej) => { const graph = []; for (let i = 0; i < 30; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); + const day = new Date(new Date().setDate(new Date().getDate() - i)); const data = datas.filter(d => d.date.year == day.getFullYear() && d.date.month == day.getMonth() + 1 && d.date.day == day.getDate() diff --git a/src/api/endpoints/i/appdata/set.ts b/src/api/endpoints/i/appdata/set.ts index 07178d6507..24f192de6b 100644 --- a/src/api/endpoints/i/appdata/set.ts +++ b/src/api/endpoints/i/appdata/set.ts @@ -34,7 +34,7 @@ module.exports = (params, user, app, isSecure) => new Promise(async (res, rej) = const [value, valueError] = $(params.value).optional.string().$; if (valueError) return rej('invalid value param'); - let set = {}; + const set = {}; if (data) { Object.entries(data).forEach(([k, v]) => { set[`data.${k}`] = v; diff --git a/src/api/endpoints/posts/create.ts b/src/api/endpoints/posts/create.ts index 26faee4713..535f850a6e 100644 --- a/src/api/endpoints/posts/create.ts +++ b/src/api/endpoints/posts/create.ts @@ -36,9 +36,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { // Fetch files // forEach だと途中でエラーなどがあっても return できないので // 敢えて for を使っています。 - for (let i = 0; i < mediaIds.length; i++) { - const mediaId = mediaIds[i]; - + for (const mediaId of mediaIds) { // Fetch file // SELECT _id const entity = await DriveFile.findOne({ @@ -188,7 +186,7 @@ module.exports = (params, user, app) => new Promise(async (res, rej) => { } }); - let mentions = []; + const mentions = []; function addMention(mentionee, type) { // Reject if already added diff --git a/src/api/event.ts b/src/api/event.ts index 39dc809bdc..9613a9f7cc 100644 --- a/src/api/event.ts +++ b/src/api/event.ts @@ -13,14 +13,6 @@ class MisskeyEvent { config.redis.port, config.redis.host); } - private publish(channel: string, type: string, value?: any): void { - const message = value == null ? - { type: type } : - { type: type, body: value }; - - this.redisClient.publish(`misskey:${channel}`, JSON.stringify(message)); - } - public publishUserStream(userId: ID, type: string, value?: any): void { this.publish(`user-stream:${userId}`, type, typeof value === 'undefined' ? null : value); } @@ -32,6 +24,14 @@ class MisskeyEvent { public publishMessagingStream(userId: ID, otherpartyId: ID, type: string, value?: any): void { this.publish(`messaging-stream:${userId}-${otherpartyId}`, type, typeof value === 'undefined' ? null : value); } + + private publish(channel: string, type: string, value?: any): void { + const message = value == null ? + { type: type } : + { type: type, body: value }; + + this.redisClient.publish(`misskey:${channel}`, JSON.stringify(message)); + } } const ev = new MisskeyEvent(); -- cgit v1.2.3-freya