import { getApiUrl } from "./getApiUrl" ; import { getApiKey } from "./getApiKey" ; import { queryStringify } from "./queryStringify" ; export function uploadPixabayImages ( value ) { const apiUrl = getApiUrl ( ) ; const apiKey = getApiKey ( ) ; const images = typeof value === "string" ? [ JSON . parse ( value ) ] : value . map ( ( v ) : string => JSON . parse ( v ) ) ; const response = UrlFetchApp . fetch ( apiUrl + '/upload-pixabay-images' , { method : "post" , payload : { images : JSON . stringify ( images ) } , headers : { Authorization : "Bearer " + apiKey } , muteHttpExceptions : true } ) ; if ( response . getResponseCode ( ) === 200 ) { return JSON . parse ( response . getContentText ( ) ) . urls ; } else if ( response . getResponseCode ( ) === 401 ) { throw new Error ( "The API key is invalid or expired." ) ; } else { throw new Error ( response . getContentText ( ) ) ; } }