Skip to content

Commit c0cfe85

Browse files
committed
progress parameters updated
1 parent 8b29785 commit c0cfe85

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

src/Lighthouse/upload/files/browser.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export default async <T extends boolean>(
4444
onProgress: (progress) => {
4545
uploadProgressCallback({
4646
progress: progress,
47-
total: 100, // We don't have the total size here, so we're using 100 as a percentage
48-
uploaded: progress * 100,
4947
})
5048
},
5149
})

src/Lighthouse/uploadEncrypted/encrypt/file/browser.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default async (
2929
apiKey: string,
3030
publicKey: string,
3131
auth_token: string,
32-
uploadProgressCallback: (data: IUploadProgressCallback) => void
32+
uploadProgressCallback?: (data: IUploadProgressCallback) => void
3333
): Promise<{ data: IFileUploadedResponse[] }> => {
3434
try {
3535
let keyMap = {} as any
@@ -73,40 +73,42 @@ export default async (
7373
)
7474
})
7575

76-
const controller = new AbortController()
77-
const signal = controller.signal
78-
const response = await retryFetch(endpoint, {
79-
method: 'POST',
80-
body: formData,
81-
timeout: 7200000,
82-
headers: {
83-
Encryption: `${true}`,
84-
Authorization: token,
85-
},
86-
signal,
87-
})
76+
const response = uploadProgressCallback
77+
? await retryFetch(endpoint, {
78+
method: 'POST',
79+
body: formData,
80+
timeout: 7200000,
81+
headers: {
82+
Encryption: `${true}`,
83+
Authorization: token,
84+
},
85+
onProgress: (progress) => {
86+
uploadProgressCallback({
87+
progress: progress,
88+
})
89+
},
90+
})
91+
: await retryFetch(endpoint, {
92+
method: 'POST',
93+
body: formData,
94+
timeout: 7200000,
95+
headers: {
96+
Encryption: `${true}`,
97+
Authorization: token,
98+
},
99+
})
88100
if (!response.ok) {
89101
throw new Error(`HTTP error! status: ${response.status}`)
90102
}
91103

92104
const reader = response.body?.getReader()
93-
const contentLength = +response.headers.get('Content-Length')!
94-
let receivedLength = 0
95105
let chunks = []
96106
while (true) {
97107
const { done, value } = await reader!.read()
98108
if (done) {
99109
break
100110
}
101111
chunks.push(value)
102-
receivedLength += value.length
103-
uploadProgressCallback({
104-
progress: contentLength
105-
? Math.round(receivedLength / contentLength)
106-
: 0,
107-
total: contentLength || 0,
108-
uploaded: receivedLength,
109-
})
110112
}
111113

112114
let responseData = new TextDecoder('utf-8').decode(

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
export interface IUploadProgressCallback {
22
progress: number
3-
total: number
4-
uploaded: number
53
}
64

75
export interface IFileUploadedResponse {

0 commit comments

Comments
 (0)