11import basePathConvert from '../../utils/basePathConvert'
22import { lighthouseConfig } from '../../../lighthouse.config'
33import { UploadFileReturnType , DealParameters } from '../../../types'
4- import { retryFetch } from '../../utils/util'
4+ import { fetchWithTimeout } from '../../utils/util'
55
66export async function walk ( dir : string ) {
77 const { readdir, stat } = eval ( `require` ) ( 'fs-extra' )
@@ -25,7 +25,6 @@ export async function walk(dir: string) {
2525export default async < T extends boolean > (
2626 sourcePath : string ,
2727 apiKey : string ,
28- multi : boolean ,
2928 dealParameters : DealParameters | undefined
3029) : Promise < { data : UploadFileReturnType < T > } > => {
3130 const { createReadStream, lstatSync } = eval ( `require` ) ( 'fs-extra' )
@@ -36,7 +35,7 @@ export default async <T extends boolean>(
3635 try {
3736 const endpoint =
3837 lighthouseConfig . lighthouseNode +
39- `/api/v0/add?wrap-with-directory=${ multi } `
38+ `/api/v0/add?wrap-with-directory=false `
4039 if ( stats . isFile ( ) ) {
4140 const data = new FormData ( )
4241 const stream = createReadStream ( sourcePath )
@@ -48,7 +47,7 @@ export default async <T extends boolean>(
4847
4948 data . append ( 'file' , blob , path . basename ( sourcePath ) )
5049
51- const response = await retryFetch ( endpoint , {
50+ const response = await fetchWithTimeout ( endpoint , {
5251 method : 'POST' ,
5352 body : data ,
5453 credentials : 'include' ,
@@ -67,12 +66,7 @@ export default async <T extends boolean>(
6766 }
6867
6968 let responseData = ( await response . text ( ) ) as any
70- if ( multi ) {
71- const temp = responseData . split ( '\n' )
72- responseData = JSON . parse ( temp [ temp . length - 2 ] )
73- } else {
74- responseData = JSON . parse ( responseData )
75- }
69+ responseData = JSON . parse ( responseData )
7670
7771 return { data : responseData }
7872 } else {
@@ -90,11 +84,11 @@ export default async <T extends boolean>(
9084 data . append (
9185 'file' ,
9286 blob ,
93- multi ? path . basename ( file ) : basePathConvert ( sourcePath , file )
87+ basePathConvert ( sourcePath , file )
9488 )
9589 }
9690
97- const response = await retryFetch ( endpoint , {
91+ const response = await fetchWithTimeout ( endpoint , {
9892 method : 'POST' ,
9993 body : data ,
10094 credentials : 'include' ,
@@ -113,17 +107,7 @@ export default async <T extends boolean>(
113107 }
114108
115109 let responseData = ( await response . text ( ) ) as any
116-
117- if ( typeof responseData === 'string' ) {
118- if ( multi ) {
119- responseData = JSON . parse (
120- `[${ responseData . slice ( 0 , - 1 ) } ]` . split ( '\n' ) . join ( ',' )
121- )
122- } else {
123- const temp = responseData . split ( '\n' )
124- responseData = JSON . parse ( temp [ temp . length - 2 ] )
125- }
126- }
110+ responseData = JSON . parse ( responseData )
127111
128112 return { data : responseData }
129113 }
0 commit comments