From aa8767eb0bf0735045482169813b214016b32e40 Mon Sep 17 00:00:00 2001 From: Logan Date: Mon, 24 Jul 2023 04:05:35 +0800 Subject: [PATCH] Revert "feat: s3 multipart upload" This reverts commit 157f45f765d46d7360fd4fa099e56d235084b7b4. --- src/helpers/index.ts | 68 ++------------------------------------------ yarn.lock | 2 +- 2 files changed, 3 insertions(+), 67 deletions(-) diff --git a/src/helpers/index.ts b/src/helpers/index.ts index 8927bedfe..111315658 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -27,7 +27,7 @@ export const validateImage = (file: RcFile, fileSize?: number) => { return isImage && inSize } -export const uploadFileOld = async (key: string, file: Blob, authToken: string | null, config?: AxiosRequestConfig) => +export const uploadFile = async (key: string, file: Blob, authToken: string | null, config?: AxiosRequestConfig) => await axios .post( `${process.env.REACT_APP_API_BASE_ROOT}/sys/sign-url`, @@ -45,7 +45,7 @@ export const uploadFileOld = async (key: string, file: Blob, authToken: string | .then(res => res.data.result) .then(url => { const { query } = queryString.parseUrl(url) - const a = axios.put<{ status: number; data: string }>(url, file, { + return axios.put<{ status: number; data: string }>(url, file, { ...config, headers: { ...query, @@ -54,70 +54,6 @@ export const uploadFileOld = async (key: string, file: Blob, authToken: string | }) }) -export const uploadFile = async (key: string, file: Blob, authToken: string | null, config?: AxiosRequestConfig) => { - if (!file) { - throw new Error('no file') - } - try { - const createResponse = await axios.post( - `${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}/storage/multipart/create`, - { - params: { Key: key, type: file.type }, - }, - { - headers: { authorization: `Bearer ${authToken}` }, - }, - ) - const { uploadId } = createResponse.data - - const PART_SIZE = 5 * 1024 * 1024 // 5MB - const { size } = file - const partCount = Math.max(Math.ceil(size / PART_SIZE), 1) - let parts = [] - - for (let partNumber = 1; partNumber <= partCount; partNumber++) { - const start = (partNumber - 1) * PART_SIZE - const end = partNumber * PART_SIZE - - const presignResponse = await axios.post( - `${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}/storage/multipart/sign-url`, - { - params: { Key: key, UploadId: uploadId, PartNumber: partNumber }, - }, - { - headers: { authorization: `Bearer ${authToken}` }, - }, - ) - const { presignedUrl } = presignResponse.data - - const uploadResponse = await axios.put(presignedUrl, file.slice(start, end), { - ...config, - headers: { - 'Content-Type': file.type, - }, - }) - parts.push({ - ETag: `${uploadResponse.headers.etag}`, - PartNumber: partNumber, - }) - } - - const completedUploadResponse = await axios.post( - `${process.env.REACT_APP_LODESTAR_SERVER_ENDPOINT}/storage/multipart/complete`, - { - params: { Key: key, UploadId: uploadId, MultipartUpload: { Parts: parts } }, - }, - { - headers: { authorization: `Bearer ${authToken}` }, - }, - ) - return { data: completedUploadResponse.data, status: completedUploadResponse.status } - } catch (error) { - console.log(error) - throw error - } -} - export const uploadFileV2 = async ( key: string, file: Blob, diff --git a/yarn.lock b/yarn.lock index 7fcf86b83..c6dfa9850 100644 --- a/yarn.lock +++ b/yarn.lock @@ -13959,7 +13959,7 @@ lodash.upperfirst@^4.3.1: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== -lodestar-app-element@urfit-tech/lodestar-app-element#master: +lodestar-app-element@urfit-tech/lodestar-app-element#5618d2672b405edb3840bd28d4be27b2c6e80167: version "0.1.0" resolved "https://codeload.github.com/urfit-tech/lodestar-app-element/tar.gz/8cda736c5d040bb677f26ef9ad1fdcbb838cc2a2" dependencies: