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

Function uploadToPixelDrain

native.ts:417–451  ·  view source on GitHub ↗
(
    _: IpcMainInvokeEvent,
    fileBuffer: ArrayBuffer,
    filename: string,
    apiKey?: string
)

Source from the content-addressed store, hash-verified

415}
416
417export async function uploadToPixelDrain(
418 _: IpcMainInvokeEvent,
419 fileBuffer: ArrayBuffer,
420 filename: string,
421 apiKey?: string
422): Promise<NativeUploadResult> {
423 try {
424 const headers: Record<string, string> = {};
425 if (apiKey?.trim()) {
426 headers.Authorization = `Basic ${Buffer.from(`:${apiKey.trim()}`).toString("base64")}`;
427 }
428
429 const response = await rawFetch(`https://pixeldrain.com/api/file/${encodeURIComponent(filename)}`, "PUT", fileBuffer, headers);
430
431 const text = await response.text();
432 let data: { id?: string; message?: string; } | null = null;
433 try {
434 data = text ? JSON.parse(text) : null;
435 } catch {
436 data = null;
437 }
438
439 if (!response.ok) {
440 return { success: false, error: data?.message || `Upload failed: ${response.status} ${text}` };
441 }
442
443 if (!data?.id) {
444 return { success: false, error: data?.message || "No URL returned from upload" };
445 }
446
447 return { success: true, url: `https://pixeldrain.com/u/${data.id}` };
448 } catch (e) {
449 return { success: false, error: e instanceof Error ? e.message : "Unknown error" };
450 }
451}
452
453function isValidHttpsUrl(url: string): boolean {
454 try {

Callers

nothing calls this directly

Calls 2

rawFetchFunction · 0.85
textMethod · 0.80

Tested by

no test coverage detected