From cebea4e94c15b5a75da40801683b2c290a7e6fdb Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 8 Apr 2018 04:02:12 +0900 Subject: [PATCH] Some bug fixes and clean ups --- .../endpoints/aggregation/notes/reaction.ts | 76 ------------------- .../endpoints/aggregation/notes/reactions.ts | 72 ------------------ .../api/endpoints/aggregation/notes/reply.ts | 75 ------------------ .../api/endpoints/aggregation/notes/repost.ts | 75 ------------------ .../api/endpoints/drive/files/create.ts | 2 +- .../endpoints/drive/files/upload_from_url.ts | 2 +- src/server/api/endpoints/notes/polls/vote.ts | 2 +- .../api/endpoints/notes/reactions/create.ts | 1 - 8 files changed, 3 insertions(+), 302 deletions(-) delete mode 100644 src/server/api/endpoints/aggregation/notes/reaction.ts delete mode 100644 src/server/api/endpoints/aggregation/notes/reactions.ts delete mode 100644 src/server/api/endpoints/aggregation/notes/reply.ts delete mode 100644 src/server/api/endpoints/aggregation/notes/repost.ts diff --git a/src/server/api/endpoints/aggregation/notes/reaction.ts b/src/server/api/endpoints/aggregation/notes/reaction.ts deleted file mode 100644 index 586e8c2d8..000000000 --- a/src/server/api/endpoints/aggregation/notes/reaction.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Note from '../../../../../models/note'; -import Reaction from '../../../../../models/note-reaction'; - -/** - * Aggregate reaction of a note - * - * @param {any} params - * @return {Promise} - */ -module.exports = (params) => new Promise(async (res, rej) => { - // Get 'noteId' parameter - const [noteId, noteIdErr] = $(params.noteId).id().$; - if (noteIdErr) return rej('invalid noteId param'); - - // Lookup note - const note = await Note.findOne({ - _id: noteId - }); - - if (note === null) { - return rej('note not found'); - } - - const datas = await Reaction - .aggregate([ - { $match: { noteId: note._id } }, - { $project: { - createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST - }}, - { $project: { - date: { - year: { $year: '$createdAt' }, - month: { $month: '$createdAt' }, - day: { $dayOfMonth: '$createdAt' } - } - }}, - { $group: { - _id: '$date', - count: { $sum: 1 } - }} - ]); - - datas.forEach(data => { - data.date = data._id; - delete data._id; - }); - - const graph = []; - - for (let i = 0; i < 30; 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() - )[0]; - - if (data) { - graph.push(data); - } else { - graph.push({ - date: { - year: day.getFullYear(), - month: day.getMonth() + 1, // In JavaScript, month is zero-based. - day: day.getDate() - }, - count: 0 - }); - } - } - - res(graph); -}); diff --git a/src/server/api/endpoints/aggregation/notes/reactions.ts b/src/server/api/endpoints/aggregation/notes/reactions.ts deleted file mode 100644 index ff9491292..000000000 --- a/src/server/api/endpoints/aggregation/notes/reactions.ts +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Note from '../../../../../models/note'; -import Reaction from '../../../../../models/note-reaction'; - -/** - * Aggregate reactions of a note - * - * @param {any} params - * @return {Promise} - */ -module.exports = (params) => new Promise(async (res, rej) => { - // Get 'noteId' parameter - const [noteId, noteIdErr] = $(params.noteId).id().$; - if (noteIdErr) return rej('invalid noteId param'); - - // Lookup note - const note = await Note.findOne({ - _id: noteId - }); - - if (note === null) { - return rej('note not found'); - } - - const startTime = new Date(new Date().setMonth(new Date().getMonth() - 1)); - - const reactions = await Reaction - .find({ - noteId: note._id, - $or: [ - { deletedAt: { $exists: false } }, - { deletedAt: { $gt: startTime } } - ] - }, { - sort: { - _id: -1 - }, - fields: { - _id: false, - noteId: false - } - }); - - const graph = []; - - for (let i = 0; i < 30; i++) { - let day = new Date(new Date().setDate(new Date().getDate() - i)); - day = new Date(day.setMilliseconds(999)); - day = new Date(day.setSeconds(59)); - day = new Date(day.setMinutes(59)); - day = new Date(day.setHours(23)); - // day = day.getTime(); - - const count = reactions.filter(r => - r.createdAt < day && (r.deletedAt == null || r.deletedAt > day) - ).length; - - graph.push({ - date: { - year: day.getFullYear(), - month: day.getMonth() + 1, // In JavaScript, month is zero-based. - day: day.getDate() - }, - count: count - }); - } - - res(graph); -}); diff --git a/src/server/api/endpoints/aggregation/notes/reply.ts b/src/server/api/endpoints/aggregation/notes/reply.ts deleted file mode 100644 index 42df95a9a..000000000 --- a/src/server/api/endpoints/aggregation/notes/reply.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Note from '../../../../../models/note'; - -/** - * Aggregate reply of a note - * - * @param {any} params - * @return {Promise} - */ -module.exports = (params) => new Promise(async (res, rej) => { - // Get 'noteId' parameter - const [noteId, noteIdErr] = $(params.noteId).id().$; - if (noteIdErr) return rej('invalid noteId param'); - - // Lookup note - const note = await Note.findOne({ - _id: noteId - }); - - if (note === null) { - return rej('note not found'); - } - - const datas = await Note - .aggregate([ - { $match: { reply: note._id } }, - { $project: { - createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST - }}, - { $project: { - date: { - year: { $year: '$createdAt' }, - month: { $month: '$createdAt' }, - day: { $dayOfMonth: '$createdAt' } - } - }}, - { $group: { - _id: '$date', - count: { $sum: 1 } - }} - ]); - - datas.forEach(data => { - data.date = data._id; - delete data._id; - }); - - const graph = []; - - for (let i = 0; i < 30; 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() - )[0]; - - if (data) { - graph.push(data); - } else { - graph.push({ - date: { - year: day.getFullYear(), - month: day.getMonth() + 1, // In JavaScript, month is zero-based. - day: day.getDate() - }, - count: 0 - }); - } - } - - res(graph); -}); diff --git a/src/server/api/endpoints/aggregation/notes/repost.ts b/src/server/api/endpoints/aggregation/notes/repost.ts deleted file mode 100644 index feb3348a7..000000000 --- a/src/server/api/endpoints/aggregation/notes/repost.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Module dependencies - */ -import $ from 'cafy'; -import Note from '../../../../../models/note'; - -/** - * Aggregate renote of a note - * - * @param {any} params - * @return {Promise} - */ -module.exports = (params) => new Promise(async (res, rej) => { - // Get 'noteId' parameter - const [noteId, noteIdErr] = $(params.noteId).id().$; - if (noteIdErr) return rej('invalid noteId param'); - - // Lookup note - const note = await Note.findOne({ - _id: noteId - }); - - if (note === null) { - return rej('note not found'); - } - - const datas = await Note - .aggregate([ - { $match: { renoteId: note._id } }, - { $project: { - createdAt: { $add: ['$createdAt', 9 * 60 * 60 * 1000] } // Convert into JST - }}, - { $project: { - date: { - year: { $year: '$createdAt' }, - month: { $month: '$createdAt' }, - day: { $dayOfMonth: '$createdAt' } - } - }}, - { $group: { - _id: '$date', - count: { $sum: 1 } - }} - ]); - - datas.forEach(data => { - data.date = data._id; - delete data._id; - }); - - const graph = []; - - for (let i = 0; i < 30; 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() - )[0]; - - if (data) { - graph.push(data); - } else { - graph.push({ - date: { - year: day.getFullYear(), - month: day.getMonth() + 1, // In JavaScript, month is zero-based. - day: day.getDate() - }, - count: 0 - }); - } - } - - res(graph); -}); diff --git a/src/server/api/endpoints/drive/files/create.ts b/src/server/api/endpoints/drive/files/create.ts index 10ced1d8b..df0bd0a0d 100644 --- a/src/server/api/endpoints/drive/files/create.ts +++ b/src/server/api/endpoints/drive/files/create.ts @@ -3,7 +3,7 @@ */ import $ from 'cafy'; import { validateFileName, pack } from '../../../../../models/drive-file'; -import create from '../../../../../drive/add-file'; +import create from '../../../../../services/drive/add-file'; /** * Create a file diff --git a/src/server/api/endpoints/drive/files/upload_from_url.ts b/src/server/api/endpoints/drive/files/upload_from_url.ts index acb67b2e0..9ebc8b823 100644 --- a/src/server/api/endpoints/drive/files/upload_from_url.ts +++ b/src/server/api/endpoints/drive/files/upload_from_url.ts @@ -3,7 +3,7 @@ */ import $ from 'cafy'; import { pack } from '../../../../../models/drive-file'; -import uploadFromUrl from '../../../../../drive/upload-from-url'; +import uploadFromUrl from '../../../../../services/drive/upload-from-url'; /** * Create a file from a URL diff --git a/src/server/api/endpoints/notes/polls/vote.ts b/src/server/api/endpoints/notes/polls/vote.ts index fd4412ad3..03d94da60 100644 --- a/src/server/api/endpoints/notes/polls/vote.ts +++ b/src/server/api/endpoints/notes/polls/vote.ts @@ -5,7 +5,7 @@ import $ from 'cafy'; import Vote from '../../../../../models/poll-vote'; import Note from '../../../../../models/note'; import Watching from '../../../../../models/note-watching'; -import watch from '../../../../../note/watch'; +import watch from '../../../../../services/note/watch'; import { publishNoteStream } from '../../../../../publishers/stream'; import notify from '../../../../../publishers/notify'; diff --git a/src/server/api/endpoints/notes/reactions/create.ts b/src/server/api/endpoints/notes/reactions/create.ts index ffb7bcc35..c80c5416b 100644 --- a/src/server/api/endpoints/notes/reactions/create.ts +++ b/src/server/api/endpoints/notes/reactions/create.ts @@ -2,7 +2,6 @@ * Module dependencies */ import $ from 'cafy'; -import Reaction from '../../../../../models/note-reaction'; import Note from '../../../../../models/note'; import create from '../../../../../services/note/reaction/create';