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

Function uploadToPixelDrain

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

Source from the content-addressed store, hash-verified

947}
948
949async function uploadToPixelDrain(fileBlob: Blob, filename: string): Promise<string> {
950 const { pixelDrainKey } = settings.store as { pixelDrainKey?: string; };
951
952 if (Native) {
953 const result = await Native.uploadToPixelDrain(await fileBlob.arrayBuffer(), filename, pixelDrainKey?.trim() || undefined);
954 if (!result.success || !result.url) throw new Error(result.error || "No URL returned from upload");
955 return result.url;
956 }
957
958 const headers: Record<string, string> = {};
959 if (pixelDrainKey?.trim()) {
960 headers.Authorization = `Basic ${btoa(`:${pixelDrainKey.trim()}`)}`;
961 }
962
963 const response = await uploadRequestWithTimeout(`https://pixeldrain.com/api/file/${encodeURIComponent(filename)}`, {
964 method: "PUT",
965 headers,
966 body: fileBlob
967 });
968
969 const text = await response.text();
970 let data: { id?: string; success?: boolean; message?: string; } | null = null;
971 try {
972 data = text ? JSON.parse(text) : null;
973 } catch {
974 data = null;
975 }
976
977 if (!response.ok) {
978 throw new Error(data?.message || `Upload failed: ${response.status} ${text}`);
979 }
980
981 if (!data?.id) {
982 throw new Error(data?.message || "No URL returned from upload");
983 }
984
985 return `https://pixeldrain.com/u/${data.id}`;
986}
987
988function buildWebdavAuthHeader(): string | null {
989 const { webdavUsername, webdavPassword } = settings.store as {

Callers 1

uploadToServiceFunction · 0.70

Calls 2

uploadRequestWithTimeoutFunction · 0.85
textMethod · 0.80

Tested by

no test coverage detected