cleanup(backend): refactor UtilityService (MisskeyIO#858)

This commit is contained in:
あわわわとーにゅ 2024-12-28 11:39:48 +09:00 committed by GitHub
parent cb73368c83
commit ff195d4f8d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 106 additions and 126 deletions

View file

@ -94,7 +94,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
if (ps.host == null) {
q.andWhere('emoji.host IS NOT NULL');
} else {
q.andWhere('emoji.host = :host', { host: this.utilityService.toPuny(ps.host) });
q.andWhere('emoji.host = :host', { host: this.utilityService.normalizeHost(ps.host) });
}
if (ps.query) {

View file

@ -36,7 +36,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private fetchInstanceMetadataService: FetchInstanceMetadataService,
) {
super(meta, paramDef, async (ps, me) => {
const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) });
const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.normalizeHost(ps.host) });
if (instance == null) {
throw new Error('instance not found');

View file

@ -40,7 +40,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private moderationLogService: ModerationLogService,
) {
super(meta, paramDef, async (ps, me) => {
const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.toPuny(ps.host) });
const instance = await this.instancesRepository.findOneBy({ host: this.utilityService.normalizeHost(ps.host) });
if (instance == null) {
throw new Error('instance not found');

View file

@ -114,7 +114,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private async fetchAny(uri: string, me: MiLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
// ブロックしてたら中断
const fetchedMeta = await this.metaService.fetch();
if (this.utilityService.isBlockedHost(fetchedMeta.blockedHosts, this.utilityService.extractDbHost(uri))) return null;
if (this.utilityService.isItemListedIn(this.utilityService.extractHost(uri), fetchedMeta.blockedHosts)) return null;
let local = await this.mergePack(me, ...await Promise.all([
this.apDbResolverService.getUserFromApId(uri),
@ -122,7 +122,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
]));
if (local != null) return local;
const host = this.utilityService.extractDbHost(uri);
const host = this.utilityService.extractHost(uri);
// local object, not found in db? fail
if (this.utilityService.isSelfHost(host)) return null;

View file

@ -41,7 +41,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
) {
super(meta, paramDef, async (ps, me) => {
const instance = await this.instancesRepository
.findOneBy({ host: this.utilityService.toPuny(ps.host) });
.findOneBy({ host: this.utilityService.normalizeHost(ps.host) });
return instance ? await this.instanceEntityService.pack(instance, me) : null;
});

View file

@ -87,7 +87,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const user = await this.usersRepository.findOneBy(ps.userId != null
? { id: ps.userId }
: { usernameLower: ps.username!.toLowerCase(), host: this.utilityService.toPunyNullable(ps.host) ?? IsNull() });
: { usernameLower: ps.username!.toLowerCase(), host: ps.host ? this.utilityService.normalizeHost(ps.host) : IsNull() });
if (user == null) {
throw new ApiError(meta.errors.noSuchUser);

View file

@ -99,7 +99,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => {
const user = await this.usersRepository.findOneBy(ps.userId != null
? { id: ps.userId }
: { usernameLower: ps.username!.toLowerCase(), host: this.utilityService.toPunyNullable(ps.host) ?? IsNull() });
: { usernameLower: ps.username!.toLowerCase(), host: ps.host ? this.utilityService.normalizeHost(ps.host) : IsNull() });
if (user == null) {
throw new ApiError(meta.errors.noSuchUser);