uploads via workers
This commit is contained in:
parent
346352a780
commit
53f4e5ed92
|
@ -1,5 +1,5 @@
|
|||
import HTTPService from 'services/HTTPService';
|
||||
import { getEndpoint } from 'utils/common/apiUtil';
|
||||
import { getEndpoint, getUploadEndpoint } from 'utils/common/apiUtil';
|
||||
import { getToken } from 'utils/common/key';
|
||||
import { logError } from 'utils/sentry';
|
||||
import { EnteFile } from 'types/file';
|
||||
|
@ -8,6 +8,7 @@ import { UploadFile, UploadURL, MultipartUploadURLs } from 'types/upload';
|
|||
import { retryHTTPCall } from 'utils/upload/uploadRetrier';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
const UPLOAD_ENDPOINT = getUploadEndpoint();
|
||||
const MAX_URL_REQUESTS = 50;
|
||||
|
||||
class UploadHttpClient {
|
||||
|
@ -92,10 +93,12 @@ class UploadHttpClient {
|
|||
try {
|
||||
await retryHTTPCall(() =>
|
||||
HTTPService.put(
|
||||
fileUploadURL.url,
|
||||
`${UPLOAD_ENDPOINT}/file-upload`,
|
||||
file,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
'UPLOAD-URL': fileUploadURL.url,
|
||||
},
|
||||
progressTracker
|
||||
)
|
||||
);
|
||||
|
@ -114,20 +117,22 @@ class UploadHttpClient {
|
|||
try {
|
||||
const response = await retryHTTPCall(async () => {
|
||||
const resp = await HTTPService.put(
|
||||
partUploadURL,
|
||||
`${UPLOAD_ENDPOINT}/multipart-upload`,
|
||||
filePart,
|
||||
null,
|
||||
null,
|
||||
{
|
||||
'UPLOAD-URL': partUploadURL,
|
||||
},
|
||||
progressTracker
|
||||
);
|
||||
if (!resp?.headers?.etag) {
|
||||
if (!resp?.data?.etag) {
|
||||
const err = Error(CustomError.ETAG_MISSING);
|
||||
logError(err, 'putFile in parts failed');
|
||||
throw err;
|
||||
}
|
||||
return resp;
|
||||
});
|
||||
return response.headers.etag as string;
|
||||
return response.data.etag as string;
|
||||
} catch (e) {
|
||||
logError(e, 'put filePart failed');
|
||||
throw e;
|
||||
|
@ -137,9 +142,15 @@ class UploadHttpClient {
|
|||
async completeMultipartUpload(completeURL: string, reqBody: any) {
|
||||
try {
|
||||
await retryHTTPCall(() =>
|
||||
HTTPService.post(completeURL, reqBody, null, {
|
||||
'content-type': 'text/xml',
|
||||
})
|
||||
HTTPService.post(
|
||||
`${UPLOAD_ENDPOINT}/multipart-complete`,
|
||||
reqBody,
|
||||
null,
|
||||
{
|
||||
'content-type': 'text/xml',
|
||||
'UPLOAD-URL': completeURL,
|
||||
}
|
||||
)
|
||||
);
|
||||
} catch (e) {
|
||||
logError(e, 'put file in parts failed');
|
||||
|
|
|
@ -51,3 +51,10 @@ export const getFamilyPortalURL = () => {
|
|||
}
|
||||
return `https://family.ente.io`;
|
||||
};
|
||||
|
||||
export const getUploadEndpoint = () => {
|
||||
if (process.env.NEXT_PUBLIC_ENTE_UPLOAD_ENDPOINT !== undefined) {
|
||||
return process.env.NEXT_PUBLIC_ENTE_UPLOAD_ENDPOINT;
|
||||
}
|
||||
return `http://localhost:8787`;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue