rss json atomを隠した

This commit is contained in:
hijiki 2024-11-01 18:07:22 +09:00
parent b3fc2b484a
commit 1bfcdc45e8
3 changed files with 72 additions and 71 deletions

View File

@ -485,7 +485,7 @@ export class ClientServerService {
// URL preview endpoint // URL preview endpoint
fastify.get<{ Querystring: { url: string; lang: string; } }>('/url', (request, reply) => this.urlPreviewService.handle(request, reply)); fastify.get<{ Querystring: { url: string; lang: string; } }>('/url', (request, reply) => this.urlPreviewService.handle(request, reply));
const getFeed = async (acct: string) => { /* const getFeed = async (acct: string) => {
const { username, host } = Acct.parse(acct); const { username, host } = Acct.parse(acct);
const user = await this.usersRepository.findOneBy({ const user = await this.usersRepository.findOneBy({
usernameLower: username.toLowerCase(), usernameLower: username.toLowerCase(),
@ -496,7 +496,7 @@ export class ClientServerService {
return user && await this.feedService.packFeed(user); return user && await this.feedService.packFeed(user);
}; };
// Atom /* // Atom
fastify.get<{ Params: { user?: string; } }>('/@:user.atom', async (request, reply) => { fastify.get<{ Params: { user?: string; } }>('/@:user.atom', async (request, reply) => {
if (request.params.user == null) return await renderBase(reply); if (request.params.user == null) return await renderBase(reply);
@ -540,7 +540,7 @@ export class ClientServerService {
return; return;
} }
}); });
*/
//#region SSR (for crawlers) //#region SSR (for crawlers)
// User // User
fastify.get<{ Params: { user: string; sub?: string; } }>('/@:user/:sub?', async (request, reply) => { fastify.get<{ Params: { user: string; sub?: string; } }>('/@:user/:sub?', async (request, reply) => {

View File

@ -19,78 +19,79 @@ import { parse as mfmParse } from '@transfem-org/sfm-js';
@Injectable() @Injectable()
export class FeedService { export class FeedService {
constructor( constructor(
@Inject(DI.config) @Inject(DI.config)
private config: Config, private config: Config,
@Inject(DI.userProfilesRepository) @Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository, private userProfilesRepository: UserProfilesRepository,
@Inject(DI.notesRepository) @Inject(DI.notesRepository)
private notesRepository: NotesRepository, private notesRepository: NotesRepository,
@Inject(DI.driveFilesRepository) @Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository, private driveFilesRepository: DriveFilesRepository,
private userEntityService: UserEntityService, private userEntityService: UserEntityService,
private driveFileEntityService: DriveFileEntityService, private driveFileEntityService: DriveFileEntityService,
private idService: IdService, private idService: IdService,
private mfmService: MfmService, private mfmService: MfmService,
) { ) {
} }
@bindThis @bindThis
public async packFeed(user: MiUser) { public async packFeed(user: MiUser) {
const author = { // フィード生成を無効化
link: `${this.config.url}/@${user.username}`, throw new Error("フィード生成は無効化されています");
name: user.name ?? user.username,
};
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id }); // フィード生成のロジックはここでコメントアウトまたは削除します
/*
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
const notes = await this.notesRepository.find({ const notes = await this.notesRepository.find({
where: { where: {
userId: user.id, userId: user.id,
renoteId: IsNull(), renoteId: IsNull(),
visibility: In(['public', 'home']), visibility: In(['public', 'home']),
}, },
order: { id: -1 }, order: { id: -1 },
take: 20, take: 20,
}); });
const feed = new Feed({ const feed = new Feed({
id: author.link, id: author.link,
title: `${author.name} (@${user.username}@${this.config.host})`, title: `${author.name} (@${user.username}@${this.config.host})`,
updated: notes.length !== 0 ? this.idService.parse(notes[0].id).date : undefined, updated: notes.length !== 0 ? this.idService.parse(notes[0].id).date : undefined,
generator: 'Sharkey', generator: 'Sharkey',
description: `${user.notesCount} Notes, ${profile.followingVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.followersVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`, description: `${user.notesCount} Notes, ${profile.followingVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.followersVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
link: author.link, link: author.link,
image: user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user), image: user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user),
feedLinks: { feedLinks: {
json: `${author.link}.json`, json: `${author.link}.json`,
atom: `${author.link}.atom`, atom: `${author.link}.atom`,
}, },
author, author,
copyright: user.name ?? user.username, copyright: user.name ?? user.username,
}); });
for (const note of notes) { for (const note of notes) {
const files = note.fileIds.length > 0 ? await this.driveFilesRepository.findBy({ const files = note.fileIds.length > 0 ? await this.driveFilesRepository.findBy({
id: In(note.fileIds), id: In(note.fileIds),
}) : []; }) : [];
const file = files.find(file => file.type.startsWith('image/')); const file = files.find(file => file.type.startsWith('image/'));
const text = note.text; const text = note.text;
feed.addItem({ feed.addItem({
title: `New note by ${author.name}`, title: `New note by ${author.name}`,
link: `${this.config.url}/notes/${note.id}`, link: `${this.config.url}/notes/${note.id}`,
date: this.idService.parse(note.id).date, date: this.idService.parse(note.id).date,
description: note.cw ?? undefined, description: note.cw ?? undefined,
content: text ? this.mfmService.toHtml(mfmParse(text), JSON.parse(note.mentionedRemoteUsers)) ?? undefined : undefined, content: text ? this.mfmService.toHtml(mfmParse(text), JSON.parse(note.mentionedRemoteUsers)) ?? undefined : undefined,
image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined, image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined,
}); });
} }
return feed; return feed;
} */
}
} }

View File

@ -133,13 +133,13 @@ describe('Webリソース', () => {
}); });
describe.each([ describe.each([
{ ext: 'rss', type: 'application/rss+xml; charset=utf-8' }, /* { ext: 'rss', type: 'application/rss+xml; charset=utf-8' },
{ ext: 'atom', type: 'application/atom+xml; charset=utf-8' }, { ext: 'atom', type: 'application/atom+xml; charset=utf-8' },
{ ext: 'json', type: 'application/json; charset=utf-8' }, { ext: 'json', type: 'application/json; charset=utf-8' },*/
])('/@:username.$ext', ({ ext, type }) => { ])('/@:username.$ext', ({ ext, type }) => {
const path = (username: string): string => `/@${username}.${ext}`; const path = (username: string): string => `/@${username}.${ext}`;
test('がGETできる。', async () => await ok({ /* test('GET', async () => await ok({
path: path(alice.username), path: path(alice.username),
type, type,
})); }));
@ -161,7 +161,7 @@ describe('Webリソース', () => {
test('MFMを含まない。', async () => { test('MFMを含まない。', async () => {
const content = await simpleGet(path(alice.username), "*/*", undefined, res => res.text()); const content = await simpleGet(path(alice.username), "*/*", undefined, res => res.text());
const _body: unknown = content.body; /* const _body: unknown = content.body;
// JSONフィードのときは改めて文字列化する // JSONフィードのときは改めて文字列化する
const body: string = typeof (_body) === "object" ? JSON.stringify(_body) : _body as string; const body: string = typeof (_body) === "object" ? JSON.stringify(_body) : _body as string;
@ -169,7 +169,7 @@ describe('Webリソース', () => {
throw new Error("MFM shouldn't be included"); throw new Error("MFM shouldn't be included");
} }
}); });
}) })*/
}); });
describe.each([{ path: '/api/foo' }])('$path', ({ path }) => { describe.each([{ path: '/api/foo' }])('$path', ({ path }) => {