feat: redirect request instead of returning presigned url

This commit is contained in:
thecodrr
2021-10-15 11:12:05 +05:00
parent d176a2e0dd
commit df13446e30

View File

@@ -23,8 +23,11 @@ export default class FileStorage {
async uploadFile(groupId, hash) { async uploadFile(groupId, hash) {
const token = await this.tokenManager.getAccessToken(); const token = await this.tokenManager.getAccessToken();
const url = await this._getPresignedURL(hash, token, "PUT"); const url = `${hosts.API_HOST}/s3?name=${hash}`;
const { execute, cancel } = this.fs.uploadFile(hash, { url }); const { execute, cancel } = this.fs.uploadFile(hash, {
url,
headers: { Authorization: `Bearer ${token}` },
});
this._queue.push({ groupId, hash, cancel, type: "upload" }); this._queue.push({ groupId, hash, cancel, type: "upload" });
const result = await execute(); const result = await execute();
this._deleteOp(groupId, "upload"); this._deleteOp(groupId, "upload");
@@ -76,15 +79,4 @@ export default class FileStorage {
exists(filename) { exists(filename) {
return this.fs.exists(filename); return this.fs.exists(filename);
} }
async _getPresignedURL(filename, token, verb) {
const response = await fetch(`${hosts.API_HOST}/s3?name=${filename}`, {
method: verb,
headers: {
Authorization: `Bearer ${token}`,
},
});
if (response.ok) return await response.text();
throw new Error("Couldn't get presigned url.");
}
} }