Update show.ts

This commit is contained in:
syuilo 2025-09-17 19:58:18 +09:00
parent 89302ed248
commit 4d6ff822c4
1 changed files with 2 additions and 35 deletions

View File

@ -18,13 +18,9 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { bindThis } from '@/decorators.js';
import { ApiError } from '../../error.js';
import { IdentifiableError } from '@/misc/identifiable-error.js';
import { FetchAllowSoftFailMask } from '@/core/activitypub/misc/check-against-url.js';
import * as Acct from '@/misc/acct.js';
import { IsNull } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { NotesRepository, UsersRepository } from '@/models/_.js';
import { ApiError } from '../../error.js';
export const meta = {
tags: ['federation'],
@ -113,9 +109,6 @@ export const paramDef = {
@Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor(
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
private utilityService: UtilityService,
private userEntityService: UserEntityService,
private noteEntityService: NoteEntityService,
@ -144,7 +137,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
let local = await this.mergePack(me, ...await Promise.all([
this.apDbResolverService.getUserFromApId(uri).then(async x => x ?? await this.getUserFromProfileUrl(uri)),
this.apDbResolverService.getUserFromApId(uri),
this.apDbResolverService.getNoteFromApId(uri),
]));
if (local != null) return local;
@ -207,32 +200,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
);
}
// To keep consistency with ap/show from external server,
// this function will handle `https://local.instance/@user`
// profile url to resolve user.
@bindThis
private async getUserFromProfileUrl(url: string): Promise<MiUser | null | undefined> {
if (!this.utilityService.isUriLocal(url)) {
return null;
}
const uri = new URL(url);
const pathComponents = uri.pathname.split('/').filter(Boolean);
if (pathComponents.length === 1 && pathComponents[0].startsWith('@')) {
const acct = Acct.parse(pathComponents[0]);
// normalize acct host
if (this.utilityService.isSelfHost(acct.host)) acct.host = null;
return await this.usersRepository.findOneBy({
usernameLower: acct.username.toLowerCase(),
host: acct.host ?? IsNull(),
isSuspended: false,
});
}
return null;
}
@bindThis
private async mergePack(me: MiLocalUser | null | undefined, user: MiUser | null | undefined, note: MiNote | null | undefined): Promise<SchemaType<typeof meta.res> | null> {
if (user != null) {