mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
The team or user can be deleted before the async processor runs, so gracefully skip the avatar upload instead of throwing. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { Team, User } from "@server/models";
|
|
import type { Event, TeamEvent, UserEvent } from "@server/types";
|
|
import UploadTeamAvatarTask from "../tasks/UploadTeamAvatarTask";
|
|
import UploadUserAvatarTask from "../tasks/UploadUserAvatarTask";
|
|
import BaseProcessor from "./BaseProcessor";
|
|
|
|
export default class AvatarProcessor extends BaseProcessor {
|
|
static applicableEvents: Event["name"][] = ["users.create", "teams.create"];
|
|
|
|
async perform(event: UserEvent | TeamEvent) {
|
|
// The uploads are performed in a separate task to allow for retrying in the
|
|
// case of failures as it involves network calls to third party services.
|
|
|
|
if (event.name === "users.create") {
|
|
// The user may have been deleted before this processor runs.
|
|
const user = await User.findByPk(event.userId);
|
|
|
|
if (user?.avatarUrl) {
|
|
await new UploadUserAvatarTask().schedule({
|
|
userId: event.userId,
|
|
avatarUrl: user.avatarUrl,
|
|
});
|
|
}
|
|
}
|
|
|
|
if (event.name === "teams.create") {
|
|
// The team may have been deleted before this processor runs.
|
|
const team = await Team.findByPk(event.teamId);
|
|
|
|
if (team?.avatarUrl) {
|
|
await new UploadTeamAvatarTask().schedule({
|
|
teamId: event.teamId,
|
|
avatarUrl: team.avatarUrl,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|