Allow file access not in Attachments table (#5876)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Tom Moor
2023-09-24 09:43:37 -04:00
committed by GitHub
parent d0bb6c6a41
commit e50e0bba53
9 changed files with 181 additions and 85 deletions

View File

@@ -33,6 +33,34 @@ export default class AttachmentHelper {
return `${keyPrefix}/${name}`;
}
/**
* Parse a key into its constituent parts
*
* @param key The key to parse
* @returns The constituent parts
*/
static parseKey(key: string): {
bucket: string;
userId: string;
id: string;
fileName: string | undefined;
isPublicBucket: boolean;
} {
const parts = key.split("/");
const bucket = parts[0];
const userId = parts[1];
const id = parts[2];
const [fileName] = parts.length > 3 ? parts.slice(-1) : [];
return {
bucket,
userId,
id,
fileName,
isPublicBucket: bucket === Buckets.avatars || bucket === Buckets.public,
};
}
/**
* Get the ACL to use for a given attachment preset
*