mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-16 07:46:31 +00:00
fix(image-stream): Remove inability to fallback to octet-stream (#1363)
Using `mime-types` in that place made it impossible to use other other file extensions like `.sdcard` and have them treated as `application/octet-stream` when drag and dropping images into Etcher. This moves the fallback logic in `lib/image-stream` to `.getFromFilePath()`, to still facilitate proper MIME type detection, while allowing it to fall back to the octet-stream handler, if there's no available handler for a specific type. Change-Type: patch Changelog-Entry: Fix not treating unknown images as octet-stream
This commit is contained in:
parent
1cf4cdcee9
commit
becca2d05e
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -32,3 +32,4 @@ Makefile text
|
|||||||
*.xz binary
|
*.xz binary
|
||||||
*.zip binary
|
*.zip binary
|
||||||
*.dmg binary
|
*.dmg binary
|
||||||
|
*.rpi-sdcard binary
|
||||||
|
@ -76,14 +76,9 @@ exports.getFromFilePath = (file) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return utils.getArchiveMimeType(file).then((type) => {
|
return utils.getArchiveMimeType(file).then((type) => {
|
||||||
if (!_.has(handlers, type)) {
|
const MIME_TYPE_RAW_IMAGE = 'application/octet-stream';
|
||||||
throw errors.createUserError({
|
const mimeType = _.has(handlers, type) ? type : MIME_TYPE_RAW_IMAGE;
|
||||||
title: 'Invalid image',
|
return _.invoke(handlers, mimeType, file, {
|
||||||
description: `The ${type} format is not supported`
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return _.invoke(handlers, type, file, {
|
|
||||||
size: fileStats.size
|
size: fileStats.size
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -41,10 +41,6 @@ exports.getArchiveMimeType = (filename) => {
|
|||||||
const mimeType = mime.lookup(filename);
|
const mimeType = mime.lookup(filename);
|
||||||
|
|
||||||
if (mimeType) {
|
if (mimeType) {
|
||||||
if (mimeType === 'application/x-iso9660-image') {
|
|
||||||
return Bluebird.resolve(MIME_TYPE_RAW_IMAGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Bluebird.resolve(mimeType);
|
return Bluebird.resolve(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
tests/image-stream/data/unrecognized/random.rpi-sdcard
Normal file
BIN
tests/image-stream/data/unrecognized/random.rpi-sdcard
Normal file
Binary file not shown.
@ -61,10 +61,10 @@ describe('ImageStream: Utils', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should resolve application/octet-stream for an uncompressed iso', function() {
|
it('should resolve application/x-iso9660-image for an uncompressed iso', function() {
|
||||||
const file = path.join(DATA_PATH, 'images', 'raspberrypi.iso');
|
const file = path.join(DATA_PATH, 'images', 'raspberrypi.iso');
|
||||||
return utils.getArchiveMimeType(file).then((type) => {
|
return utils.getArchiveMimeType(file).then((type) => {
|
||||||
m.chai.expect(type).to.equal('application/octet-stream');
|
m.chai.expect(type).to.equal('application/x-iso9660-image');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -82,6 +82,13 @@ describe('ImageStream: Utils', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should resolve application/octet-stream for an unrecognized file type', function() {
|
||||||
|
const file = path.join(DATA_PATH, 'unrecognized', 'random.rpi-sdcard');
|
||||||
|
return utils.getArchiveMimeType(file).then((type) => {
|
||||||
|
m.chai.expect(type).to.equal('application/octet-stream');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('.extractStream()', function() {
|
describe('.extractStream()', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user