Skip to content

Commit 4eec1f8

Browse files
committed
response fixes
1 parent a6b69e6 commit 4eec1f8

File tree

6 files changed

+16
-24
lines changed

6 files changed

+16
-24
lines changed

src/Lighthouse/uploadEncrypted/decrypt/browser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/* istanbul ignore file */
22
import { decryptFile } from '../encryptionBrowser'
33
import { lighthouseConfig } from '../../../lighthouse.config'
4-
import { retryFetch } from '../../utils/util'
4+
import { fetchWithTimeout } from '../../utils/util'
55

66
export default async (
77
cid: string,
88
fileEncryptionKey: string,
99
mimeType: string
1010
) => {
11-
const response = await retryFetch(
11+
const response = await fetchWithTimeout(
1212
lighthouseConfig.lighthouseGateway + '/api/v0/cat/' + cid,
1313
{
1414
method: 'POST',

src/Lighthouse/uploadEncrypted/decrypt/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* istanbul ignore file */
22
import { decryptFile } from '../encryptionNode'
33
import { lighthouseConfig } from '../../../lighthouse.config'
4-
import { retryFetch } from '../../utils/util'
4+
import { fetchWithTimeout } from '../../utils/util'
55

66
export default async (cid: string, fileEncryptionKey: any) => {
77
try {
8-
const response = await retryFetch(
8+
const response = await fetchWithTimeout(
99
lighthouseConfig.lighthouseGateway + '/api/v0/cat/' + cid,
1010
{
1111
method: 'POST',

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../../../../types'
77
import { encryptFile } from '../../encryptionBrowser'
88
import { lighthouseConfig } from '../../../../lighthouse.config'
9-
import { checkDuplicateFileNames, retryFetch } from '../../../utils/util'
9+
import { checkDuplicateFileNames, fetchWithTimeout } from '../../../utils/util'
1010

1111
declare const FileReader: any
1212

@@ -74,7 +74,7 @@ export default async (
7474
})
7575

7676
const response = uploadProgressCallback
77-
? await retryFetch(endpoint, {
77+
? await fetchWithTimeout(endpoint, {
7878
method: 'POST',
7979
body: formData,
8080
timeout: 7200000,
@@ -88,7 +88,7 @@ export default async (
8888
})
8989
},
9090
})
91-
: await retryFetch(endpoint, {
91+
: await fetchWithTimeout(endpoint, {
9292
method: 'POST',
9393
body: formData,
9494
timeout: 7200000,
@@ -115,13 +115,7 @@ export default async (
115115
new Uint8Array(chunks.flatMap((chunk) => [...chunk]))
116116
) as any
117117

118-
if (typeof responseData === 'string') {
119-
responseData = JSON.parse(
120-
`[${responseData.slice(0, -1)}]`.split('\n').join(',')
121-
)
122-
} else {
123-
responseData = [responseData]
124-
}
118+
responseData = JSON.parse(responseData)
125119

126120
const savedKey = await Promise.all(
127121
responseData.map(async (data: IFileUploadedResponse) => {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { generate, saveShards } from '@lighthouse-web3/kavach'
33
import { encryptFile } from '../../encryptionNode'
44
import { walk } from '../../../upload/files/node'
55
import { IFileUploadedResponse } from '../../../../types'
6-
import { retryFetch } from '../../../utils/util'
6+
import { fetchWithTimeout } from '../../../utils/util'
77

88
export default async (
99
sourcePath: any,
@@ -28,7 +28,7 @@ export default async (
2828
const blob = new Blob([Buffer.from(encryptedData)])
2929
formData.append('file', blob, sourcePath.replace(/^.*[\\/]/, ''))
3030

31-
const response = await retryFetch(endpoint, {
31+
const response = await fetchWithTimeout(endpoint, {
3232
method: 'POST',
3333
body: formData,
3434
timeout: 7200000,
@@ -81,7 +81,7 @@ export default async (
8181
})
8282
)
8383

84-
const response = await retryFetch(endpoint, {
84+
const response = await fetchWithTimeout(endpoint, {
8585
method: 'POST',
8686
body: formData,
8787
timeout: 7200000,
@@ -96,9 +96,7 @@ export default async (
9696
}
9797

9898
const responseText = await response.text()
99-
const jsondata = JSON.parse(
100-
`[${responseText.slice(0, -1)}]`.split('\n').join(',')
101-
) as IFileUploadedResponse[]
99+
const jsondata = JSON.parse(responseText) as IFileUploadedResponse[]
102100

103101
const savedKey = await Promise.all(
104102
jsondata.map(async (data) => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { encryptFile } from '../../encryptionBrowser'
33
import { generate, saveShards } from '@lighthouse-web3/kavach'
44
import { lighthouseConfig } from '../../../../lighthouse.config'
5-
import { retryFetch } from '../../../utils/util'
5+
import { fetchWithTimeout } from '../../../utils/util'
66

77
export default async (
88
text: string,
@@ -32,7 +32,7 @@ export default async (
3232
name
3333
)
3434

35-
const response = await retryFetch(endpoint, {
35+
const response = await fetchWithTimeout(endpoint, {
3636
method: 'POST',
3737
body: formData,
3838
timeout: 7200000,

src/Lighthouse/uploadEncrypted/encrypt/text/node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { encryptFile } from '../../encryptionNode'
33
import { generate, saveShards } from '@lighthouse-web3/kavach'
44
import { lighthouseConfig } from '../../../../lighthouse.config'
5-
import { retryFetch } from '../../../utils/util'
5+
import { fetchWithTimeout } from '../../../utils/util'
66

77
export default async (
88
text: string,
@@ -27,7 +27,7 @@ export default async (
2727
const blob = new Blob([Buffer.from(encryptedData)])
2828
formData.append('file', blob, name)
2929

30-
const response = await retryFetch(endpoint, {
30+
const response = await fetchWithTimeout(endpoint, {
3131
method: 'POST',
3232
body: formData,
3333
credentials: 'include',

0 commit comments

Comments
 (0)