@@ -252,48 +252,82 @@ export default async function ShareVideoPage(props: Props) {
252
252
) ;
253
253
}
254
254
255
- let individualFiles : {
256
- fileName : string ;
257
- url : string ;
258
- } [ ] = [ ] ;
255
+ console . log ( "[ShareVideoPage] Fetching individual files for video:" , videoId ) ;
256
+ const individualFiles = await fetch (
257
+ `${ clientEnv . NEXT_PUBLIC_WEB_URL } /api/video/individual-files?videoId=${ videoId } ` ,
258
+ {
259
+ method : "GET" ,
260
+ credentials : "include" ,
261
+ cache : "no-store" ,
262
+ }
263
+ ) . then ( ( res ) => res . json ( ) ) ;
264
+
265
+ console . log ( "[ShareVideoPage] Fetching analytics for video:" , videoId ) ;
266
+ const analyticsResponse = await fetch (
267
+ `${ clientEnv . NEXT_PUBLIC_WEB_URL } /api/video/analytics?videoId=${ videoId } ` ,
268
+ {
269
+ method : "GET" ,
270
+ credentials : "include" ,
271
+ cache : "no-store" ,
272
+ }
273
+ ) ;
259
274
260
- if ( video ?. source . type === "desktopMP4" ) {
261
- console . log (
262
- "[ShareVideoPage] Fetching individual files for desktop MP4 video:" ,
263
- videoId
264
- ) ;
265
- const res = await fetch (
266
- `${ clientEnv . NEXT_PUBLIC_WEB_URL } /api/video/individual?videoId=${ videoId } &userId=${ video . ownerId } ` ,
267
- {
268
- method : "GET" ,
269
- credentials : "include" ,
270
- cache : "no-store" ,
271
- }
272
- ) ;
275
+ const analyticsData = await analyticsResponse . json ( ) ;
276
+ const initialAnalytics = {
277
+ views : analyticsData . count || 0 ,
278
+ comments : commentsQuery . filter ( ( c ) => c . type === "text" ) . length ,
279
+ reactions : commentsQuery . filter ( ( c ) => c . type === "emoji" ) . length ,
280
+ } ;
273
281
274
- const data = await res . json ( ) ;
275
- individualFiles = data . files ;
276
- }
282
+ // Fetch custom domain information
283
+ let customDomain : string | null = null ;
284
+ let domainVerified = false ;
277
285
278
- console . log ( "[ShareVideoPage] Rendering Share component for video:" , videoId ) ;
286
+ // Check if the video is shared with a space
287
+ if ( video . sharedSpace ?. spaceId ) {
288
+ const spaceData = await db
289
+ . select ( {
290
+ customDomain : spaces . customDomain ,
291
+ domainVerified : spaces . domainVerified ,
292
+ } )
293
+ . from ( spaces )
294
+ . where ( eq ( spaces . id , video . sharedSpace . spaceId ) )
295
+ . limit ( 1 ) ;
279
296
280
- const analyticsData = await db
281
- . select ( {
282
- id : videos . id ,
283
- totalComments : sql < number > `COUNT(DISTINCT CASE WHEN ${ comments . type } = 'text' THEN ${ comments . id } END)` ,
284
- totalReactions : sql < number > `COUNT(DISTINCT CASE WHEN ${ comments . type } = 'emoji' THEN ${ comments . id } END)` ,
285
- } )
286
- . from ( videos )
287
- . leftJoin ( comments , eq ( videos . id , comments . videoId ) )
288
- . where ( eq ( videos . id , videoId ) )
289
- . groupBy ( videos . id ) ;
297
+ if ( spaceData . length > 0 && spaceData [ 0 ] && spaceData [ 0 ] . customDomain ) {
298
+ customDomain = spaceData [ 0 ] . customDomain ;
299
+ // Handle domainVerified which could be a Date or boolean
300
+ if ( spaceData [ 0 ] . domainVerified !== null ) {
301
+ domainVerified = true ; // If it exists (not null), consider it verified
302
+ }
303
+ }
304
+ }
290
305
291
- const initialAnalytics = {
292
- views : 0 ,
293
- comments : analyticsData [ 0 ] ?. totalComments || 0 ,
294
- reactions : analyticsData [ 0 ] ?. totalReactions || 0 ,
295
- } ;
306
+ // If no custom domain from shared space, check the owner's space
307
+ if ( ! customDomain && video . ownerId ) {
308
+ const ownerSpaces = await db
309
+ . select ( {
310
+ customDomain : spaces . customDomain ,
311
+ domainVerified : spaces . domainVerified ,
312
+ } )
313
+ . from ( spaces )
314
+ . where ( eq ( spaces . ownerId , video . ownerId ) )
315
+ . limit ( 1 ) ;
316
+
317
+ if (
318
+ ownerSpaces . length > 0 &&
319
+ ownerSpaces [ 0 ] &&
320
+ ownerSpaces [ 0 ] . customDomain
321
+ ) {
322
+ customDomain = ownerSpaces [ 0 ] . customDomain ;
323
+ // Handle domainVerified which could be a Date or boolean
324
+ if ( ownerSpaces [ 0 ] . domainVerified !== null ) {
325
+ domainVerified = true ; // If it exists (not null), consider it verified
326
+ }
327
+ }
328
+ }
296
329
330
+ // Get space members if the video is shared with a space
297
331
const membersList = video . sharedSpace ?. spaceId
298
332
? await db
299
333
. select ( {
@@ -316,6 +350,8 @@ export default async function ShareVideoPage(props: Props) {
316
350
comments = { commentsQuery }
317
351
individualFiles = { individualFiles }
318
352
initialAnalytics = { initialAnalytics }
353
+ customDomain = { customDomain }
354
+ domainVerified = { domainVerified }
319
355
/>
320
356
) ;
321
357
}
0 commit comments