Commit Graph
51 Commits
Author SHA1 Message Date
thePR0M3TH3ANandClaude Opus 4.8 f0eecec09d feat(delete): warn when a hosted file is left behind by locked storage
Deleting a video removes the Nostr note(s) but cleanup of the underlying R2/S3
object was silently skipped when storage was locked — leaving the file publicly
downloadable with no indication to the user. Now the delete flow surfaces a
clear heads-up when that happens, telling the user to unlock storage and delete
again (or remove the object from their bucket manually).

To make the signal accurate, deleteVideoStorage now resolves the affected object
keys BEFORE the credentials check (publicBaseUrl is available even while
locked). So "storage-locked" is reported only when there are genuinely hosted
objects to remove; an external-URL video (nothing on the user's bucket) returns
"no-matching-objects" and never triggers a false warning.

Tests (deleteVideoStorage via injected credentials/deleteObject): locked +
hosted object -> storage-locked; locked + external URL -> no-matching-objects
(no false alarm); unlocked -> actually deletes the object. Mutation-verified —
restoring the old credentials-first ordering misreports the external-URL case.

Build + full lint green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-20 12:21:49 -04:00
thePR0M3TH3ANandClaude Opus 4.8 573c9b00ef refactor(storage): extract helpers + verifyPublicAccess from r2Service (8/10)
File-size decomposition (no behavior change). Move the pure helpers
(normalizeInfoHash, isValidInfoHash, resolveUploadIdentifier, buildCorsGuidance,
createDefaultSettings, safeDecodeNpub) and the verifyPublicAccess flow (as an
instance-param function with a thin delegator) into js/services/r2ServiceHelpers.js.
Dropped the now-unused calculateTorrentInfoHash import from the service.

r2Service.js: 1376 -> 1192 lines (below its original 1194 baseline; re-recorded
to 1192).

Build + full unit suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-19 16:35:53 -04:00
thePR0M3TH3ANandClaude Opus 4.8 fdebf05e1a feat(s3): bring generic S3 to parity with R2 (cleanup + CORS guidance)
Two gaps where generic S3 trailed Cloudflare R2:

1. Object cleanup on delete/edit didn't work for generic S3. deleteVideoStorage
   built its client via makeR2Client, which hard-forces path-style and ignores
   the connection's forcePathStyle -- so vhost-style S3 deletes were misaddressed
   and cleanup silently failed (S3 users' deleted/edited files orphaned). It is
   now provider-aware (mirrors uploadFile): R2 -> makeR2Client (path-style),
   generic S3 -> makeS3Client honoring forcePathStyle. makeS3Client is now
   injectable for testing.

2. CORS guidance on upload failure was R2-only. Extracted isLikelyCorsError +
   a generic-S3 guidance builder into js/utils/uploadErrorHints.js (re-exported
   from r2Service for back-compat); s3UploadService now appends actionable CORS
   guidance on an opaque "Failed to fetch" too.

Generic S3 is now at functional parity with R2 for upload -> publish -> cleanup.

Tests: r2-delete-video-storage (adds generic-S3 forcePathStyle routing),
s3-upload-cors-guidance (new). Full suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-17 06:13:38 -04:00
thePR0M3TH3ANandClaude Opus 4.8 7f5dcd7e50 fix(upload): attach CORS guidance to direct upload failures
A new user's top first-upload failure is a missing R2 CORS policy (browser
PUT/POST blocked) -- and object-scoped R2 tokens often cannot auto-set CORS.
The connection test already surfaces buildCorsGuidance on the opaque
"Failed to fetch", but a user who skips the test and uploads directly got a
bare "Upload failed: Failed to fetch". The upload error handler now detects the
browser CORS/network rejection (isLikelyCorsError -- Chrome "Failed to fetch",
Firefox "NetworkError", Safari "Load failed") and appends the same actionable
guidance. Updated the R2 follow-up TODO (credential audit done; CORS reviewed).

Test: tests/services/r2-cors-error-classifier.test.mjs. Full suite green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-17 05:47:12 -04:00
thePR0M3TH3ANandClaude Opus 4.8 95b51b6e61 feat(r2): delete the underlying storage objects when a video is deleted
Deleting a video removed the Nostr note but left the actual file (plus its
thumbnail and .torrent) publicly downloadable at its R2/S3 URL forever — a
privacy gap and ongoing storage cost. Now the delete flow also removes the
backing objects, best-effort.

- collectVideoStorageKeys() (storagePointer.js): pure helper that derives the
  object keys (video + sibling .torrent + thumbnail) from a note, ONLY for URLs
  under the owner's bucket base — external/3rd-party URLs are never returned.
- R2Service.deleteVideoStorage(): resolves the owner's connection, and deletes
  those keys. Skips cleanly when storage is locked / no creds / no owned
  objects, and never throws (failures are recorded, not propagated) so storage
  cleanup can't block note deletion. R2Service class now exported for testing.
- app.handleDeleteModalConfirm: calls it after handleFullDeleteVideo succeeds.

Tests: tests/storage-key-collection.test.mjs (4),
tests/services/r2-delete-video-storage.test.mjs (4). Full suite green.

Note: superseded versions orphaned by past edits aren't retroactively cleaned;
edit-time cleanup (next) prevents new orphans going forward.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 22:09:57 -04:00
thePR0M3TH3ANandClaude Opus 4.8 3d6ffe997b fix(upload): surface thumbnail/.torrent upload failures to the user
These optional-asset uploads are non-fatal, but failures were warn-only — the
user got a silently-missing thumbnail or torrent with no signal. Both upload
services now emit a 'warning' status at the point of failure and append a note
to the final 'Published' status (downgraded to warning variant) listing what
failed. Cloudflare-upload audit #5.

Test: tests/services/s3-upload-optional-asset-failures.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:19:27 -04:00
thePR0M3TH3ANandClaude Opus 4.8 6b603cc21c fix(upload): surface an 'Analyzing' status during pre-upload file hashing
Computing the torrent info-hash (and the content-hash fallback) reads the entire
file before the upload starts and before any progress is emitted, so on
multi-GB videos there was a long silent pause that looked like a freeze. Both
upload services now emit an 'Analyzing video…' status when a full-file hash is
required (i.e. no valid info-hash was pre-supplied). Cloudflare-upload audit #2.

Test: tests/services/s3-upload-analyzing-status.test.mjs.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 20:14:21 -04:00
thePR0M3TH3ANandClaude Opus 4.8 066d98febb fix(upload): content-address storage keys to stop URL-first overwrites
buildR2Key fell back to a static "uploads" namespace (and "video" slug) when
no torrent info-hash was available, so two distinct URL-first uploads sharing a
filename produced the SAME R2/S3 key — the second silently overwrote the first
object while the first video note still pointed at that URL (data loss).
WebTorrent uploads were already safe because the info-hash namespaces the key.

Add computeStorageContentHash(file) in js/r2.js: when no info-hash is present it
derives a deterministic content-based namespace — full SHA-256 of the bytes for
files ≤512 MB (idempotent: re-uploading the same file reuses the key), and a
SHA-256 fingerprint over name/size/mtime + sampled head/tail bytes above that,
so we never buffer a multi-GB video in memory. Wired into BOTH upload paths
(r2Service + s3UploadService) via a new storageIdentifier kept separate from the
info-hash, so magnet generation is unchanged.

Test: tests/storage-key-collision.test.mjs (distinct same-named uploads get
distinct keys; same content is idempotent; large-file fingerprint path samples
edges without buffering and stays deterministic). Full unit suite green.

test_integrity_note:
  change_type: ["new_tests"]
  scenarios:
    - id: SCN-upload-key-no-collision
      given: "a URL-first upload with no torrent info-hash"
      when: "the storage key is derived (computeStorageContentHash -> buildR2Key)"
      then: "distinct same-named files get distinct keys, same content is idempotent, and no key uses the colliding 'uploads' namespace"
  observable_outcomes:
    - "returned key strings for real Blob/File content and a fake >512MB file"
  determinism_controls:
    - "fixed byte content; fake large file with stubbed slice() and fixed lastModified"
  anti_cheat_rationale:
    prevents:
      - "hard-coded return value"
      - "over-mocking internal logic"
  relaxation:
    did_relax_any_assertion: false

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-06-16 16:56:12 -04:00
thePR0M3TH3AN 419a3f419c Add storage pointer tags to video posts 2026-01-26 22:07:32 -05:00
thePR0M3TH3AN ee31e4318a Compute upload identifiers before building R2 keys 2026-01-26 21:43:39 -05:00
thePR0M3TH3AN c02db755ac Refactor R2 key prefix for deterministic identifiers 2026-01-26 12:47:05 -05:00
thePR0M3TH3AN 82986650ce Store video file fingerprints alongside series IDs 2026-01-26 12:25:54 -05:00
thePR0M3TH3AN 50ec850706 Merge pull request #1730 from PR0M3TH3AN/codex/add-unit-tests-for-r2service
R2Service: add DI for storage helpers and unit tests for bucket selection
2026-01-26 07:47:06 -05:00
thePR0M3TH3AN 84468cbed5 Add R2 bucket config tests 2026-01-26 07:46:54 -05:00
thePR0M3TH3AN 16b8656521 Fix R2 bucket resolution and add coverage 2026-01-26 07:40:23 -05:00
thePR0M3TH3AN 5759b9437a Use configured bucket for R2 verification 2026-01-26 07:37:24 -05:00
thePR0M3TH3AN ad0f58e328 Use meta bucket in R2 bucket resolution 2026-01-26 07:35:34 -05:00
thePR0M3TH3AN a1d27996f7 Handle locked R2 storage metadata 2026-01-26 07:26:52 -05:00
thePR0M3TH3AN 4e71b1d320 Add R2 CORS failure context logging 2026-01-25 22:00:22 -05:00
thePR0M3TH3AN 69dc281c04 Add debug logs for upload settings presence 2026-01-25 21:57:09 -05:00
thePR0M3TH3AN 1e2f6b989a Migrate legacy R2 settings to storage service 2026-01-25 21:33:00 -05:00
thePR0M3TH3AN 4248999294 Guard r2 settings bucket lookup 2026-01-25 21:07:54 -05:00
thePR0M3TH3AN 46161ccea2 Improve R2 CORS error guidance 2026-01-25 21:05:24 -05:00
thePR0M3TH3AN eac1e9a75d Normalize storage connection public URLs 2026-01-25 20:54:15 -05:00
google-labs-jules[bot] 070c054043 Refactor upload flow for immediate uploads and fix logging crash
- Refactored `UploadModal.js` to trigger uploads immediately on file selection.
- Added progress bars and result fields (Video URL, Magnet, Torrent) to the UI.
- Fixed a crash in `r2Service.js` caused by `userLogger.debug` usage.
- Exposed `prepareUpload` and `uploadFile` methods in `r2Service` and `s3UploadService` for granular control.
- Updated `upload-modal.html` with new UI elements.
2026-01-25 20:53:16 +00:00
thePR0M3TH3AN 15dea2bbf6 Add generic S3 connection support helpers 2026-01-24 12:39:56 -05:00
thePR0M3TH3AN e6ecbaf9e6 Add generic S3 multipart helpers 2026-01-23 20:02:15 -05:00
google-labs-jules[bot] e51f21681b feat: make r2Service generic and integrate storageService 2026-01-16 02:58:36 +00:00
google-labs-jules[bot] cf9d1c08be Refactor UploadModal to use StorageService for secure R2 credentials 2026-01-16 02:35:00 +00:00
google-labs-jules[bot] 5772ed1992 docs: add developer documentation to R2 upload service
Added comprehensive JSDoc comments to `js/services/r2Service.js` to explain the critical "Hybrid" hosting strategy and complex orchestration logic.

Key additions:
- File header explaining the service's role.
- Detailed documentation for `handleCloudflareUploadSubmit`, explaining the sequence of uploads and the construction of Magnet URIs with `ws` (WebSeed) and `xs` (Exact Source) parameters.
- Documentation for `ensureBucketConfigForNpub` covering bucket sanitization and auto-configuration.
- Documentation for `verifyPublicAccess` explaining the "Upload-then-Fetch" validation strategy.
2026-01-15 20:31:59 +00:00
google-labs-jules[bot] 4e840c6159 feat: improve magnet link reliability with webseeds
- Update `UploadModal.js` to pre-calculate R2 keys and public URLs before upload.
- Update `torrentHash.js` to embed the calculated video URL as a webseed (`url-list`) in the `.torrent` file.
- Update `r2Service.js` to accept forced keys/URLs and append `&xs=` (pointing to the .torrent file) to the magnet link.
- Ensures magnet links work for peerless downloads via WebSeed (BEP19) and HTTP Seeding (BEP17).
2026-01-15 13:26:27 +00:00
thePR0M3TH3AN a3374f0569 Guard upload when info hash is unavailable 2026-01-14 21:38:27 -05:00
thePR0M3TH3AN 6262a3cb37 Add torrent metadata upload for R2 videos 2026-01-14 21:28:57 -05:00
google-labs-jules[bot] 657ee40eb5 fix(r2): inject infohash into nip-71 imeta tags for webtorrent bootstrapping 2026-01-15 02:04:14 +00:00
google-labs-jules[bot] 0a79108c05 fix(r2): validate baseDomain to reject S3 API endpoints
Updated `r2Service.js` to detect if the user inputs an S3 API endpoint (e.g. `*.r2.cloudflarestorage.com`) as the Public Bucket URL. If detected, it prevents saving and displays a clear error message instructing the user to use the correct public domain (e.g. `*.r2.dev`). This prevents CORS errors and confusion caused by using the wrong endpoint type.
2026-01-14 17:19:14 +00:00
google-labs-jules[bot] fe1b6d0ae2 fix(storage): fix R2 setup issues (CORS, polyfills, headers)
- Switched to `esm.sh` bundle for `@aws-sdk/client-s3` to fix browser compatibility and `fs.readFile` errors.
- Removed `cf-create-bucket-if-missing` header from `multipartUpload` to prevent 403 Forbidden/CORS failures with standard API tokens.
- Refactored `verifyPublicAccess` to attempt CORS setup even if bucket check fails, and added specific error messaging for CORS issues.
- Updated documentation to include `POST` and `HEAD` in the recommended R2 CORS policy.
2026-01-14 17:11:04 +00:00
google-labs-jules[bot] 8097f64ba8 fix(storage): handle R2 CORS errors & use bundled aws-sdk
1.  **Refactor R2 Verification**: Separated bucket existence checks from CORS configuration in `r2Service.js`. Previously, if `HeadBucket` failed (e.g., due to CORS restrictions), the CORS configuration step was skipped. Now, CORS setup is attempted independently, increasing the chance of successful auto-configuration.
2.  **Improve Error Messaging**: Enhanced error handling in `verifyPublicAccess` to detect "Failed to fetch" errors and explicitly suggest checking Cloudflare R2 CORS settings in the UI.
3.  **Fix AWS SDK Import**: Consolidated the AWS SDK import fix to use the `?bundle` version from `esm.sh` in `r2-s3.js`. This prevents `fs.readFile` runtime errors by ensuring a browser-compatible build is loaded.
2026-01-14 16:36:25 +00:00
google-labs-jules[bot] a0ef54434a Implement 2-step wizard for R2 credentials with public access verification
- Added `deleteObject` to `js/storage/r2-s3.js` for cleanup.
- Added `verifyPublicAccess` to `js/services/r2Service.js` to test bucket configuration.
- Refactored `components/upload-modal.html` to support wizard steps.
- Updated `js/ui/components/UploadModal.js` to manage wizard state and trigger verification.
2026-01-12 20:16:30 +00:00
google-labs-jules[bot] f45f027a56 Refine R2 upload UX with bucket auto-creation attempt and clearer guidance
- Updated `R2Service` to attempt bucket creation via S3 API (`ensureBucketExists`) before upload. This improves the UX for users with Admin keys or custom domains while gracefully failing (with a warning) for users with minimal permissions.
- Modified `UploadModal` helper text to explicitly instruct users about enabling "Public Access" in the Cloudflare dashboard for new buckets.
- Updated `js/r2.js` to ensure the "Public Bucket URL" is always sanitized to include the `https://` protocol, fixing potential webseed generation issues.
2026-01-12 19:40:07 +00:00
google-labs-jules[bot] 7dc2977cf2 Update Cloudflare R2 upload to use minimal permissions and add progress bar
- Removed requirement for Cloudflare API Token, Zone ID, and Worker Token from Upload Modal and R2Service.
- Simplified R2 configuration to require only Account ID, S3 Access Keys, and a user-provided Public Bucket URL.
- Added a read-only field in Upload Modal displaying the derived target bucket name (npub-based) for user reference.
- Implemented client-side torrent info hash calculation using `WebTorrent` (via `js/utils/torrentHash.js`) to generate magnet links before upload.
- Added a visual upload progress bar to the Upload Modal.
- Updated `js/r2.js` to ensure the Public Bucket URL always includes the `https://` protocol.
2026-01-12 18:53:22 +00:00
google-labs-jules[bot] 44aed00b5e Add thumbnail upload support to UploadModal and R2Service
- Added file input and browse button for thumbnails in `upload-modal.html`.
- Updated `UploadModal.js` to handle thumbnail file selection and UI toggling.
- Updated `r2Service.js` to upload thumbnail file (if present) to R2 and update metadata.
- Ensured thumbnail keys are derived from video keys for consistent naming.
2026-01-09 03:03:35 +00:00
google-labs-jules[bot] 3a86ad5b20 docs: Add detailed R2 setup guide and clarify API token requirement
- Add new "Setup Guide" section to `docs/storage-r2.md` detailing the dual-credential requirement (S3 Keys + Cloudflare API Token) for full automation.
- Remove unsupported "manual/S3-only" workflow documentation to prevent user confusion.
- Update `js/services/r2Service.js` error message to explicitly prompt users for an API Token when the public domain is missing, instead of suggesting manual configuration.
2026-01-09 02:44:25 +00:00
google-labs-jules[bot] 9028f77464 feat: add client-side R2 to WebTorrent generation flow
Integrates WebTorrent client-side seeding into the Cloudflare R2 upload path.
- Adds `uploadFile` to `r2Service` for generic file uploads.
- Updates `UploadModal` to offer an optional "Create torrent & seed" flow.
- Generates magnet links and .torrent files in the browser after R2 upload.
- Uploads the .torrent file to R2 and populates `xs` tag.
- Populates `ws` (Web Seed) with the R2 public URL.
- Adds UI progress indicators for hashing and torrent upload.
- Enforces a 2GB file size limit for browser seeding to prevent crashes.
- Adds a mandatory legal rights confirmation checkbox for R2 uploads.
2026-01-08 13:50:53 +00:00
thePR0M3TH3AN 700056b5fc Extract video note payload normalization 2025-10-26 18:21:32 -04:00
thePR0M3TH3AN 7ae07b1369 refactor: migrate console usage to shared loggers 2025-10-15 14:37:25 -04:00
thePR0M3TH3AN d705cf176b Revert "Refactor logging to centralized logger" 2025-10-15 11:14:10 -04:00
thePR0M3TH3AN 37ba57aa37 Refactor logging to centralized logger 2025-10-15 11:11:14 -04:00
thePR0M3TH3AN d33ca197d7 Prevent conflicting audience flags in upload forms 2025-10-09 22:03:58 -04:00
thePR0M3TH3AN 1122c702af Add NSFW and kid-friendly toggles to upload flows 2025-10-09 21:55:05 -04:00
thePR0M3TH3AN 9041f9c0b7 feat: pass nip71 metadata through publish pipeline 2025-10-04 18:49:43 -04:00