summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notes
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2018-10-25 07:04:15 +0900
committersyuilo <syuilotan@yahoo.co.jp>2018-10-25 07:04:15 +0900
commit380f5a972c4bdf40c12273426f2dd1a9e16b81a2 (patch)
treea8670f76343449ec3dc5c50176a152a435a7d512 /src/server/api/endpoints/notes
parentUpdate Node.js to v11 (diff)
downloadsharkey-380f5a972c4bdf40c12273426f2dd1a9e16b81a2.tar.gz
sharkey-380f5a972c4bdf40c12273426f2dd1a9e16b81a2.tar.bz2
sharkey-380f5a972c4bdf40c12273426f2dd1a9e16b81a2.zip
Implement featured note API
Diffstat (limited to 'src/server/api/endpoints/notes')
-rw-r--r--src/server/api/endpoints/notes/featured.ts49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/server/api/endpoints/notes/featured.ts b/src/server/api/endpoints/notes/featured.ts
new file mode 100644
index 0000000000..363170ead6
--- /dev/null
+++ b/src/server/api/endpoints/notes/featured.ts
@@ -0,0 +1,49 @@
+import $ from 'cafy';
+import Note from '../../../../models/note';
+import { packMany } from '../../../../models/note';
+import { ILocalUser } from '../../../../models/user';
+import getParams from '../../get-params';
+
+export const meta = {
+ desc: {
+ 'ja-JP': 'Featuredな投稿を取得します。',
+ 'en-US': 'Get featured notes.'
+ },
+
+ requireCredential: false,
+
+ params: {
+ limit: $.num.optional.range(1, 30).note({
+ default: 10,
+ desc: {
+ 'ja-JP': '最大数'
+ }
+ })
+ }
+};
+
+export default async (params: any, user: ILocalUser) => {
+ const [ps, psErr] = getParams(meta, params);
+ if (psErr) throw psErr;
+
+ const day = 1000 * 60 * 60 * 24;
+
+ const notes = await Note
+ .find({
+ createdAt: {
+ $gt: new Date(Date.now() - day)
+ },
+ deletedAt: null,
+ visibility: { $in: ['public', 'home'] }
+ }, {
+ limit: ps.limit,
+ sort: {
+ score: -1
+ },
+ hint: {
+ score: -1
+ }
+ });
+
+ return await packMany(notes, user);
+};