Skip to content

Commit

Permalink
fix shared download regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsapenna authored and Hang Le committed Oct 25, 2023
1 parent 00b0d5e commit 246c951
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 30 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- (GL #1137) Fix upload repeatability and worker lifecycle issues leading to upload unavailability
- (GL #1127) Fix `ServiceWorker` issues affecting Firefox downloads
- (GL #1091) Fix subfolder download button downloading only one file
- (GL #1129) Fix shared folder uploads and downloads in the new upload implementation (follow-up)

### Removed

Expand Down
77 changes: 49 additions & 28 deletions swift_browser_ui_frontend/src/common/socket.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Functions for handling interfacing between workers and upload API socket

import { DELETE, GET, PUT, getUploadEndpoint, getUploadSocket } from "./api";
import { getUploadEndpoint, getUploadSocket, signedFetch } from "./api";
import { DEV } from "./conv";
import { getDB } from "./db";

Expand Down Expand Up @@ -89,6 +89,8 @@ export default class UploadSocket {
e.data.container,
e.data.files,
e.data.pubkey,
e.data.owner,
e.data.ownerName,
).then(() => {
if (DEV) {
console.log(
Expand Down Expand Up @@ -146,7 +148,7 @@ export default class UploadSocket {
}

// Get headers for download
async getHeaders(container, fileList, pubkey) {
async getHeaders(container, fileList, pubkey, owner, ownerName) {
let headers = {};

// If no files are specified, get all files in the container
Expand All @@ -173,38 +175,34 @@ export default class UploadSocket {
container,
);

let signatureUrl = new URL(`/sign/${60}`, document.location.origin);
signatureUrl.searchParams.append("path", whitelistPath);
let signed = await GET(signatureUrl);
signed = await signed.json();
let whitelistUrl = new URL(
this.$store.state.uploadEndpoint.concat(whitelistPath),
await signedFetch(
"PUT",
this.$store.state.uploadEndpoint,
whitelistPath,
pubkey,
{
flavor: "crypt4gh",
session: upInfo.id,
},
);
whitelistUrl.searchParams.append("valid", signed.valid);
whitelistUrl.searchParams.append("signature", signed.signature);
whitelistUrl.searchParams.append("flavor", "crypt4gh");
whitelistUrl.searchParams.append("session", upInfo.id);
await PUT(whitelistUrl, pubkey);

for (const file of files) {
// Get the file header
let headerPath = `/header/${this.active.name}/${container}/${file}`;
signatureUrl = new URL(`/sign/${60}`, document.location.origin);
signatureUrl.searchParams.append("path", headerPath);
signed = await GET(signatureUrl);
signed = await signed.json();
let headerUrl = new URL(
this.$store.state.uploadEndpoint.concat(headerPath),
let header = await signedFetch(
"GET",
this.$store.state.uploadEndpoint,
`/header/${this.active.name}/${container}/${file}`,
undefined,
{
session: upInfo.id,
owner: ownerName,
},
);
headerUrl.searchParams.append("valid", signed.valid);
headerUrl.searchParams.append("signature", signed.signature);
headerUrl.searchParams.append("session", upInfo.id);
let resp = await GET(headerUrl);
let header = await resp.text();
header = await header.text();

// Prepare and sign the file URL
// Prepare the file URL
let fileUrl = new URL(
`/download/${this.active.id}/${container}/${file}`,
`/download/${owner ? owner : this.active.id}/${container}/${file}`,
document.location.origin,
);
fileUrl.searchParams.append("project", this.active.id);
Expand All @@ -215,7 +213,15 @@ export default class UploadSocket {
};
}

await DELETE(whitelistUrl);
await signedFetch(
"DELETE",
this.$store.state.uploadEndpoint,
whitelistPath,
undefined,
{
session: upInfo.id,
},
);

if (!this.useServiceWorker) {
this.downWorker.postMessage({
Expand Down Expand Up @@ -290,7 +296,14 @@ export default class UploadSocket {
async addDownload(
container,
objects,
owner = "",
) {
let ownerName = "";
if (owner) {
let ids = await this.$store.state.client.projectCheckIDs(owner);
ownerName = ids.name;
}

let fileHandle = undefined;
if (objects.length == 1) {
// Download directly into the file if available.
Expand All @@ -315,6 +328,8 @@ export default class UploadSocket {
container: container,
file: objects[0],
handle: fileHandle,
owner: owner,
ownerName: ownerName,
});
} else {
if (DEV) {
Expand All @@ -325,6 +340,8 @@ export default class UploadSocket {
command: "downloadFile",
container: container,
file: objects[0],
owner: owner,
ownerName: ownerName,
});
});
}
Expand All @@ -348,13 +365,17 @@ export default class UploadSocket {
container: container,
files: objects.length < 1 ? [] : objects,
handle: fileHandle,
owner: owner,
ownerName: ownerName,
});
} else {
navigator.serviceWorker.ready.then(reg => {
reg.active.postMessage({
command: "downloadFiles",
container: container,
files: objects.length < 1 ? [] : objects,
owner: owner,
ownerName: ownerName,
});
});
}
Expand Down
2 changes: 2 additions & 0 deletions swift_browser_ui_frontend/src/components/CObjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,15 @@ export default {
this.$store.state.socket.addDownload(
this.$route.params.container,
subfolderFiles,
this.$route.params.owner ? this.$route.params.owner : "",
).then(() => {
if (DEV) console.log(`Started downloading subfolder ${object.name}`);
});
} else {
this.$store.state.socket.addDownload(
this.$route.params.container,
[object.name],
this.$route.params.owner ? this.$route.params.owner : "",
).then(() => {
if (DEV) console.log(`Started downloading object ${object.name}`);
});
Expand Down
8 changes: 6 additions & 2 deletions swift_browser_ui_frontend/src/components/ContainerTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ export default {
size: "small",
title: this.$t("message.download"),
onClick: () => {
this.beginDownload(item.name);
this.beginDownload(
item.name,
item.owner ? item.owner : "",
);
},
target: "_blank",
path: mdiTrayArrowDown,
Expand Down Expand Up @@ -485,10 +488,11 @@ export default {
this.paginationOptions.itemCount - 1,
});
},
beginDownload(container) {
beginDownload(container, owner) {
this.$store.state.socket.addDownload(
container,
[],
owner,
).then(() => {
if (DEV) console.log(`Started downloading all objects from container ${container}`);
});
Expand Down
8 changes: 8 additions & 0 deletions swift_browser_ui_frontend/wasm/js/crypt-post-downworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ self.addEventListener("message", (e) => {
e.data.file,
],
pubkey: downloads[e.data.container].pubkey,
owner: e.data.owner,
ownerName: e.data.ownerName,
});
} else {
createDownloadSession(e.data.container, e.data.handle, false);
Expand All @@ -441,6 +443,8 @@ self.addEventListener("message", (e) => {
e.data.file,
],
pubkey: downloads[e.data.container].pubkey,
owner: e.data.owner,
ownerName: e.data.ownerName,
});
}
break;
Expand All @@ -452,6 +456,8 @@ self.addEventListener("message", (e) => {
container: e.data.container,
files: e.data.files,
pubkey: downloads[e.data.container].pubkey,
owner: e.data.owner,
ownerName: e.data.ownerName,
});
} else {
createDownloadSession(e.data.container, e.data.handle, true);
Expand All @@ -460,6 +466,8 @@ self.addEventListener("message", (e) => {
container: e.data.container,
files: e.data.files,
pubkey: downloads[e.data.container].pubkey,
owner: e.data.owner,
ownerName: e.data.ownerName,
});
}
break;
Expand Down

0 comments on commit 246c951

Please sign in to comment.