2018-12-21 02:54:39 +00:00
|
|
|
import { Feed } from 'feed';
|
2022-04-17 12:18:18 +00:00
|
|
|
import { In, IsNull } from 'typeorm';
|
2022-02-27 02:07:39 +00:00
|
|
|
import config from '@/config/index.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
2022-04-17 12:18:18 +00:00
|
|
|
import { Notes, DriveFiles, UserProfiles, Users } from '@/models/index.js';
|
2018-12-21 02:54:39 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
export default async function(user: User) {
|
2019-07-02 10:20:34 +00:00
|
|
|
const author = {
|
2018-12-21 02:54:39 +00:00
|
|
|
link: `${config.url}/@${user.username}`,
|
2021-12-09 14:58:30 +00:00
|
|
|
name: user.name || user.username,
|
2018-12-21 02:54:39 +00:00
|
|
|
};
|
|
|
|
|
2022-03-26 06:34:00 +00:00
|
|
|
const profile = await UserProfiles.findOneByOrFail({ userId: user.id });
|
2019-04-10 06:04:27 +00:00
|
|
|
|
2019-04-07 12:50:36 +00:00
|
|
|
const notes = await Notes.find({
|
|
|
|
where: {
|
|
|
|
userId: user.id,
|
2022-03-26 06:34:00 +00:00
|
|
|
renoteId: IsNull(),
|
2021-12-09 14:58:30 +00:00
|
|
|
visibility: In(['public', 'home']),
|
2019-04-07 12:50:36 +00:00
|
|
|
},
|
|
|
|
order: { createdAt: -1 },
|
2021-12-09 14:58:30 +00:00
|
|
|
take: 20,
|
2018-12-21 02:54:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const feed = new Feed({
|
|
|
|
id: author.link,
|
|
|
|
title: `${author.name} (@${user.username}@${config.host})`,
|
|
|
|
updated: notes[0].createdAt,
|
2022-09-11 04:20:43 +00:00
|
|
|
generator: 'FoundKey',
|
2021-11-07 09:04:32 +00:00
|
|
|
description: `${user.notesCount} Notes, ${profile.ffVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.ffVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
|
2018-12-21 02:54:39 +00:00
|
|
|
link: author.link,
|
2022-04-17 12:18:18 +00:00
|
|
|
image: await Users.getAvatarUrl(user),
|
2018-12-21 02:54:39 +00:00
|
|
|
feedLinks: {
|
|
|
|
json: `${author.link}.json`,
|
|
|
|
atom: `${author.link}.atom`,
|
|
|
|
},
|
2019-07-02 10:20:34 +00:00
|
|
|
author,
|
2021-12-09 14:58:30 +00:00
|
|
|
copyright: user.name || user.username,
|
2019-07-02 10:20:34 +00:00
|
|
|
});
|
2018-12-21 02:54:39 +00:00
|
|
|
|
|
|
|
for (const note of notes) {
|
2022-03-26 06:34:00 +00:00
|
|
|
const files = note.fileIds.length > 0 ? await DriveFiles.findBy({
|
2021-12-09 14:58:30 +00:00
|
|
|
id: In(note.fileIds),
|
2019-04-07 12:50:36 +00:00
|
|
|
}) : [];
|
|
|
|
const file = files.find(file => file.type.startsWith('image/'));
|
2018-12-21 02:54:39 +00:00
|
|
|
|
|
|
|
feed.addItem({
|
|
|
|
title: `New note by ${author.name}`,
|
2019-04-07 12:50:36 +00:00
|
|
|
link: `${config.url}/notes/${note.id}`,
|
2018-12-21 02:54:39 +00:00
|
|
|
date: note.createdAt,
|
2019-04-12 16:43:22 +00:00
|
|
|
description: note.cw || undefined,
|
|
|
|
content: note.text || undefined,
|
2021-12-09 14:58:30 +00:00
|
|
|
image: file ? DriveFiles.getPublicUrl(file) || undefined : undefined,
|
2018-12-21 02:54:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return feed;
|
|
|
|
}
|