mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-17 19:28:58 +01:00
e314be5b59
* Fix avatar/banner proxy Co-authored-by: mei23 <m@m544.net> * use getAvatarUrl * fix * join avatar and banner to improve performance * join * Update hybrid-timeline.ts * fix Co-authored-by: mei23 <m@m544.net> Co-authored-by: syuilo <Syuilotan@yahoo.co.jp>
67 lines
2 KiB
TypeScript
67 lines
2 KiB
TypeScript
import define from '../../define.js';
|
|
import { generateMutedUserQuery } from '../../common/generate-muted-user-query.js';
|
|
import { Notes } from '@/models/index.js';
|
|
import { generateBlockedUserQuery } from '../../common/generate-block-query.js';
|
|
|
|
export const meta = {
|
|
tags: ['notes'],
|
|
|
|
requireCredential: false,
|
|
|
|
res: {
|
|
type: 'array',
|
|
optional: false, nullable: false,
|
|
items: {
|
|
type: 'object',
|
|
optional: false, nullable: false,
|
|
ref: 'Note',
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
export const paramDef = {
|
|
type: 'object',
|
|
properties: {
|
|
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
|
|
offset: { type: 'integer', default: 0 },
|
|
},
|
|
required: [],
|
|
} as const;
|
|
|
|
// eslint-disable-next-line import/no-default-export
|
|
export default define(meta, paramDef, async (ps, user) => {
|
|
const max = 30;
|
|
const day = 1000 * 60 * 60 * 24 * 3; // 3日前まで
|
|
|
|
const query = Notes.createQueryBuilder('note')
|
|
.addSelect('note.score')
|
|
.where('note.userHost IS NULL')
|
|
.andWhere(`note.score > 0`)
|
|
.andWhere(`note.createdAt > :date`, { date: new Date(Date.now() - day) })
|
|
.andWhere(`note.visibility = 'public'`)
|
|
.innerJoinAndSelect('note.user', 'user')
|
|
.leftJoinAndSelect('user.avatar', 'avatar')
|
|
.leftJoinAndSelect('user.banner', 'banner')
|
|
.leftJoinAndSelect('note.reply', 'reply')
|
|
.leftJoinAndSelect('note.renote', 'renote')
|
|
.leftJoinAndSelect('reply.user', 'replyUser')
|
|
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
|
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
|
.leftJoinAndSelect('renote.user', 'renoteUser')
|
|
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
|
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
|
|
|
if (user) generateMutedUserQuery(query, user);
|
|
if (user) generateBlockedUserQuery(query, user);
|
|
|
|
let notes = await query
|
|
.orderBy('note.score', 'DESC')
|
|
.take(max)
|
|
.getMany();
|
|
|
|
notes.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime());
|
|
|
|
notes = notes.slice(ps.offset, ps.offset + ps.limit);
|
|
|
|
return await Notes.packMany(notes, user);
|
|
});
|