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
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 user = await this.usersRepository.findOneBy({
usernameLower: username.toLowerCase(),
@ -496,7 +496,7 @@ export class ClientServerService {
return user && await this.feedService.packFeed(user);
};
// Atom
/* // Atom
fastify.get<{ Params: { user?: string; } }>('/@:user.atom', async (request, reply) => {
if (request.params.user == null) return await renderBase(reply);
@ -540,7 +540,7 @@ export class ClientServerService {
return;
}
});
*/
//#region SSR (for crawlers)
// User
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()
export class FeedService {
constructor(
@Inject(DI.config)
private config: Config,
constructor(
@Inject(DI.config)
private config: Config,
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
@Inject(DI.userProfilesRepository)
private userProfilesRepository: UserProfilesRepository,
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
@Inject(DI.driveFilesRepository)
private driveFilesRepository: DriveFilesRepository,
private userEntityService: UserEntityService,
private driveFileEntityService: DriveFileEntityService,
private idService: IdService,
private mfmService: MfmService,
) {
}
private userEntityService: UserEntityService,
private driveFileEntityService: DriveFileEntityService,
private idService: IdService,
private mfmService: MfmService,
) {
}
@bindThis
public async packFeed(user: MiUser) {
const author = {
link: `${this.config.url}/@${user.username}`,
name: user.name ?? user.username,
};
@bindThis
public async packFeed(user: MiUser) {
// フィード生成を無効化
throw new Error("フィード生成は無効化されています");
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
// フィード生成のロジックはここでコメントアウトまたは削除します
/*
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
const notes = await this.notesRepository.find({
where: {
userId: user.id,
renoteId: IsNull(),
visibility: In(['public', 'home']),
},
order: { id: -1 },
take: 20,
});
const notes = await this.notesRepository.find({
where: {
userId: user.id,
renoteId: IsNull(),
visibility: In(['public', 'home']),
},
order: { id: -1 },
take: 20,
});
const feed = new Feed({
id: author.link,
title: `${author.name} (@${user.username}@${this.config.host})`,
updated: notes.length !== 0 ? this.idService.parse(notes[0].id).date : undefined,
generator: 'Sharkey',
description: `${user.notesCount} Notes, ${profile.followingVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.followersVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
link: author.link,
image: user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user),
feedLinks: {
json: `${author.link}.json`,
atom: `${author.link}.atom`,
},
author,
copyright: user.name ?? user.username,
});
const feed = new Feed({
id: author.link,
title: `${author.name} (@${user.username}@${this.config.host})`,
updated: notes.length !== 0 ? this.idService.parse(notes[0].id).date : undefined,
generator: 'Sharkey',
description: `${user.notesCount} Notes, ${profile.followingVisibility === 'public' ? user.followingCount : '?'} Following, ${profile.followersVisibility === 'public' ? user.followersCount : '?'} Followers${profile.description ? ` · ${profile.description}` : ''}`,
link: author.link,
image: user.avatarUrl ?? this.userEntityService.getIdenticonUrl(user),
feedLinks: {
json: `${author.link}.json`,
atom: `${author.link}.atom`,
},
author,
copyright: user.name ?? user.username,
});
for (const note of notes) {
const files = note.fileIds.length > 0 ? await this.driveFilesRepository.findBy({
id: In(note.fileIds),
}) : [];
const file = files.find(file => file.type.startsWith('image/'));
const text = note.text;
for (const note of notes) {
const files = note.fileIds.length > 0 ? await this.driveFilesRepository.findBy({
id: In(note.fileIds),
}) : [];
const file = files.find(file => file.type.startsWith('image/'));
const text = note.text;
feed.addItem({
title: `New note by ${author.name}`,
link: `${this.config.url}/notes/${note.id}`,
date: this.idService.parse(note.id).date,
description: note.cw ?? undefined,
content: text ? this.mfmService.toHtml(mfmParse(text), JSON.parse(note.mentionedRemoteUsers)) ?? undefined : undefined,
image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined,
});
}
feed.addItem({
title: `New note by ${author.name}`,
link: `${this.config.url}/notes/${note.id}`,
date: this.idService.parse(note.id).date,
description: note.cw ?? undefined,
content: text ? this.mfmService.toHtml(mfmParse(text), JSON.parse(note.mentionedRemoteUsers)) ?? undefined : undefined,
image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined,
});
}
return feed;
}
return feed;
*/
}
}

View File

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