mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-07 05:13:01 +00:00
Refactor R2 key prefix for deterministic identifiers
This commit is contained in:
1 parent
00b0e85438
commit
c02db755ac
6 files changed
+42
-12
No files matched your search
@@ -211,13 +211,13 @@ function guessExtension(file) {
|
||||
}
|
||||
}
|
||||
|
||||
export function buildR2Key(npub, file) {
|
||||
const now = new Date();
|
||||
const year = now.getUTCFullYear();
|
||||
const month = String(now.getUTCMonth() + 1).padStart(2, "0");
|
||||
export function buildR2Key(npub, file, identifier = "") {
|
||||
const safeNpub = String(npub || "")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, "");
|
||||
const safeIdentifier = String(identifier || "")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]/g, "");
|
||||
const baseName = typeof file?.name === "string" ? file.name : "video";
|
||||
const withoutExt = baseName.replace(/\.[^/.]+$/, "");
|
||||
const slug = withoutExt
|
||||
@@ -226,7 +226,8 @@ export function buildR2Key(npub, file) {
|
||||
.replace(/^-+|-+$/g, "");
|
||||
const safeSlug = slug || "video";
|
||||
const ext = guessExtension(file);
|
||||
return `u/${safeNpub}/${year}/${month}/${safeSlug}.${ext}`;
|
||||
const namespace = safeIdentifier || "uploads";
|
||||
return `u/${safeNpub}/${namespace}/${safeSlug}.${ext}`;
|
||||
}
|
||||
|
||||
export function buildPublicUrl(baseUrl, key) {
|
||||
|
||||
Reference in new issue
Block a user