import { validateResponse } from './helpers' ; import { ChromeSyncStorage } from './types' ; const baseUrl = 'STELLAR_ENV' === 'dev' ? 'http://localhost:8080' : 'https://stellar-photos.herokuapp.com' ; async function makeRequest ( url ) { const response = await fetch ( url ) ; return validateResponse ( response ) ; } function getRandomPhoto ( collections , resolution ) { return makeRequest ( `${ baseUrl }/random-photo/?collections=${ collections }&resolution=${ resolution }` ) ; } function searchPhotos ( key , page ) { return makeRequest ( `${ baseUrl }/search-unsplash/?key=${ key }&page=${ page }` ) ; } function validateCollections ( collections ) { return makeRequest ( `${ baseUrl }/validate-collections/?collections=${ collections }` ) ; } function saveToDropboxApi ( imageId , dropboxToken , url ) { return makeRequest ( `${ baseUrl }/dropbox/save/?id=${ imageId }&token=${ dropboxToken }&url=${ url }` ) ; } function getDropboxKey ( ) { return makeRequest ( `${ baseUrl }/dropbox/key/` ) ; } function authorizeOnedrive ( code ) { return makeRequest ( `${ baseUrl }/onedrive/auth/?code=${ code }` ) ; } function refreshOnedriveTokenApi ( token ) { return makeRequest ( `${ baseUrl }/onedrive/refresh/?refresh_token=${ token }` ) ; } function trackDownload ( id ) { return makeRequest ( `${ baseUrl }/download-photo/?id=${ id }` ) ; } function getOnedriveId ( ) { return makeRequest ( `${ baseUrl }/onedrive/id/` ) ; } function getGoogleDriveKey ( ) { return makeRequest ( `${ baseUrl }/googledrive/key/` ) ; } function authorizeGoogleDrive ( code ) { return makeRequest ( `${ baseUrl }/googledrive/auth/?code=${ code }` ) ; } function refreshGoogleDriveTokenApi ( token ) { return makeRequest ( `${ baseUrl }/googledrive/refresh/?refresh_token=${ token }` ) ; } function saveToGoogleDriveApi ( imageId , token , url ) { return makeRequest ( `${ baseUrl }/googledrive/save/?id=${ imageId }&token=${ token }&url=${ url }` ) ; } export { getRandomPhoto , searchPhotos , saveToDropboxApi , getDropboxKey , authorizeOnedrive , refreshOnedriveTokenApi , validateCollections , trackDownload , getOnedriveId , getGoogleDriveKey , authorizeGoogleDrive , refreshGoogleDriveTokenApi , saveToGoogleDriveApi , } ;