MCPcopy Create free account
hub / github.com/dfinity/cancan / uploadVideo

Function uploadVideo

scripts/seed.ts:100–130  ·  view source on GitHub ↗
(video)

Source from the content-addressed store, hash-verified

98}
99
100async 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
132function chunkFile(filePath) {
133 const file = fs.readFileSync(filePath);

Callers

nothing calls this directly

Calls 2

chunkFileFunction · 0.85
encodeArrayBufferFunction · 0.70

Tested by

no test coverage detected