diff --git a/app/routes/index.js b/app/routes/index.js index d1d5bb0..1f7a1aa 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -2,6 +2,7 @@ import Route from '@ember/routing/route'; import EmberObject from '@ember/object'; import { inject as service } from '@ember/service'; import { isEmpty } from '@ember/utils'; +import simpleContentType from 'inspektor/utils/simple-content-type'; export default Route.extend({ @@ -24,10 +25,12 @@ export default Route.extend({ return this.get('storage.client').getListing(path).then(listing => { Object.keys(listing).forEach(name => { let item = listing[name]; + let type = item['Content-Type'] || 'folder'; + if (type !== 'folder') { type = simpleContentType(type); } items.push(EmberObject.create({ name: name, - type: item['Content-Type'] || 'folder', + type: type, size: item['Content-Length'] || null })); }); diff --git a/app/utils/simple-content-type.js b/app/utils/simple-content-type.js new file mode 100644 index 0000000..7a90f65 --- /dev/null +++ b/app/utils/simple-content-type.js @@ -0,0 +1,3 @@ +export default function simpleContentType(str) { + return str.replace(/;.*$/, ''); +} diff --git a/tests/unit/utils/simple-content-type-test.js b/tests/unit/utils/simple-content-type-test.js new file mode 100644 index 0000000..f41cf4c --- /dev/null +++ b/tests/unit/utils/simple-content-type-test.js @@ -0,0 +1,11 @@ +import simpleContentType from 'inspektor/utils/simple-content-type'; +import { module, test } from 'qunit'; + +module('Unit | Utility | simple content type'); + +test('it removes the charset portion', function(assert) { + let type = 'application/json; charset=UTF-8'; + let result = simpleContentType(type); + + assert.equal(result, 'application/json'); +});