mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-27 21:26:38 +00:00
Fix write step for Http file process
Change-type: patch Signed-off-by: Andrea Rosci <andrear@balena.io>
This commit is contained in:
parent
00e8f11913
commit
1e1bd3c508
@ -65,6 +65,7 @@ import SrcSvg from '../../../assets/src.svg';
|
|||||||
import { DriveSelector } from '../drive-selector/drive-selector';
|
import { DriveSelector } from '../drive-selector/drive-selector';
|
||||||
import { DrivelistDrive } from '../../../../shared/drive-constraints';
|
import { DrivelistDrive } from '../../../../shared/drive-constraints';
|
||||||
import axios, { AxiosRequestConfig } from 'axios';
|
import axios, { AxiosRequestConfig } from 'axios';
|
||||||
|
import { isJson } from '../../../../shared/utils';
|
||||||
|
|
||||||
const recentUrlImagesKey = 'recentUrlImages';
|
const recentUrlImagesKey = 'recentUrlImages';
|
||||||
|
|
||||||
@ -378,7 +379,9 @@ export class SourceSelector extends React.Component<
|
|||||||
this.setState({ imageLoading: true });
|
this.setState({ imageLoading: true });
|
||||||
await this.selectSource(
|
await this.selectSource(
|
||||||
imagePath,
|
imagePath,
|
||||||
isURL(imagePath) ? sourceDestination.Http : sourceDestination.File,
|
isURL(this.normalizeImagePath(imagePath))
|
||||||
|
? sourceDestination.Http
|
||||||
|
: sourceDestination.File,
|
||||||
).promise;
|
).promise;
|
||||||
this.setState({ imageLoading: false });
|
this.setState({ imageLoading: false });
|
||||||
}
|
}
|
||||||
@ -394,7 +397,7 @@ export class SourceSelector extends React.Component<
|
|||||||
analytics.logException(error);
|
analytics.logException(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.isJson(decodeURIComponent(selected))) {
|
if (isJson(decodeURIComponent(selected))) {
|
||||||
const config: AxiosRequestConfig = JSON.parse(
|
const config: AxiosRequestConfig = JSON.parse(
|
||||||
decodeURIComponent(selected),
|
decodeURIComponent(selected),
|
||||||
);
|
);
|
||||||
@ -413,13 +416,12 @@ export class SourceSelector extends React.Component<
|
|||||||
return new sourceDestination.Http({ url: selected, auth });
|
return new sourceDestination.Http({ url: selected, auth });
|
||||||
}
|
}
|
||||||
|
|
||||||
public isJson(jsonString: string) {
|
public normalizeImagePath(imgPath: string) {
|
||||||
try {
|
const decodedPath = decodeURIComponent(imgPath);
|
||||||
JSON.parse(jsonString);
|
if (isJson(decodedPath)) {
|
||||||
} catch (e) {
|
return JSON.parse(decodedPath).url ?? decodedPath;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return decodedPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private reselectSource() {
|
private reselectSource() {
|
||||||
@ -445,7 +447,10 @@ export class SourceSelector extends React.Component<
|
|||||||
let source;
|
let source;
|
||||||
let metadata: SourceMetadata | undefined;
|
let metadata: SourceMetadata | undefined;
|
||||||
if (isString(selected)) {
|
if (isString(selected)) {
|
||||||
if (SourceType === sourceDestination.Http && !isURL(selected)) {
|
if (
|
||||||
|
SourceType === sourceDestination.Http &&
|
||||||
|
!isURL(this.normalizeImagePath(selected))
|
||||||
|
) {
|
||||||
this.handleError(
|
this.handleError(
|
||||||
'Unsupported protocol',
|
'Unsupported protocol',
|
||||||
selected,
|
selected,
|
||||||
|
@ -35,8 +35,10 @@ import { totalmem } from 'os';
|
|||||||
|
|
||||||
import { toJSON } from '../../shared/errors';
|
import { toJSON } from '../../shared/errors';
|
||||||
import { GENERAL_ERROR, SUCCESS } from '../../shared/exit-codes';
|
import { GENERAL_ERROR, SUCCESS } from '../../shared/exit-codes';
|
||||||
import { delay } from '../../shared/utils';
|
import { delay, isJson } from '../../shared/utils';
|
||||||
import { SourceMetadata } from '../app/components/source-selector/source-selector';
|
import { SourceMetadata } from '../app/components/source-selector/source-selector';
|
||||||
|
import axios from 'axios';
|
||||||
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
ipc.config.id = process.env.IPC_CLIENT_ID as string;
|
ipc.config.id = process.env.IPC_CLIENT_ID as string;
|
||||||
ipc.config.socketRoot = process.env.IPC_SOCKET_ROOT as string;
|
ipc.config.socketRoot = process.env.IPC_SOCKET_ROOT as string;
|
||||||
@ -171,6 +173,7 @@ interface WriteOptions {
|
|||||||
autoBlockmapping: boolean;
|
autoBlockmapping: boolean;
|
||||||
decompressFirst: boolean;
|
decompressFirst: boolean;
|
||||||
SourceType: string;
|
SourceType: string;
|
||||||
|
httpRequest?: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
ipc.connectTo(IPC_SERVER_ID, () => {
|
ipc.connectTo(IPC_SERVER_ID, () => {
|
||||||
@ -281,7 +284,17 @@ ipc.connectTo(IPC_SERVER_ID, () => {
|
|||||||
path: imagePath,
|
path: imagePath,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
source = new Http({ url: imagePath, avoidRandomAccess: true });
|
const decodedImagePath = decodeURIComponent(imagePath);
|
||||||
|
if (isJson(decodedImagePath)) {
|
||||||
|
const imagePathObject = JSON.parse(decodedImagePath);
|
||||||
|
source = new Http({
|
||||||
|
url: imagePathObject.url,
|
||||||
|
avoidRandomAccess: true,
|
||||||
|
axiosInstance: axios.create(_.omit(imagePathObject, ['url'])),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
source = new Http({ url: imagePath, avoidRandomAccess: true });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const results = await writeAndValidate({
|
const results = await writeAndValidate({
|
||||||
|
@ -61,3 +61,12 @@ export function getAppPath(): string {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isJson(jsonString: string) {
|
||||||
|
try {
|
||||||
|
JSON.parse(jsonString);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user