fix: Allow viewers to upload avatar (#4349)

* fix: Allow viewers to upload avatar

* DeleteAttachmentTask

* fix: Previous avatar should be deleted on change, if possible

* fix: Also cleanup team logo on change
This commit is contained in:
Tom Moor
2022-10-29 09:08:20 -04:00
committed by GitHub
parent 19e26ba402
commit 79cbe304da
7 changed files with 191 additions and 65 deletions

View File

@@ -1,13 +1,18 @@
import { uniq, compact } from "lodash";
const attachmentRegex = /\/api\/attachments\.redirect\?id=(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
const attachmentRedirectRegex = /\/api\/attachments\.redirect\?id=(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
const attachmentPublicRegex = /public\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
export default function parseAttachmentIds(text: string): string[] {
export default function parseAttachmentIds(
text: string,
includePublic = false
): string[] {
return uniq(
compact(
[...text.matchAll(attachmentRegex)].map(
(match) => match.groups && match.groups.id
)
[
...text.matchAll(attachmentRedirectRegex),
...(includePublic ? text.matchAll(attachmentPublicRegex) : []),
].map((match) => match.groups && match.groups.id)
)
);
}