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