(video)
| 98 | } |
| 99 | |
| 100 | async function uploadVideo(video) { |
| 101 | const pathname = path.resolve(__dirname, assetPath, video.name, video.name); |
| 102 | const videoFilePath = `${pathname}.mp4`; |
| 103 | const videoPicPath = `${pathname}.jpg`; |
| 104 | |
| 105 | console.time(`Created video ${video.name}`); |
| 106 | const videoChunks = chunkFile(videoFilePath); |
| 107 | const videoIdResponse = await canister.createVideo({ |
| 108 | ...video, |
| 109 | chunkCount: videoChunks.length, |
| 110 | }); |
| 111 | console.timeEnd(`Created video ${video.name}`); |
| 112 | |
| 113 | const videoId = videoIdResponse[0] as string; |
| 114 | |
| 115 | console.time(`Stored video ${video.name}`); |
| 116 | await Promise.all( |
| 117 | videoChunks.map((chunk, chunkIndex) => |
| 118 | canister.putVideoChunk(videoId, chunkIndex + 1, chunk) |
| 119 | ) |
| 120 | ); |
| 121 | console.timeEnd(`Stored video ${video.name}`); |
| 122 | |
| 123 | // upload png |
| 124 | console.time(`Stored video thumbnail for ${video.name}`); |
| 125 | const videoPicFile = fs.readFileSync(videoPicPath); |
| 126 | const videoPicArray = videoPicFile.buffer.slice(0); |
| 127 | const picAsNat = encodeArrayBuffer(videoPicArray); |
| 128 | await canister.putVideoPic(videoId, [picAsNat]); |
| 129 | console.timeEnd(`Stored video thumbnail for ${video.name}`); |
| 130 | } |
| 131 | |
| 132 | function chunkFile(filePath) { |
| 133 | const file = fs.readFileSync(filePath); |
nothing calls this directly
no test coverage detected