MCPcopy Index your code
hub / github.com/ScattrdBlade/bigFileUpload / uploadToEncryptingHost

Function uploadToEncryptingHost

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

Source from the content-addressed store, hash-verified

526}
527
528async function uploadToEncryptingHost(fileBlob: Blob, filename: string): Promise<string> {
529 const config = getEncryptingHostConfig();
530
531 const formData = new FormData();
532 formData.append("password", makeRandomHex(16));
533 formData.append("userKey", config.key);
534 formData.append("urlStyle", config.urlStyle);
535 formData.append("domains", JSON.stringify(config.domains));
536 if (config.title) {
537 formData.append("title", config.title);
538 }
539 if (config.color) {
540 formData.append("color", config.color);
541 }
542 if (config.fakelink) {
543 formData.append("fakelink", config.fakelink);
544 }
545 formData.append("file", fileBlob, filename);
546
547 const response = await uploadRequestWithTimeout("https://encrypting.host/upload", {
548 method: "POST",
549 body: formData
550 });
551
552 const text = await response.text();
553 let data: { url?: string; error?: string; } | null = null;
554
555 try {
556 data = text ? JSON.parse(text) as { url?: string; error?: string; } : null;
557 } catch {
558 data = null;
559 }
560
561 if (!response.ok) {
562 throw new Error(`Upload failed: ${response.status} ${text}`);
563 }
564
565 const parsedUrl = data?.url?.trim() || "";
566 const fallbackUrl = text.trim().startsWith("http") ? text.trim() : "";
567 const url = parsedUrl || fallbackUrl;
568 if (!url) {
569 throw new Error("No URL returned from upload");
570 }
571
572 return url;
573}
574
575function getServiceConfigError(service: ServiceType): string | null {
576 const store = settings.store as {

Callers 1

uploadToServiceFunction · 0.85

Calls 4

getEncryptingHostConfigFunction · 0.85
uploadRequestWithTimeoutFunction · 0.85
textMethod · 0.80
makeRandomHexFunction · 0.70

Tested by

no test coverage detected