Implement featured note API
This commit is contained in:
parent
407467a236
commit
380f5a972c
@ -22,11 +22,11 @@ Note.createIndex('userId');
|
|||||||
Note.createIndex('mentions');
|
Note.createIndex('mentions');
|
||||||
Note.createIndex('visibleUserIds');
|
Note.createIndex('visibleUserIds');
|
||||||
Note.createIndex('tagsLower');
|
Note.createIndex('tagsLower');
|
||||||
|
Note.createIndex('_user.host');
|
||||||
Note.createIndex('_files._id');
|
Note.createIndex('_files._id');
|
||||||
Note.createIndex('_files.contentType');
|
Note.createIndex('_files.contentType');
|
||||||
Note.createIndex({
|
Note.createIndex({ createdAt: -1 });
|
||||||
createdAt: -1
|
Note.createIndex({ score: -1 }, { sparse: true });
|
||||||
});
|
|
||||||
export default Note;
|
export default Note;
|
||||||
|
|
||||||
export function isValidText(text: string): boolean {
|
export function isValidText(text: string): boolean {
|
||||||
@ -85,8 +85,14 @@ export type INote = {
|
|||||||
heading: number;
|
heading: number;
|
||||||
speed: number;
|
speed: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
uri: string;
|
uri: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 人気の投稿度合いを表すスコア
|
||||||
|
*/
|
||||||
|
score: number;
|
||||||
|
|
||||||
// 非正規化
|
// 非正規化
|
||||||
_reply?: {
|
_reply?: {
|
||||||
userId: mongo.ObjectID;
|
userId: mongo.ObjectID;
|
||||||
@ -298,6 +304,7 @@ export const pack = async (
|
|||||||
delete _note.prev;
|
delete _note.prev;
|
||||||
delete _note.next;
|
delete _note.next;
|
||||||
delete _note.tagsLower;
|
delete _note.tagsLower;
|
||||||
|
delete _note.score;
|
||||||
delete _note._user;
|
delete _note._user;
|
||||||
delete _note._reply;
|
delete _note._reply;
|
||||||
delete _note._renote;
|
delete _note._renote;
|
||||||
|
49
src/server/api/endpoints/notes/featured.ts
Normal file
49
src/server/api/endpoints/notes/featured.ts
Normal file
@ -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);
|
||||||
|
};
|
@ -314,7 +314,8 @@ async function renderActivity(data: Option, note: INote) {
|
|||||||
function incRenoteCount(renote: INote) {
|
function incRenoteCount(renote: INote) {
|
||||||
Note.update({ _id: renote._id }, {
|
Note.update({ _id: renote._id }, {
|
||||||
$inc: {
|
$inc: {
|
||||||
renoteCount: 1
|
renoteCount: 1,
|
||||||
|
score: 1
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -36,12 +36,12 @@ export default async (user: IUser, note: INote, reaction: string) => new Promise
|
|||||||
|
|
||||||
res();
|
res();
|
||||||
|
|
||||||
const inc: {[key: string]: number} = {};
|
|
||||||
inc[`reactionCounts.${reaction}`] = 1;
|
|
||||||
|
|
||||||
// Increment reactions count
|
// Increment reactions count
|
||||||
await Note.update({ _id: note._id }, {
|
await Note.update({ _id: note._id }, {
|
||||||
$inc: inc
|
$inc: {
|
||||||
|
[`reactionCounts.${reaction}`]: 1,
|
||||||
|
score: 1
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
perUserReactionsChart.update(user, note);
|
perUserReactionsChart.update(user, note);
|
||||||
|
Loading…
Reference in New Issue
Block a user