mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
* wip * Implementation complete * tidying * test * Address feedback * Remove duplicative retry logic from UpdateDocumentsPopularityScoreTask. Now that we're split across many runs this is not neccessary * Refactor to subclass, config to instance * Refactor BaseTask to named export * fix: Missing partition * tsc * Feedback
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { randomUUID } from "crypto";
|
|
import { Team } from "@server/models";
|
|
import { Buckets } from "@server/models/helpers/AttachmentHelper";
|
|
import FileStorage from "@server/storage/files";
|
|
import { BaseTask, TaskPriority } from "./base/BaseTask";
|
|
|
|
type Props = {
|
|
/** The teamId to operate on */
|
|
teamId: string;
|
|
/** The original avatarUrl from the SSO provider */
|
|
avatarUrl: string;
|
|
};
|
|
|
|
/**
|
|
* A task that uploads the provided avatarUrl to S3 storage and updates the
|
|
* team's record with the new url.
|
|
*/
|
|
export default class UploadTeamAvatarTask extends BaseTask<Props> {
|
|
public async perform(props: Props) {
|
|
const team = await Team.findByPk(props.teamId, {
|
|
rejectOnEmpty: true,
|
|
});
|
|
|
|
const res = await FileStorage.storeFromUrl(
|
|
props.avatarUrl,
|
|
`${Buckets.avatars}/${team.id}/${randomUUID()}`,
|
|
"public-read"
|
|
);
|
|
|
|
if (res?.url) {
|
|
await team.update({ avatarUrl: res.url });
|
|
}
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
attempts: 3,
|
|
priority: TaskPriority.Normal,
|
|
};
|
|
}
|
|
}
|