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