MCPcopy
hub / github.com/TransformerOptimus/SuperAGI / downloadFile

Function downloadFile

gui/utils/utils.js:117–156  ·  view source on GitHub ↗
(fileId, fileName = null)

Source from the content-addressed store, hash-verified

115};
116
117export const downloadFile = (fileId, fileName = null) => {
118 // const authToken = localStorage.getItem('accessToken');
119 const authToken = Cookies.get("accessToken");
120 const url = `${baseUrl()}/resources/get/${fileId}`;
121 const env = localStorage.getItem('applicationEnvironment');
122
123 if (env === 'PROD') {
124 const headers = {
125 Authorization: `Bearer ${authToken}`,
126 };
127
128 return fetch(url, {headers})
129 .then((response) => response.blob())
130 .then((blob) => {
131 if (fileName) {
132 const fileUrl = window.URL.createObjectURL(blob);
133 const anchorElement = document.createElement('a');
134 anchorElement.href = fileUrl;
135 anchorElement.download = fileName;
136 anchorElement.click();
137 window.URL.revokeObjectURL(fileUrl);
138 } else {
139 return blob;
140 }
141 })
142 .catch((error) => {
143 console.error('Error downloading file:', error);
144 });
145 } else {
146 if (fileName) {
147 window.open(url, '_blank');
148 } else {
149 return fetch(url)
150 .then((response) => response.blob())
151 .catch((error) => {
152 console.error('Error downloading file:', error);
153 });
154 }
155 }
156};
157
158export const downloadAllFiles = (files, run_name) => {
159 const zip = new JSZip();

Callers 1

downloadAllFilesFunction · 0.85

Calls 2

baseUrlFunction · 0.90
errorMethod · 0.80

Tested by

no test coverage detected