diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-10-25 07:04:15 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-10-25 07:04:15 +0900 |
| commit | 380f5a972c4bdf40c12273426f2dd1a9e16b81a2 (patch) | |
| tree | a8670f76343449ec3dc5c50176a152a435a7d512 /src/server/api/endpoints/notes | |
| parent | Update Node.js to v11 (diff) | |
| download | sharkey-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.ts | 49 |
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); +}; |