mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
42959d66db
* 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
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { IntegrationService, IntegrationType } from "@shared/types";
|
|
import { Integration } from "@server/models";
|
|
import { Buckets } from "@server/models/helpers/AttachmentHelper";
|
|
import { BaseTask, TaskPriority } from "@server/queues/tasks/base/BaseTask";
|
|
import FileStorage from "@server/storage/files";
|
|
|
|
type Props = {
|
|
/** The integrationId to operate on */
|
|
integrationId: string;
|
|
/** The original logoUrl from Linear */
|
|
logoUrl: string;
|
|
};
|
|
|
|
/**
|
|
* A task that uploads the provided logoUrl to storage and updates the
|
|
* Linear integration record with the new url.
|
|
*/
|
|
export default class UploadLinearWorkspaceLogoTask extends BaseTask<Props> {
|
|
public async perform(props: Props) {
|
|
const integration = await Integration.scope("withAuthentication").findByPk<
|
|
Integration<IntegrationType.Embed>
|
|
>(props.integrationId);
|
|
if (!integration || integration.service !== IntegrationService.Linear) {
|
|
return;
|
|
}
|
|
|
|
const res = await FileStorage.storeFromUrl(
|
|
props.logoUrl,
|
|
`${Buckets.avatars}/${integration.teamId}/${crypto.randomUUID()}`,
|
|
"public-read",
|
|
{
|
|
headers: {
|
|
Authorization: `Bearer ${integration.authentication.token}`,
|
|
},
|
|
}
|
|
);
|
|
|
|
if (res?.url) {
|
|
integration.settings.linear!.workspace.logoUrl = res.url;
|
|
integration.changed("settings", true);
|
|
await integration.save();
|
|
}
|
|
}
|
|
|
|
public get options() {
|
|
return {
|
|
attempts: 3,
|
|
priority: TaskPriority.Normal,
|
|
};
|
|
}
|
|
}
|