Repository navigation
feat: let owners import a video's file from a URL instead of uploading it - #5
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Changes
API
New endpoints:
videos:uploadscope)POST /organizations/:slug/libraries/:id/videos/:videoId/importPOST /libraries/:id/videos/:videoId/import{ "url": "https://…/clip.mp4" }Responses. Both return
202with the video, nowuploading, once the import is queued. The video now includesimportHost, the host it's being imported from, ornull.Following progress. Use the video or status endpoints, or the existing
video.uploadedandvideo.upload_failedwebhook events.Errors.
video.already_uploadedlibrary.storage_changedvideo.import.url_not_allowedNew failure reasons on the video:
import_unreachable,import_too_large,import_timed_outandimport_failed.Activity log. A new
video.import_startedentry records the host and file name.Worker
Queue. Each import goes through the outbox and then onto a new
video-importBullMQ 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_bytesis updated after each part.Checks.
Content-Lengthbefore downloading, and again while the bytes arrive.Content-Lengthcounts 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:
These are retried with exponential backoff, and fail the video on the last attempt:
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
httpandhttpsaddresses. URLs with credentials are refused.VIDEO_IMPORT_ALLOW_PRIVATE_URLSallows them, and defaults to on outside production, as for webhooks.VIDEO_IMPORT_TIMEOUT_MS.Database
0006_add_video_imports.sqladds avideo_importstable:idvideo_id: unique, deleted along with the videourlIt holds the import in progress, the same way
video_uploadsholds an unfinished upload:Configuration
New settings, all in
.env.example:VIDEO_IMPORT_CONCURRENCY2VIDEO_IMPORT_MAX_ATTEMPTS3VIDEO_IMPORT_RETRY_DELAY_MS60000VIDEO_IMPORT_TIMEOUT_MS10800000(3 h)VIDEO_IMPORT_ALLOW_PRIVATE_URLSWeb
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:
The library layout now remounts the tab per library.