-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Distinguish videoUpload modes for more accurate progress reporting #1196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4fd8c7b
f8ee04a
f172676
d061707
bfd47a7
2faa7d9
dd48f37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,7 @@ import { | |||||||||||||||||||
| } from "@aws-sdk/client-cloudfront"; | ||||||||||||||||||||
| import type { PresignedPost } from "@aws-sdk/s3-presigned-post"; | ||||||||||||||||||||
| import { db, updateIfDefined } from "@cap/database"; | ||||||||||||||||||||
| import { s3Buckets, videos } from "@cap/database/schema"; | ||||||||||||||||||||
| import * as Db from "@cap/database/schema"; | ||||||||||||||||||||
| import { serverEnv } from "@cap/env"; | ||||||||||||||||||||
| import { AwsCredentials, S3Buckets } from "@cap/web-backend"; | ||||||||||||||||||||
| import { Video } from "@cap/web-domain"; | ||||||||||||||||||||
|
|
@@ -15,6 +15,11 @@ import { Hono } from "hono"; | |||||||||||||||||||
| import { z } from "zod"; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| import { runPromise } from "@/lib/server"; | ||||||||||||||||||||
| import { | ||||||||||||||||||||
| isAtLeastSemver, | ||||||||||||||||||||
| isFromDesktopSemver, | ||||||||||||||||||||
| UPLOAD_PROGRESS_VERSION, | ||||||||||||||||||||
| } from "@/utils/desktop"; | ||||||||||||||||||||
|
Comment on lines
+18
to
+22
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the unused
-import {
- isAtLeastSemver,
- isFromDesktopSemver,
- UPLOAD_PROGRESS_VERSION,
-} from "@/utils/desktop";
+import {
+ isFromDesktopSemver,
+ UPLOAD_PROGRESS_VERSION,
+} from "@/utils/desktop";📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||
| import { stringOrNumberOptional } from "@/utils/zod"; | ||||||||||||||||||||
| import { withAuth } from "../../utils"; | ||||||||||||||||||||
| import { parseVideoIdOrFileKey } from "../utils"; | ||||||||||||||||||||
|
|
@@ -51,8 +56,8 @@ app.post( | |||||||||||||||||||
| try { | ||||||||||||||||||||
| const [customBucket] = await db() | ||||||||||||||||||||
| .select() | ||||||||||||||||||||
| .from(s3Buckets) | ||||||||||||||||||||
| .where(eq(s3Buckets.ownerId, user.id)); | ||||||||||||||||||||
| .from(Db.s3Buckets) | ||||||||||||||||||||
| .where(eq(Db.s3Buckets.ownerId, user.id)); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const s3Config = customBucket | ||||||||||||||||||||
| ? { | ||||||||||||||||||||
|
|
@@ -156,22 +161,32 @@ app.post( | |||||||||||||||||||
| const videoIdFromKey = fileKey.split("/")[1]; // Assuming fileKey format is userId/videoId/... | ||||||||||||||||||||
|
|
||||||||||||||||||||
| const videoIdToUse = "videoId" in body ? body.videoId : videoIdFromKey; | ||||||||||||||||||||
| if (videoIdToUse) | ||||||||||||||||||||
| if (videoIdToUse) { | ||||||||||||||||||||
| const videoId = Video.VideoId.make(videoIdToUse); | ||||||||||||||||||||
| await db() | ||||||||||||||||||||
| .update(videos) | ||||||||||||||||||||
| .update(Db.videos) | ||||||||||||||||||||
| .set({ | ||||||||||||||||||||
| duration: updateIfDefined(durationInSecs, videos.duration), | ||||||||||||||||||||
| width: updateIfDefined(width, videos.width), | ||||||||||||||||||||
| height: updateIfDefined(height, videos.height), | ||||||||||||||||||||
| fps: updateIfDefined(fps, videos.fps), | ||||||||||||||||||||
| duration: updateIfDefined(durationInSecs, Db.videos.duration), | ||||||||||||||||||||
| width: updateIfDefined(width, Db.videos.width), | ||||||||||||||||||||
| height: updateIfDefined(height, Db.videos.height), | ||||||||||||||||||||
| fps: updateIfDefined(fps, Db.videos.fps), | ||||||||||||||||||||
| }) | ||||||||||||||||||||
| .where( | ||||||||||||||||||||
| and( | ||||||||||||||||||||
| eq(videos.id, Video.VideoId.make(videoIdToUse)), | ||||||||||||||||||||
| eq(videos.ownerId, user.id), | ||||||||||||||||||||
| ), | ||||||||||||||||||||
| and(eq(Db.videos.id, videoId), eq(Db.videos.ownerId, user.id)), | ||||||||||||||||||||
| ); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // i hate this but it'll have to do | ||||||||||||||||||||
| const clientSupportsUploadProgress = isFromDesktopSemver( | ||||||||||||||||||||
| c.req, | ||||||||||||||||||||
| UPLOAD_PROGRESS_VERSION, | ||||||||||||||||||||
| ); | ||||||||||||||||||||
| if (fileKey.endsWith("result.mp4") && clientSupportsUploadProgress) | ||||||||||||||||||||
| await db() | ||||||||||||||||||||
| .update(Db.videoUploads) | ||||||||||||||||||||
| .set({ mode: "singlepart" }) | ||||||||||||||||||||
| .where(eq(Db.videoUploads.videoId, videoId)); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if (method === "post") return c.json({ presignedPostData: data! }); | ||||||||||||||||||||
| else return c.json({ presignedPutData: data! }); | ||||||||||||||||||||
| } catch (s3Error) { | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { HonoRequest } from "hono"; | ||
|
|
||
| export function isFromDesktopSemver( | ||
| request: HonoRequest, | ||
| semver: readonly [number, number, number], | ||
| ) { | ||
| const xCapVersion = request.header("X-Cap-Desktop-Version"); | ||
|
|
||
| return xCapVersion ? isAtLeastSemver(xCapVersion, ...semver) : false; | ||
| } | ||
|
|
||
| export const UPLOAD_PROGRESS_VERSION = [0, 3, 68] as const; | ||
|
|
||
| export function isAtLeastSemver( | ||
| versionString: string, | ||
| major: number, | ||
| minor: number, | ||
| patch: number, | ||
| ): boolean { | ||
| const match = versionString | ||
| .replace(/^v/, "") | ||
| .match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?/); | ||
| if (!match) return false; | ||
| const [, vMajor, vMinor, vPatch, prerelease] = match; | ||
| const M = vMajor ? parseInt(vMajor, 10) || 0 : 0; | ||
| const m = vMinor ? parseInt(vMinor, 10) || 0 : 0; | ||
| const p = vPatch ? parseInt(vPatch, 10) || 0 : 0; | ||
| if (M > major) return true; | ||
| if (M < major) return false; | ||
| if (m > minor) return true; | ||
| if (m < minor) return false; | ||
| if (p > patch) return true; | ||
| if (p < patch) return false; | ||
| // Equal triplet: accept only non-prerelease | ||
| return !prerelease; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.