@saltcorn/filemanager 0.8.3-beta.0 → 0.8.3-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/App.svelte CHANGED
@@ -74,8 +74,8 @@
74
74
  .filter(([k, v]) => v)
75
75
  .map(([k, v]) => k);
76
76
 
77
- async function POST(url, body) {
78
- return await fetch(url, {
77
+ async function POST(url, body, isDownload) {
78
+ const go=fetch(url, {
79
79
  headers: {
80
80
  "X-Requested-With": "XMLHttpRequest",
81
81
  "CSRF-Token": window._sc_globalCsrf,
@@ -84,6 +84,23 @@
84
84
  method: "POST",
85
85
  body: JSON.stringify(body || {}),
86
86
  });
87
+ if(isDownload){
88
+ const res = await go
89
+ const blob = await res.blob()
90
+
91
+ const link = document.createElement("a");
92
+ link.href = window.URL.createObjectURL(blob);
93
+ const header = res.headers.get('Content-Disposition');
94
+ if(header){
95
+ const parts = header.split(';');
96
+ let filename = parts[1].split('=')[1].replaceAll('"', "");
97
+ link.download = filename;
98
+ } else link.target = "_blank";
99
+ link.click();
100
+
101
+ return
102
+ } else
103
+ return await go;
87
104
  }
88
105
 
89
106
  async function goAction(e) {
@@ -113,6 +130,11 @@
113
130
  });
114
131
  await fetchAndReset();
115
132
  break;
133
+ case "Unzip":
134
+ await POST(`/files/unzip/${lastSelected.location}`, {});
135
+ await fetchAndReset();
136
+ break;
137
+
116
138
  }
117
139
  }
118
140
  async function changeAccessRole(e) {
@@ -123,6 +145,17 @@
123
145
  }
124
146
  await fetchAndReset(true);
125
147
  }
148
+ async function downloadZip() {
149
+ const filesToZip=[]
150
+ for (const fileNm of selectedList) {
151
+ filesToZip.push(fileNm)
152
+
153
+ }
154
+ await POST(`/files/download-zip`, {
155
+ files: filesToZip,
156
+ location: currentFolder
157
+ }, true);
158
+ }
126
159
  async function moveDirectory(e) {
127
160
  for (const fileNm of selectedList) {
128
161
  const new_path = e.target.value;
@@ -363,8 +396,19 @@
363
396
  {#if selectedList.length === 1}
364
397
  <option>Rename</option>
365
398
  {/if}
399
+ {#if selectedList.length === 1 && lastSelected.filename.endsWith(".zip")}
400
+ <option>Unzip</option>
401
+ {/if}
366
402
  </select>
367
403
  </div>
404
+ {#if selectedList.length > 1}
405
+ <button class="btn btn-outline-secondary mt-2"
406
+ on:click={downloadZip}>
407
+ <i class="fas fa-file-archive"></i>
408
+ Download Zip Archive
409
+ </button>
410
+ {/if}
411
+
368
412
  {/if}
369
413
  </div>
370
414
  </div>