Skip to content

feat: let owners import a video's file from a URL instead of uploading it - #5

Merged
its-gabo merged 1 commit into
mainfrom
gs_feat_add_option_to_import_from_url
Nov 19, 2026
Merged

its-gabo merged 1 commit into
mainfrom
gs_feat_add_option_to_import_from_url

Conversation

@its-gabo

Copy link
Copy Markdown
Owner

Summary

Until now, a video's file could only come from a browser upload. Members and library API keys can now give a URL instead, and the worker downloads the file from there. The file then goes through the same checks and processing as an uploaded one. Long downloads run on their own queue, so they never hold up transcoding, emails or webhooks.

This PR also fixes library tabs keeping the previous library's settings after you switch libraries.

What members see

  • Import from URL tab. The add-video dialog has two tabs: File and URL. Paste a direct link to an MP4 or MOV file. If you leave the title empty, the video is named after the file in the URL.
  • Progress in the video list. The row shows "Importing from host" with the bytes stored so far. Only the host is ever shown, because the rest of a URL can hold a token.
  • Failures. A failed import shows its reason in the video list: the file isn't a video, the URL couldn't be reached, the file is too large, or the download timed out. Uploading a file still works on a failed video.
  • Replacing an import. Starting an upload or another import on the same video stops a running import and discards what it stored.

Changes

API

New endpoints:

Member route Library API route (videos:upload scope) Body
POST /organizations/:slug/libraries/:id/videos/:videoId/import POST /libraries/:id/videos/:videoId/import { "url": "https://…/clip.mp4" }
  • Responses. Both return 202 with the video, now uploading, once the import is queued. The video now includes importHost, the host it's being imported from, or null.

  • Following progress. Use the video or status endpoints, or the existing video.uploaded and video.upload_failed webhook events.

  • Errors.

    Status Code When
    409 video.already_uploaded The video already has a file
    409 library.storage_changed The library's storage changed while the import was starting
    422 video.import.url_not_allowed The URL isn't a public HTTP or HTTPS address
    422 validation The URL is malformed, longer than 2048 characters, uses another scheme, or contains a username or password
  • New failure reasons on the video: import_unreachable, import_too_large, import_timed_out and import_failed.

  • Activity log. A new video.import_started entry records the host and file name.

Worker

  • Queue. Each import goes through the outbox and then onto a new video-import BullMQ queue, one job per import. If the outbox relays a message twice, the file is still downloaded only once.

  • Download. The file is streamed into storage in 16 MiB parts of a multipart upload, the same part size as uploads, so memory use stays at about one part per import. uploaded_bytes is updated after each part.

  • Checks.

    • The first bytes must be MP4 or MOV.
    • The size limit is checked against Content-Length before downloading, and again while the bytes arrive.
    • A download that ends before its Content-Length counts as cut short.
  • Finishing. The video is marked uploaded and queued for processing in one transaction, with the same webhooks an upload sends. The multipart upload is completed as the last step.

  • Retries. These fail at once:

    • a file that isn't a video
    • a 4xx answer other than 408 and 429
    • a file that's too large
    • more than 5 redirects

    These are retried with exponential backoff, and fail the video on the last attempt:

    • 5xx, 408 and 429 answers
    • timeouts
    • dropped connections
    • storage errors

    Each attempt starts the download from the beginning.

  • Replacement. A newer import or upload replaces a running import. The import notices at its next part, aborts its multipart upload and stops.

Security

  • Public addresses only. In production, imports may only reach public http and https addresses. URLs with credentials are refused.
  • Redirects. Every redirect is checked like the first URL, and at most 5 are followed.
  • DNS. Each connection's resolved IP address is checked with the webhook delivery's public-address lookup, so a host that resolves to a private address can't get through, including through DNS rebinding.
  • Private addresses in development. VIDEO_IMPORT_ALLOW_PRIVATE_URLS allows them, and defaults to on outside production, as for webhooks.
  • Timeouts. A stalled download stops after 60 seconds without data. A whole download must finish within VIDEO_IMPORT_TIMEOUT_MS.
  • The URL isn't kept. It's stored only while the import runs and deleted when it finishes or fails.

Database

0006_add_video_imports.sql adds a video_imports table:

  • id
  • video_id: unique, deleted along with the video
  • url
  • timestamps

It holds the import in progress, the same way video_uploads holds an unfinished upload:

  • Starting. An import replaces the video's upload row, and an upload replaces its import row.
  • Ending. The row is deleted when the import finishes or fails.
  • Locking. Import rows only change under the video's row lock, so a running import's "am I still current?" check holds until its write.

Configuration

New settings, all in .env.example:

Variable Default Meaning
VIDEO_IMPORT_CONCURRENCY 2 Downloads one worker runs at a time
VIDEO_IMPORT_MAX_ATTEMPTS 3 Attempts before an import fails
VIDEO_IMPORT_RETRY_DELAY_MS 60000 First retry delay; each later one doubles it
VIDEO_IMPORT_TIMEOUT_MS 10800000 (3 h) Time limit for a whole download
VIDEO_IMPORT_ALLOW_PRIVATE_URLS on outside production Allow private and local addresses

Web

  • Add-video dialog. File and URL tabs. A URL import creates the draft and then starts the import. If the server refuses the URL, trying again reuses the same draft.

  • Video list. "Importing from host" with progress. The row offers "Upload file" instead of "Resume upload", since there's no upload to resume.

  • Translations. English and Polish.

  • Library tabs. Switching libraries left the open tab with the previous library's values:

    • Player and Encoding showed the previous library's settings, and saving wrote them to the new library.
    • Security and Storage kept unsaved edits.
    • Webhook deliveries kept their page number.

    The library layout now remounts the tab per library.

@its-gabo
its-gabo merged commit dc7f472 into main Nov 19, 2026
1 check passed
@its-gabo
its-gabo deleted the gs_feat_add_option_to_import_from_url branch November 22, 2026 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant