diff --git a/lib/gui/app/components/source-selector/source-selector.tsx b/lib/gui/app/components/source-selector/source-selector.tsx index 68c037ae..411b0b51 100644 --- a/lib/gui/app/components/source-selector/source-selector.tsx +++ b/lib/gui/app/components/source-selector/source-selector.tsx @@ -61,6 +61,7 @@ import ImageSvg from '../../../assets/image.svg'; import SrcSvg from '../../../assets/src.svg'; import { DriveSelector } from '../drive-selector/drive-selector'; import { DrivelistDrive } from '../../../../shared/drive-constraints'; +import axios, { AxiosRequestConfig } from 'axios'; const recentUrlImagesKey = 'recentUrlImages'; @@ -334,14 +335,34 @@ export class SourceSelector extends React.Component< analytics.logException(error); } + if (this.isJson(decodeURIComponent(selected))) { + const config: AxiosRequestConfig = JSON.parse( + decodeURIComponent(selected), + ); + return new sourceDestination.Http({ + url: config.url!, + axiosInstance: axios.create(_.omit(config, ['url'])), + }); + } + if (SourceType === sourceDestination.File) { return new sourceDestination.File({ path: selected, }); } + return new sourceDestination.Http({ url: selected }); } + public isJson(jsonString: string) { + try { + JSON.parse(jsonString); + } catch (e) { + return false; + } + return true; + } + private reselectSource() { analytics.logEvent('Reselect image', { previousImage: selectionState.getImage(),