MCPcopy Index your code
hub / github.com/CapSoftware/Cap / startMediaServerEditJob

Function startMediaServerEditJob

apps/web/workflows/edit-video.ts:157–236  ·  view source on GitHub ↗
(
	mediaServerUrl: string,
	body: {
		videoId: string;
		userId: string;
		sourceUrl: string;
		outputPresignedUrl: string;
		outputVerificationUrl?: string;
		thumbnailPresignedUrl: string;
		previewGifPresignedUrl: string;
		webhookUrl: string;
		webhookSecret?: string;
		keepRanges: VideoEditRange[];
	},
)

Source from the content-addressed store, hash-verified

155}
156
157async function startMediaServerEditJob(
158 mediaServerUrl: string,
159 body: {
160 videoId: string;
161 userId: string;
162 sourceUrl: string;
163 outputPresignedUrl: string;
164 outputVerificationUrl?: string;
165 thumbnailPresignedUrl: string;
166 previewGifPresignedUrl: string;
167 webhookUrl: string;
168 webhookSecret?: string;
169 keepRanges: VideoEditRange[];
170 },
171): Promise<string> {
172 for (let attempt = 0; attempt < MEDIA_SERVER_START_MAX_ATTEMPTS; attempt++) {
173 const headers: Record<string, string> = {
174 "Content-Type": "application/json",
175 };
176 if (body.webhookSecret) {
177 headers["x-media-server-secret"] = body.webhookSecret;
178 }
179
180 const response = await fetch(`${mediaServerUrl}/video/edit`, {
181 method: "POST",
182 headers,
183 body: JSON.stringify(body),
184 });
185
186 if (response.ok) {
187 const { jobId } = (await response.json()) as { jobId: string };
188 return jobId;
189 }
190
191 const errorData = (await response.json().catch(() => ({}))) as {
192 error?: string;
193 code?: string;
194 details?: string;
195 instanceId?: string;
196 pid?: number;
197 activeVideoProcesses?: number;
198 maxConcurrentVideoProcesses?: number;
199 jobCount?: number;
200 };
201 const baseErrorMessage =
202 errorData.error || errorData.details || "Video edit failed to start";
203 const busyDiagnostics =
204 errorData.code === "SERVER_BUSY"
205 ? [
206 errorData.instanceId ? `instance=${errorData.instanceId}` : null,
207 typeof errorData.pid === "number" ? `pid=${errorData.pid}` : null,
208 typeof errorData.activeVideoProcesses === "number" &&
209 typeof errorData.maxConcurrentVideoProcesses === "number"
210 ? `active=${errorData.activeVideoProcesses}/${errorData.maxConcurrentVideoProcesses}`
211 : null,
212 typeof errorData.jobCount === "number"
213 ? `jobCount=${errorData.jobCount}`
214 : null,

Callers 1

Calls 2

waitForRetryFunction · 0.70
fetchFunction · 0.50

Tested by

no test coverage detected