feat: send metadata along with download request

This commit is contained in:
thecodrr
2021-11-18 15:17:02 +05:00
parent 9ccb0fee12
commit 2c927a5dd7
3 changed files with 37 additions and 26 deletions

View File

@@ -8,28 +8,29 @@ export default class FileStorage {
this._queue = [];
}
async downloadFile(groupId, hash, chunkSize) {
const url = `${hosts.API_HOST}/s3?name=${hash}`;
async downloadFile(groupId, filename, chunkSize, metadata) {
const url = `${hosts.API_HOST}/s3?name=${filename}`;
const token = await this.tokenManager.getAccessToken();
const { execute, cancel } = this.fs.downloadFile(hash, {
const { execute, cancel } = this.fs.downloadFile(filename, {
metadata,
url,
chunkSize,
headers: { Authorization: `Bearer ${token}` },
});
this._queue.push({ groupId, hash, cancel, type: "download" });
this._queue.push({ groupId, filename, cancel, type: "download" });
const result = await execute();
this._deleteOp(groupId, "download");
return result;
}
async uploadFile(groupId, hash) {
async uploadFile(groupId, filename) {
const token = await this.tokenManager.getAccessToken();
const url = `${hosts.API_HOST}/s3?name=${hash}`;
const { execute, cancel } = this.fs.uploadFile(hash, {
const url = `${hosts.API_HOST}/s3?name=${filename}`;
const { execute, cancel } = this.fs.uploadFile(filename, {
url,
headers: { Authorization: `Bearer ${token}` },
});
this._queue.push({ groupId, hash, cancel, type: "upload" });
this._queue.push({ groupId, filename, cancel, type: "upload" });
const result = await execute();
this._deleteOp(groupId, "upload");
return result;
@@ -65,7 +66,7 @@ export default class FileStorage {
if (localOnly) return await this.fs.deleteFile(filename);
const token = await this.tokenManager.getToken();
const url = `${hosts.API_HOST}/s3?name=${hash}`;
const url = `${hosts.API_HOST}/s3?name=${filename}`;
return await this.fs.deleteFile(filename, {
url,
headers: { Authorization: `Bearer ${token}` },