Skip to content

Commit 2451afc

Browse files
fix upload progress + boolean DB types done properly
1 parent c210134 commit 2451afc

File tree

16 files changed

+63
-38
lines changed

16 files changed

+63
-38
lines changed

apps/desktop/src-tauri/src/recording.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::{path::PathBuf, str::FromStr, sync::Arc, time::Duration};
1919
use tauri::{AppHandle, Manager};
2020
use tauri_plugin_dialog::{DialogExt, MessageDialogBuilder};
2121
use tauri_specta::Event;
22-
use tracing::{error, info};
22+
use tracing::{debug, error, info};
2323

2424
use crate::{
2525
App, CurrentRecordingChanged, MutableState, NewStudioRecordingAdded, RecordingState,
@@ -355,7 +355,7 @@ pub async fn start_recording(
355355
)
356356
});
357357

358-
println!("spawning actor");
358+
debug!("spawning start_recording actor");
359359

360360
// done in spawn to catch panics just in case
361361
let spawn_actor_res = async {

apps/desktop/src-tauri/src/upload.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use tauri_plugin_clipboard_manager::ClipboardExt;
2222
use tokio::io::{AsyncReadExt, AsyncSeekExt};
2323
use tokio::task::{self, JoinHandle};
2424
use tokio::time::sleep;
25-
use tracing::{error, info, trace, warn};
25+
use tracing::{debug, error, info, trace, warn};
2626

2727
#[derive(Deserialize, Serialize, Clone, Type, Debug)]
2828
pub struct S3UploadMeta {
@@ -664,14 +664,12 @@ impl InstantMultipartUpload {
664664
let mut uploaded_parts = Vec::new();
665665
let mut part_number = 1;
666666
let mut last_uploaded_position: u64 = 0;
667-
let mut progress = UploadProgressUpdater::new(app.clone(), video_id.clone());
668-
669-
println!("Starting multipart upload for {video_id}...");
667+
let mut progress = UploadProgressUpdater::new(app.clone(), pre_created_video.id.clone());
670668

671669
// --------------------------------------------
672670
// initiate the multipart upload
673671
// --------------------------------------------
674-
println!("Initiating multipart upload for {video_id}...");
672+
debug!("Initiating multipart upload for {video_id}...");
675673
let initiate_response = match app
676674
.authed_api_request("/api/upload/multipart/initiate", |c, url| {
677675
c.post(url)

apps/web/actions/videos/get-user-videos.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function getUserVideos(limit?: number) {
3131
${videos.createdAt}
3232
)
3333
`,
34-
hasActiveUpload: sql<number>`IF(${videoUploads.videoId} IS NULL, 0, 1)`,
34+
hasActiveUpload: sql`${videoUploads.videoId} IS NULL`.mapWith(Boolean),
3535
})
3636
.from(videos)
3737
.leftJoin(comments, eq(videos.id, comments.videoId))
@@ -62,7 +62,6 @@ export async function getUserVideos(limit?: number) {
6262
metadata: video.metadata as
6363
| { customCreatedAt?: string; [key: string]: any }
6464
| undefined,
65-
hasActiveUpload: video.hasActiveUpload === 1,
6665
};
6766
});
6867

apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export interface CapCardProps extends PropsWithChildren {
6262
ownerName: string | null;
6363
metadata?: VideoMetadata;
6464
hasPassword?: boolean;
65-
hasActiveUpload?: boolean;
65+
hasActiveUpload: boolean | undefined;
6666
duration?: number;
6767
};
6868
analytics: number;
@@ -164,7 +164,10 @@ export const CapCard = ({
164164

165165
const isOwner = userId === cap.ownerId;
166166

167-
const uploadProgress = useUploadProgress(cap.id, cap.hasActiveUpload);
167+
const uploadProgress = useUploadProgress(
168+
cap.id,
169+
cap.hasActiveUpload || false,
170+
);
168171

169172
// Helper function to create a drag preview element
170173
const createDragPreview = (text: string): HTMLElement => {

apps/web/app/(org)/dashboard/caps/page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export default async function CapsPage({
173173
${videos.createdAt}
174174
)
175175
`,
176-
hasPassword: sql<number>`IF(${videos.password} IS NULL, 0, 1)`,
177-
hasActiveUpload: sql<number>`IF(${videoUploads.videoId} IS NULL, 0, 1)`,
176+
hasPassword: sql`${videos.password} IS NULL`.mapWith(Boolean),
177+
hasActiveUpload: sql`${videoUploads.videoId} IS NULL`.mapWith(Boolean),
178178
})
179179
.from(videos)
180180
.leftJoin(comments, eq(videos.id, comments.videoId))
@@ -245,8 +245,6 @@ export default async function CapsPage({
245245
[key: string]: any;
246246
}
247247
| undefined,
248-
hasPassword: video.hasPassword === 1,
249-
hasActiveUpload: video.hasActiveUpload === 1,
250248
};
251249
});
252250

apps/web/app/(org)/dashboard/spaces/[spaceId]/SharedCaps.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type SharedVideoData = {
3232
totalReactions: number;
3333
ownerName: string | null;
3434
metadata?: VideoMetadata;
35+
hasActiveUpload: boolean | undefined;
3536
}[];
3637

3738
type SpaceData = {

apps/web/app/(org)/dashboard/spaces/[spaceId]/components/SharedCapCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ interface SharedCapCardProps {
1414
totalReactions: number;
1515
ownerName: string | null;
1616
metadata?: VideoMetadata;
17+
hasActiveUpload: boolean | undefined;
1718
};
1819
analytics: number;
1920
isLoadingAnalytics: boolean;

apps/web/app/(org)/dashboard/spaces/[spaceId]/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ export default async function SharedCapsPage({
203203
totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,
204204
ownerName: users.name,
205205
effectiveDate: sql<string>`COALESCE(JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')), ${videos.createdAt})`,
206-
hasActiveUpload: sql<number>`IF(${videoUploads.videoId} IS NULL, 0, 1)`,
206+
hasActiveUpload: sql`${videoUploads.videoId} IS NULL`.mapWith(
207+
Boolean,
208+
),
207209
})
208210
.from(spaceVideos)
209211
.innerJoin(videos, eq(spaceVideos.videoId, videos.id))
@@ -256,7 +258,6 @@ export default async function SharedCapsPage({
256258
metadata: video.metadata as
257259
| { customCreatedAt?: string; [key: string]: any }
258260
| undefined,
259-
hasActiveUpload: video.hasActiveUpload === 1,
260261
};
261262
});
262263

@@ -312,7 +313,9 @@ export default async function SharedCapsPage({
312313
totalReactions: sql<number>`COUNT(DISTINCT CASE WHEN ${comments.type} = 'emoji' THEN ${comments.id} END)`,
313314
ownerName: users.name,
314315
effectiveDate: sql<string>`COALESCE(JSON_UNQUOTE(JSON_EXTRACT(${videos.metadata}, '$.customCreatedAt')), ${videos.createdAt})`,
315-
hasActiveUpload: sql<number>`IF(${videoUploads.videoId} IS NULL, 0, 1)`,
316+
hasActiveUpload: sql`${videoUploads.videoId} IS NULL`.mapWith(
317+
Boolean,
318+
),
316319
})
317320
.from(sharedVideos)
318321
.innerJoin(videos, eq(sharedVideos.videoId, videos.id))
@@ -377,7 +380,6 @@ export default async function SharedCapsPage({
377380
metadata: video.metadata as
378381
| { customCreatedAt?: string; [key: string]: any }
379382
| undefined,
380-
hasActiveUpload: video.hasActiveUpload === 1,
381383
};
382384
});
383385

apps/web/app/embed/[videoId]/_components/EmbedVideo.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ type CommentWithAuthor = typeof commentsSchema.$inferSelect & {
4343
export const EmbedVideo = forwardRef<
4444
HTMLVideoElement,
4545
{
46-
data: Omit<typeof videos.$inferSelect, "password">;
46+
data: Omit<typeof videos.$inferSelect, "password"> & {
47+
hasActiveUpload: boolean | undefined;
48+
};
4749
user: typeof userSelectProps | null;
4850
comments: CommentWithAuthor[];
4951
chapters?: { title: string; start: number }[];
@@ -202,6 +204,7 @@ export const EmbedVideo = forwardRef<
202204
captionsSrc={subtitleUrl || ""}
203205
videoRef={videoRef}
204206
enableCrossOrigin={enableCrossOrigin}
207+
hasActiveUpload={data.hasActiveUpload}
205208
/>
206209
) : (
207210
<HLSVideoPlayer
@@ -211,6 +214,7 @@ export const EmbedVideo = forwardRef<
211214
chaptersSrc={chaptersUrl || ""}
212215
captionsSrc={subtitleUrl || ""}
213216
videoRef={videoRef}
217+
hasActiveUpload={data.hasActiveUpload}
214218
/>
215219
)}
216220
</div>

apps/web/app/embed/[videoId]/page.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
sharedVideos,
77
users,
88
videos,
9+
videoUploads,
910
} from "@cap/database/schema";
1011
import type { VideoMetadata } from "@cap/database/types";
1112
import { buildEnv } from "@cap/env";
@@ -146,13 +147,17 @@ export default async function EmbedVideoPage(props: Props) {
146147
height: videos.height,
147148
duration: videos.duration,
148149
fps: videos.fps,
149-
hasPassword: sql<number>`IF(${videos.password} IS NULL, 0, 1)`,
150+
hasPassword: sql`${videos.password} IS NULL`.mapWith(Boolean),
150151
sharedOrganization: {
151152
organizationId: sharedVideos.organizationId,
152153
},
154+
hasActiveUpload: sql`${videoUploads.videoId} IS NULL`.mapWith(
155+
Boolean,
156+
),
153157
})
154158
.from(videos)
155159
.leftJoin(sharedVideos, eq(videos.id, sharedVideos.videoId))
160+
.leftJoin(videoUploads, eq(videos.id, videoUploads.videoId))
156161
.where(eq(videos.id, videoId)),
157162
).pipe(Policy.withPublicPolicy(videosPolicy.canView(videoId)));
158163

@@ -195,6 +200,7 @@ async function EmbedContent({
195200
}: {
196201
video: Omit<typeof videos.$inferSelect, "password"> & {
197202
sharedOrganization: { organizationId: string } | null;
203+
hasActiveUpload: boolean | undefined;
198204
};
199205
autoplay: boolean;
200206
}) {

0 commit comments

Comments
 (0)