2018-12-21 11:54:39 +09:00
|
|
|
import { Feed } from 'feed';
|
2022-02-27 11:07:39 +09:00
|
|
|
import config from '@/config/index.js';
|
|
|
|
import { User } from '@/models/entities/user.js';
|
|
|
|
import { Notes, DriveFiles, UserProfiles } from '@/models/index.js';
|
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}`,
|
2021-12-09 23:58:30 +09:00
|
|
|
name: user.name || user.username,
|
2018-12-21 11:54:39 +09:00
|
|
|
};
|
|
|
|
|
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,
|
2021-12-09 23:58:30 +09:00
|
|
|
visibility: In(['public', 'home']),
|
2019-04-07 21:50:36 +09:00
|
|
|
},
|
|
|
|
order: { createdAt: -1 },
|
2021-12-09 23:58:30 +09:00
|
|
|
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,
|
2021-12-09 23:58:30 +09:00
|
|
|
copyright: user.name || user.username,
|
2019-07-02 19:20:34 +09:00
|
|
|
});
|
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({
|
2021-12-09 23:58:30 +09:00
|
|
|
id: In(note.fileIds),
|
2019-04-07 21:50:36 +09:00
|
|
|
}) : [];
|
|
|
|
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,
|
2021-12-09 23:58:30 +09:00
|
|
|
image: file ? DriveFiles.getPublicUrl(file) || undefined : undefined,
|
2018-12-21 11:54:39 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return feed;
|
|
|
|
}
|