mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 11:52:25 +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
@@ -6,7 +6,10 @@ import {
|
||||
getVideoNoteErrorMessage,
|
||||
normalizeVideoNotePayload,
|
||||
} from "../../services/videoNotePayload.js";
|
||||
import { createTorrentMetadata } from "../../utils/torrentHash.js";
|
||||
import {
|
||||
calculateTorrentInfoHash,
|
||||
createTorrentMetadata,
|
||||
} from "../../utils/torrentHash.js";
|
||||
import { sanitizeBucketName } from "../../storage/r2-mgmt.js";
|
||||
import { buildR2Key, buildPublicUrl } from "../../r2.js";
|
||||
import { buildS3ObjectUrl } from "../../services/s3Service.js";
|
||||
@@ -524,7 +527,8 @@ export class UploadModal {
|
||||
if (this.videoUploadId !== currentUploadId) return;
|
||||
|
||||
// 2. Determine Keys
|
||||
const videoKey = buildR2Key(npub, file);
|
||||
const identifier = await this.resolveUploadIdentifier(file);
|
||||
const videoKey = buildR2Key(npub, file, identifier);
|
||||
const baseDomain = bucketEntry.publicBaseUrl;
|
||||
|
||||
// Note: buildPublicUrl works for both if the base is clean
|
||||
@@ -1088,6 +1092,19 @@ export class UploadModal {
|
||||
};
|
||||
}
|
||||
|
||||
async resolveUploadIdentifier(file) {
|
||||
try {
|
||||
const infoHash = await calculateTorrentInfoHash(file);
|
||||
const normalized = normalizeInfoHash(infoHash);
|
||||
if (isValidInfoHash(normalized)) {
|
||||
return normalized;
|
||||
}
|
||||
} catch (hashErr) {
|
||||
userLogger.warn("Failed to precompute info hash for storage key:", hashErr);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
async handleExternalFlow(metadata) {
|
||||
metadata.url = this.inputs.url?.value?.trim() || "";
|
||||
metadata.magnet = this.inputs.magnet?.value?.trim() || "";
|
||||
|
||||
Reference in new issue
Block a user