Skip to content

Commit

Permalink
fix index manifest parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiaz9 committed Oct 16, 2024
1 parent c035711 commit b8ca158
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@etherna/sdk-js",
"version": "1.7.0",
"version": "1.7.1",
"description": "Etherna SDKs for operations on the network",
"author": "Mattia Dalzocchio",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/clients/index/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type IndexVideoPreview = {
updatedAt: number
}

export type IndexVideoManifest = Omit<IndexVideoPreview, "id"> & {
export type IndexVideoManifest = Omit<IndexVideoPreview, "id" | "ownerAddress"> & {
batchId: BatchId | null
aspectRatio: number | null
hash: Reference
Expand Down
27 changes: 13 additions & 14 deletions src/swarm/video/reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class VideoReader extends BaseReader<Video | null, string, VideoRaw | Ind
}
}

const videoPreviewRaw = VideoReader.indexVideoPreviewToRaw(video.lastValidManifest)
const videoPreviewRaw = VideoReader.indexVideoPreviewToRaw(video)
videoPreviewRaw.v = video.lastValidManifest.batchId ? "2.1" : "1.2"

const videoDetailsRaw = VideoReader.emptyVideoDetails()
Expand All @@ -137,25 +137,24 @@ export class VideoReader extends BaseReader<Video | null, string, VideoRaw | Ind
}
}

static indexVideoPreviewToRaw(
videoPreview: IndexVideoPreview | IndexVideoManifest,
): VideoPreviewRaw {
static indexVideoPreviewToRaw(videoPreview: IndexVideoPreview | IndexVideo): VideoPreviewRaw {
const data = "lastValidManifest" in videoPreview ? videoPreview.lastValidManifest : videoPreview
return {
v: undefined,
title: videoPreview.title,
duration: videoPreview.duration,
title: data?.title ?? "",
duration: data?.duration ?? 0,
ownerAddress: videoPreview.ownerAddress,
thumbnail: videoPreview.thumbnail
thumbnail: data?.thumbnail
? {
...videoPreview.thumbnail,
sources: videoPreview.thumbnail.sources.map((source) => ({
...data?.thumbnail,
sources: data?.thumbnail.sources.map((source) => ({
...source,
path: source.path?.replace(/^[0-9a-f]{64}\/(.+)/, "$1").replace(/\/$/, "") ?? "",
})),
}
: null,
createdAt: dateToTimestamp(new Date(videoPreview.createdAt)),
updatedAt: dateToTimestamp(new Date(videoPreview.updatedAt)),
createdAt: data?.createdAt ?? dateToTimestamp(new Date()),
updatedAt: data?.updatedAt ? dateToTimestamp(new Date(data.updatedAt)) : null,
} satisfies VideoPreviewRaw
}

Expand All @@ -165,9 +164,9 @@ export class VideoReader extends BaseReader<Video | null, string, VideoRaw | Ind
duration: 0,
thumbnail: null,
ownerAddress: "0x0",
createdAt: Date.now(),
updatedAt: Date.now(),
v: "2.0",
createdAt: dateToTimestamp(new Date()),
updatedAt: dateToTimestamp(new Date()),
v: "2.1",
}
}

Expand Down

0 comments on commit b8ca158

Please sign in to comment.