mirror of
https://github.com/outline/outline.git
synced 2026-12-05 10:45:07 +03:00
fix: Avatar upload (#11624)
* fix: Avatar upload * Restore internal public ACL
This commit is contained in:
1 parent
371665b35c
commit
749bf49ebe
3 files changed
+24
-4
No files matched your search
@@ -173,6 +173,13 @@ export default async function userProvisioner(
|
||||
);
|
||||
});
|
||||
|
||||
if (avatarUrl && !existingUser.getFlag(UserFlag.AvatarUpdated)) {
|
||||
await new UploadUserAvatarTask().schedule({
|
||||
userId: existingUser.id,
|
||||
avatarUrl,
|
||||
});
|
||||
}
|
||||
|
||||
if (isInvite) {
|
||||
const inviter = await existingUser.$get("invitedBy");
|
||||
if (inviter) {
|
||||
|
||||
@@ -40,7 +40,7 @@ export default class UploadTeamAvatarTask extends BaseTask<Props> {
|
||||
});
|
||||
|
||||
if (attachment) {
|
||||
await team.update({ avatarUrl: attachment.url });
|
||||
await team.update({ avatarUrl: attachment.redirectUrl });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createHash } from "node:crypto";
|
||||
import { AttachmentPreset } from "@shared/types";
|
||||
import attachmentCreator from "@server/commands/attachmentCreator";
|
||||
import { createContext } from "@server/context";
|
||||
import { User } from "@server/models";
|
||||
import { Attachment, User } from "@server/models";
|
||||
import { BaseTask, TaskPriority } from "./base/BaseTask";
|
||||
|
||||
type Props = {
|
||||
@@ -24,11 +24,24 @@ export default class UploadUserAvatarTask extends BaseTask<Props> {
|
||||
|
||||
const hash = createHash("sha256").update(props.avatarUrl).digest("hex");
|
||||
|
||||
// If the user's avatar URL already contains this hash, skip the upload
|
||||
// If the user's avatar URL already contains this hash, skip the upload.
|
||||
// This handles old-style canonical S3 URLs that include the hash in the path.
|
||||
if (user.avatarUrl?.includes(hash)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// For redirect-style avatar URLs, check if the underlying attachment
|
||||
// already has this hash in its key to avoid re-uploading the same avatar.
|
||||
const redirectMatch = user.avatarUrl?.match(
|
||||
/attachments\.redirect\?id=([^&]+)/
|
||||
);
|
||||
if (redirectMatch) {
|
||||
const existing = await Attachment.findByPk(redirectMatch[1]);
|
||||
if (existing?.key.endsWith(`/${hash}`)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const attachment = await attachmentCreator({
|
||||
name: hash,
|
||||
url: props.avatarUrl,
|
||||
@@ -38,7 +51,7 @@ export default class UploadUserAvatarTask extends BaseTask<Props> {
|
||||
});
|
||||
|
||||
if (attachment) {
|
||||
await user.update({ avatarUrl: attachment.url });
|
||||
await user.update({ avatarUrl: attachment.redirectUrl });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user