diff --git a/.gitattributes b/.gitattributes index 59f60375..24b437fe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -32,3 +32,4 @@ Makefile text *.xz binary *.zip binary *.dmg binary +*.rpi-sdcard binary diff --git a/lib/image-stream/index.js b/lib/image-stream/index.js index ea526063..adbcd2b7 100644 --- a/lib/image-stream/index.js +++ b/lib/image-stream/index.js @@ -76,14 +76,9 @@ exports.getFromFilePath = (file) => { } return utils.getArchiveMimeType(file).then((type) => { - if (!_.has(handlers, type)) { - throw errors.createUserError({ - title: 'Invalid image', - description: `The ${type} format is not supported` - }); - } - - return _.invoke(handlers, type, file, { + const MIME_TYPE_RAW_IMAGE = 'application/octet-stream'; + const mimeType = _.has(handlers, type) ? type : MIME_TYPE_RAW_IMAGE; + return _.invoke(handlers, mimeType, file, { size: fileStats.size }); }); diff --git a/lib/image-stream/utils.js b/lib/image-stream/utils.js index dcd1a940..f43d7a8c 100644 --- a/lib/image-stream/utils.js +++ b/lib/image-stream/utils.js @@ -41,10 +41,6 @@ exports.getArchiveMimeType = (filename) => { const mimeType = mime.lookup(filename); if (mimeType) { - if (mimeType === 'application/x-iso9660-image') { - return Bluebird.resolve(MIME_TYPE_RAW_IMAGE); - } - return Bluebird.resolve(mimeType); } diff --git a/tests/image-stream/data/unrecognized/random.rpi-sdcard b/tests/image-stream/data/unrecognized/random.rpi-sdcard new file mode 100644 index 00000000..0246d82a Binary files /dev/null and b/tests/image-stream/data/unrecognized/random.rpi-sdcard differ diff --git a/tests/image-stream/utils.spec.js b/tests/image-stream/utils.spec.js index 691d2a26..942e6bf4 100644 --- a/tests/image-stream/utils.spec.js +++ b/tests/image-stream/utils.spec.js @@ -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'); 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() {