MCPcopy Create free account
hub / github.com/ScattrdBlade/bigFileUpload / uploadToNest

Function uploadToNest

utils/upload.ts:417–462  ·  view source on GitHub ↗
(fileBlob: Blob, filename: string)

Source from the content-addressed store, hash-verified

415}
416
417async function uploadToNest(fileBlob: Blob, filename: string): Promise<string> {
418 const { nestToken } = settings.store;
419
420 if (!nestToken) {
421 throw new Error("Auth token is required");
422 }
423
424 if (Native) {
425 const arrayBuffer = await fileBlob.arrayBuffer();
426 const result = await Native.uploadToNest(arrayBuffer, filename, nestToken);
427
428 if (!result.success) {
429 throw new Error(result.error || "Upload failed");
430 }
431
432 if (!result.url) {
433 throw new Error("No URL returned from upload");
434 }
435
436 return result.url;
437 }
438
439 const formData = new FormData();
440 formData.append("file", fileBlob, filename);
441
442 const response = await uploadRequestWithTimeout("https://nest.rip/api/files/upload", {
443 method: "POST",
444 headers: {
445 "Authorization": nestToken
446 },
447 body: formData
448 });
449
450 if (!response.ok) {
451 const errorText = await response.text();
452 throw new Error(`Upload failed: ${response.status} ${errorText}`);
453 }
454
455 const data = await response.json() as { fileURL?: string; };
456
457 if (data.fileURL) {
458 return data.fileURL;
459 }
460
461 throw new Error("No URL returned from upload");
462}
463
464type EncryptingHostUrlStyle = "query" | "param" | "fakelink" | "embed";
465

Callers 1

uploadToServiceFunction · 0.70

Calls 3

uploadRequestWithTimeoutFunction · 0.85
textMethod · 0.80
jsonMethod · 0.80

Tested by

no test coverage detected