Skip to content

Commit

Permalink
fix 7891331
Browse files Browse the repository at this point in the history
  • Loading branch information
caipira113 committed Nov 9, 2023
1 parent 43d7469 commit ae4004c
Showing 1 changed file with 47 additions and 46 deletions.
93 changes: 47 additions & 46 deletions packages/backend/src/core/AvatarDecorationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,56 +137,57 @@ export class AvatarDecorationService implements OnApplicationShutdown {
});

const userData: any = await res.json();
const avatarDecorations = userData.avatarDecorations[0];

if (avatarDecorations != null) {
const avatarDecorationId = avatarDecorations.id;
const instanceHost = instance?.host;
const decorationApiUrl = `https://${instanceHost}/api/get-avatar-decorations`;
const allRes = await this.httpRequestService.send(decorationApiUrl, {
method: 'POST',
headers: { "Content-Type": "application/json" },
body: JSON.stringify({}),
});

const allDecorations: any = await allRes.json();
let name;
let description;
const avatarDecorations = userData.avatarDecorations?.[0];

for (const decoration of allDecorations) {
if (decoration.id == avatarDecorationId) {
name = decoration.name;
description = decoration.description;
break;
}
}

const existingDecoration = await this.avatarDecorationsRepository.findOneBy({ host: userHost, remoteId: avatarDecorationId });

const decorationData = {
name: name,
description: description,
url: this.getProxiedUrl(avatarDecorations.url, 'static'),
remoteId: avatarDecorationId,
host: userHost,
};
if (!avatarDecorations) {
return;
}

if (existingDecoration == null) {
await this.create(decorationData);
} else {
await this.update(existingDecoration.id, decorationData);
const avatarDecorationId = avatarDecorations.id;
const instanceHost = instance?.host;
const decorationApiUrl = `https://${instanceHost}/api/get-avatar-decorations`;
const allRes = await this.httpRequestService.send(decorationApiUrl, {
method: 'POST',
headers: {"Content-Type": "application/json"},

Check failure on line 151 in packages/backend/src/core/AvatarDecorationService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

A space is required after '{'

Check failure on line 151 in packages/backend/src/core/AvatarDecorationService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

A space is required before '}'
body: JSON.stringify({}),
});
const allDecorations: any = await allRes.json();
let name;
let description;
for (const decoration of allDecorations) {
if (decoration.id == avatarDecorationId) {

Check failure on line 158 in packages/backend/src/core/AvatarDecorationService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

Expected '===' and instead saw '=='
name = decoration.name;
description = decoration.description;
break;
}

const findDecoration = await this.avatarDecorationsRepository.findOneBy({ host: userHost, remoteId: avatarDecorationId });
const updates = {} as Partial<MiUser>;
updates.avatarDecorations = [{
id: findDecoration?.id ?? '',
angle: avatarDecorations.angle ?? 0,
flipH: avatarDecorations.flipH ?? false,
}];

await this.usersRepository.update({ id: user.id }, updates);
}
const existingDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
remoteId: avatarDecorationId
});
const decorationData = {
name: name,
description: description,
url: this.getProxiedUrl(avatarDecorations.url, 'static'),
remoteId: avatarDecorationId,
host: userHost,
};
if (existingDecoration == null) {
await this.create(decorationData);
} else {
await this.update(existingDecoration.id, decorationData);
}
const findDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
remoteId: avatarDecorationId
});
const updates = {} as Partial<MiUser>;
updates.avatarDecorations = [{
id: findDecoration?.id ?? '',
angle: avatarDecorations.angle ?? 0,
flipH: avatarDecorations.flipH ?? false,
}];
await this.usersRepository.update({id: user.id}, updates);

Check failure on line 190 in packages/backend/src/core/AvatarDecorationService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

A space is required after '{'

Check failure on line 190 in packages/backend/src/core/AvatarDecorationService.ts

View workflow job for this annotation

GitHub Actions / lint (backend)

A space is required before '}'
}

@bindThis
Expand Down

0 comments on commit ae4004c

Please sign in to comment.