fix: enable adding video from library to another lesson

This commit is contained in:
Rotimi Best
2026-06-28 21:41:53 +01:00
parent 47b85a9697
commit 202fd30445
14 changed files with 87 additions and 38 deletions
@@ -38,7 +38,7 @@ import {
ZAssetUpdate,
ZYouTubeMetadataQuery
} from '@cio/utils/validation/assets';
import { mapAssetToLessonVideo } from '../utils/media-manager-utils';
import { getAssetHlsManifestLink, isHlsAsset, mapAssetToLessonVideo } from '../utils/media-manager-utils';
import type { AttachAssetRequest } from '../utils/types';
import type { DetachAssetRequest } from '../utils/types';
@@ -407,7 +407,9 @@ export class MediaApi extends BaseApiWithErrors {
asset: OrganizationAsset,
params: { lessonId?: string; position?: number; slotType?: string } = {}
) {
const url = await this.getVideoPlaybackUrl(asset);
// HLS assets have no presignable storageKey — the manifest is served via the
// /hls proxy + signed cookie, so the link is the relative manifest path.
const url = isHlsAsset(asset) ? getAssetHlsManifestLink(asset) : await this.getVideoPlaybackUrl(asset);
if (!url) {
snackbar.error('snackbar.media_manager.resolve_video_failed');
return null;
@@ -62,6 +62,20 @@ export function mapAssetProviderToLessonVideoType(provider: string): LessonVideo
return 'upload';
}
/**
* An HLS asset has no playable `storageKey` — its renditions live behind the
* `/hls/{assetId}/...` proxy and are streamed via a signed cookie, not a
* presigned URL. The lesson video stores the relative manifest path + `hls`
* flag so the player resolves and mints the cookie itself.
*/
export function isHlsAsset(asset: OrganizationAsset): boolean {
return Boolean(asset.hlsManifestKey);
}
export function getAssetHlsManifestLink(asset: OrganizationAsset): string {
return `/hls/${asset.id}/master.m3u8`;
}
export function mapAssetToLessonVideo(
asset: OrganizationAsset,
options: { url: string; key?: string | null }
@@ -78,6 +92,7 @@ export function mapAssetToLessonVideo(
duration?: number;
aspectRatio?: string;
createdAt?: string;
hls?: boolean;
};
} {
return {
@@ -92,7 +107,8 @@ export function mapAssetToLessonVideo(
thumbnailUrl: asset.thumbnailUrl ?? undefined,
duration: asset.durationSeconds ?? undefined,
aspectRatio: asset.aspectRatio ?? undefined,
createdAt: asset.createdAt ?? undefined
createdAt: asset.createdAt ?? undefined,
...(isHlsAsset(asset) ? { hls: true } : {})
}
};
}