summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes/global-timeline.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-09-05 23:55:51 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-09-05 23:55:51 +0900
commitb5ff2abdb9ee0c086c8970c738cce5d61761f8f5 (patch)
treec23a8e7e5bec3ea21167795fd008942127823d41 /src/server/api/endpoints/notes/global-timeline.ts
parent[WIP] Update welcome page (diff)
downloadmisskey-b5ff2abdb9ee0c086c8970c738cce5d61761f8f5.tar.gz
misskey-b5ff2abdb9ee0c086c8970c738cce5d61761f8f5.tar.bz2
misskey-b5ff2abdb9ee0c086c8970c738cce5d61761f8f5.zip
互換性のためのコードを追加 & #2623
Diffstat (limited to 'src/server/api/endpoints/notes/global-timeline.ts')
-rw-r--r--src/server/api/endpoints/notes/global-timeline.ts77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/server/api/endpoints/notes/global-timeline.ts b/src/server/api/endpoints/notes/global-timeline.ts
index 554245a0f4..e70fc5d76f 100644
--- a/src/server/api/endpoints/notes/global-timeline.ts
+++ b/src/server/api/endpoints/notes/global-timeline.ts
@@ -3,40 +3,49 @@ import Note from '../../../../models/note';
import Mute from '../../../../models/mute';
import { pack } from '../../../../models/note';
import { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
-/**
- * Get timeline of global
- */
-export default async (params: any, user: ILocalUser) => {
- // Get 'limit' parameter
- const [limit = 10, limitErr] = $.num.optional.range(1, 100).get(params.limit);
- if (limitErr) throw 'invalid limit param';
+export const meta = {
+ desc: {
+ 'ja-JP': 'グローバルタイムラインを取得します。'
+ },
+
+ params: {
+ withFiles: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か'
+ }
+ }),
+
+ mediaOnly: $.bool.optional.note({
+ desc: {
+ 'ja-JP': 'ファイルが添付された投稿に限定するか否か (このパラメータは廃止予定です。代わりに withFiles を使ってください。)'
+ }
+ }),
+
+ limit: $.num.optional.range(1, 100).note({
+ default: 10
+ }),
+
+ sinceId: $.type(ID).optional.note({}),
- // Get 'sinceId' parameter
- const [sinceId, sinceIdErr] = $.type(ID).optional.get(params.sinceId);
- if (sinceIdErr) throw 'invalid sinceId param';
+ untilId: $.type(ID).optional.note({}),
- // Get 'untilId' parameter
- const [untilId, untilIdErr] = $.type(ID).optional.get(params.untilId);
- if (untilIdErr) throw 'invalid untilId param';
+ sinceDate: $.num.optional.note({}),
- // Get 'sinceDate' parameter
- const [sinceDate, sinceDateErr] = $.num.optional.get(params.sinceDate);
- if (sinceDateErr) throw 'invalid sinceDate param';
+ untilDate: $.num.optional.note({}),
+ }
+};
- // Get 'untilDate' parameter
- const [untilDate, untilDateErr] = $.num.optional.get(params.untilDate);
- if (untilDateErr) throw 'invalid untilDate param';
+export default async (params: any, user: ILocalUser) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
// Check if only one of sinceId, untilId, sinceDate, untilDate specified
- if ([sinceId, untilId, sinceDate, untilDate].filter(x => x != null).length > 1) {
+ if ([ps.sinceId, ps.untilId, ps.sinceDate, ps.untilDate].filter(x => x != null).length > 1) {
throw 'only one of sinceId, untilId, sinceDate, untilDate can be specified';
}
- // Get 'withFiles' parameter
- const [withFiles, withFilesErr] = $.bool.optional.get(params.withFiles);
- if (withFilesErr) throw 'invalid withFiles param';
-
// ミュートしているユーザーを取得
const mutedUserIds = user ? (await Mute.find({
muterId: user._id
@@ -68,27 +77,29 @@ export default async (params: any, user: ILocalUser) => {
};
}
+ const withFiles = ps.withFiles != null ? ps.withFiles : ps.mediaOnly;
+
if (withFiles) {
query.fileIds = { $exists: true, $ne: [] };
}
- if (sinceId) {
+ if (ps.sinceId) {
sort._id = 1;
query._id = {
- $gt: sinceId
+ $gt: ps.sinceId
};
- } else if (untilId) {
+ } else if (ps.untilId) {
query._id = {
- $lt: untilId
+ $lt: ps.untilId
};
- } else if (sinceDate) {
+ } else if (ps.sinceDate) {
sort._id = 1;
query.createdAt = {
- $gt: new Date(sinceDate)
+ $gt: new Date(ps.sinceDate)
};
- } else if (untilDate) {
+ } else if (ps.untilDate) {
query.createdAt = {
- $lt: new Date(untilDate)
+ $lt: new Date(ps.untilDate)
};
}
//#endregion
@@ -96,7 +107,7 @@ export default async (params: any, user: ILocalUser) => {
// Issue query
const timeline = await Note
.find(query, {
- limit: limit,
+ limit: ps.limit,
sort: sort
});