This commit is contained in:
mattyatea 2024-05-06 07:41:47 +09:00
parent 024ce3c881
commit 9f60e186b0
5 changed files with 24 additions and 81 deletions

View File

@ -0,0 +1,11 @@
export class AvatardecorationFed1714831133156 {
name = 'AvatardecorationFed1714831133156'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "avatar_decoration" DROP COLUMN "host"`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "avatar_decoration" ADD "host" character varying(256)`);
}
}

View File

@ -39,8 +39,6 @@ import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.j
import type { AccountMoveService } from '@/core/AccountMoveService.js'; import type { AccountMoveService } from '@/core/AccountMoveService.js';
import { checkHttps } from '@/misc/check-https.js'; import { checkHttps } from '@/misc/check-https.js';
import { isNotNull } from '@/misc/is-not-null.js'; import { isNotNull } from '@/misc/is-not-null.js';
import { HttpRequestService } from '@/core/HttpRequestService.js';
import { AvatarDecorationService } from '@/core/AvatarDecorationService.js';
import { getApId, getApType, getOneApHrefNullable, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js'; import { getApId, getApType, getOneApHrefNullable, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js';
import { extractApHashtags } from './tag.js'; import { extractApHashtags } from './tag.js';
import type { OnModuleInit } from '@nestjs/common'; import type { OnModuleInit } from '@nestjs/common';
@ -79,8 +77,6 @@ export class ApPersonService implements OnModuleInit {
private apLoggerService: ApLoggerService; private apLoggerService: ApLoggerService;
private accountMoveService: AccountMoveService; private accountMoveService: AccountMoveService;
private logger: Logger; private logger: Logger;
private httpRequestService: HttpRequestService;
private avatarDecorationService: AvatarDecorationService;
constructor( constructor(
private moduleRef: ModuleRef, private moduleRef: ModuleRef,
@ -130,8 +126,6 @@ export class ApPersonService implements OnModuleInit {
this.apLoggerService = this.moduleRef.get('ApLoggerService'); this.apLoggerService = this.moduleRef.get('ApLoggerService');
this.accountMoveService = this.moduleRef.get('AccountMoveService'); this.accountMoveService = this.moduleRef.get('AccountMoveService');
this.logger = this.apLoggerService.logger; this.logger = this.apLoggerService.logger;
this.httpRequestService = this.moduleRef.get('HttpRequestService');
this.avatarDecorationService = this.moduleRef.get('AvatarDecorationService');
} }
private punyHost(url: string): string { private punyHost(url: string): string {
@ -233,73 +227,21 @@ export class ApPersonService implements OnModuleInit {
return null; return null;
} }
private async resolveAvatarAndBanner(user: MiRemoteUser, host: string | null, icon: any, image: any): Promise<Partial<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'avatarUrl' | 'bannerUrl' | 'avatarBlurhash' | 'bannerBlurhash'>>> { private async resolveAvatarAndBanner(user: MiRemoteUser, icon: any, image: any): Promise<Pick<MiRemoteUser, 'avatarId' | 'bannerId' | 'avatarUrl' | 'bannerUrl' | 'avatarBlurhash' | 'bannerBlurhash'>> {
if (user == null) throw new Error('failed to create user: user is null');
const [avatar, banner] = await Promise.all([icon, image].map(img => { const [avatar, banner] = await Promise.all([icon, image].map(img => {
// if we have an explicitly missing image, return an if (img == null) return null;
// explicitly-null set of values if (user == null) throw new Error('failed to create user: user is null');
if ((img == null) || (typeof img === 'object' && img.url == null)) {
return { id: null, url: null, blurhash: null };
}
return this.apImageService.resolveImage(user, img).catch(() => null); return this.apImageService.resolveImage(user, img).catch(() => null);
})); }));
/*
we don't want to return nulls on errors! if the database fields
are already null, nothing changes; if the database has old
values, we should keep those. The exception is if the remote has
actually removed the images: in that case, the block above
returns the special {id:null}&c value, and we return those
*/
return { return {
...( avatar ? { avatarId: avatar?.id ?? null,
avatarId: avatar.id, bannerId: banner?.id ?? null,
avatarUrl: avatar.url ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null, avatarUrl: avatar ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null,
avatarBlurhash: avatar.blurhash, bannerUrl: banner ? this.driveFileEntityService.getPublicUrl(banner) : null,
} : {}), avatarBlurhash: avatar?.blurhash ?? null,
...( banner ? { bannerBlurhash: banner?.blurhash ?? null,
bannerId: banner.id,
bannerUrl: banner.url ? this.driveFileEntityService.getPublicUrl(banner) : null,
bannerBlurhash: banner.blurhash,
} : {}),
}; };
if (host) {
const i = await this.federatedInstanceService.fetch(host);
console.log('avatarDecorationFetch: start');
if (i.softwareName === 'misskey') {
const remoteUserId = user.uri.split('/users/')[1];
const userMetaRequest = await this.httpRequestService.send(`https://${i.host}/api/users/show`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
'userId': remoteUserId,
}),
});
const res: any = await userMetaRequest.json();
if (res.avatarDecorations) {
const localDecos = await this.avatarDecorationService.getAll();
// ローカルのデコレーションとして登録する
for (const deco of res.avatarDecorations) {
if (localDecos.some((v) => v.id === deco.id)) continue;
await this.avatarDecorationService.create({
id: deco.id,
updatedAt: null,
url: deco.url,
name: `import_${host}_${deco.id}`,
description: `Imported from ${host}`,
host: host,
});
}
Object.assign(returnData, { avatarDecorations: res.avatarDecorations });
}
}
}
return returnData;
} }
/** /**

View File

@ -36,11 +36,6 @@ export class MiAvatarDecoration {
default: '', default: '',
}) })
public category: string; public category: string;
@Column('varchar', {
length: 256,
nullable: true,
})
public host: string;
// TODO: 定期ジョブで存在しなくなったロールIDを除去するようにする // TODO: 定期ジョブで存在しなくなったロールIDを除去するようにする
@Column('varchar', { @Column('varchar', {

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: syuilo and misskey-project * SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
@ -88,9 +88,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
const avatarDecorations = await this.avatarDecorationService.getAll(true); const avatarDecorations = await this.avatarDecorationService.getAll(true);
const filteredAvatarDecorations = avatarDecorations.filter(avatarDecoration => avatarDecoration.host === null); return avatarDecorations.map(avatarDecoration => ({
console.log(filteredAvatarDecorations);
return filteredAvatarDecorations.map(avatarDecoration => ({
id: avatarDecoration.id, id: avatarDecoration.id,
createdAt: this.idService.parse(avatarDecoration.id).date.toISOString(), createdAt: this.idService.parse(avatarDecoration.id).date.toISOString(),
updatedAt: avatarDecoration.updatedAt?.toISOString() ?? null, updatedAt: avatarDecoration.updatedAt?.toISOString() ?? null,

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: syuilo and misskey-project * SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
@ -70,10 +70,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
const decorations = await this.avatarDecorationService.getAll(true); const decorations = await this.avatarDecorationService.getAll(true);
const allRoles = await this.roleService.getRoles(); const allRoles = await this.roleService.getRoles();
// Filter decorations where host is null return decorations.map(decoration => ({
const filteredDecorations = decorations.filter(decoration => decoration.host === null);
return filteredDecorations.map(decoration => ({
id: decoration.id, id: decoration.id,
name: decoration.name, name: decoration.name,
description: decoration.description, description: decoration.description,