File tree Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Expand file tree Collapse file tree 2 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -98,11 +98,11 @@ export const seedDatabaseFromApi = async (
9898}
9999
100100const getImageIdFromImageUrl = ( url : string ) : string => {
101- const image_url = new URL ( url )
102- const image_id = image_url . searchParams . get ( "image_id" )
103- if ( image_id == null ) {
104- throw new Error ( `No image_id in ${ url } ` )
105- }
101+ const searchParams = new URL ( url ) . searchParams
102+ const imageId = searchParams . get ( "image_id" )
103+ if ( imageId ) return imageId
106104
107- return image_id
105+ const proxiedUrl = searchParams . get ( "url" )
106+ if ( ! proxiedUrl ) throw new Error ( `No image_id in "${ url } "` )
107+ return getImageIdFromImageUrl ( proxiedUrl )
108108}
Original file line number Diff line number Diff line change @@ -92,6 +92,19 @@ test("seed database from api", async (t) => {
9292 await seedDatabaseFromApi ( db , client )
9393 } )
9494
95+ const client_with_proxied_images = axios . create ( {
96+ baseURL : serverURL ,
97+ headers : {
98+ "x-vercel-protection-bypass" : db . vercel_protection_bypass_secret ,
99+ "x-forwarded-seam-base-url" :
100+ "https://example.com/devicedb?url=https://example.com/devicedb" ,
101+ } ,
102+ } )
103+
104+ await t . notThrowsAsync ( async ( ) => {
105+ await seedDatabaseFromApi ( db , client_with_proxied_images )
106+ } )
107+
95108 t . deepEqual ( db . manufacturers [ 0 ] , { ...manufacturer , device_model_count : 1 } )
96109 t . deepEqual ( db . device_models [ 0 ] , device_model )
97110} )
You can’t perform that action at this time.
0 commit comments