Simplify content type shown in dir lists

This commit is contained in:
Basti 2017-11-12 15:06:07 +01:00
parent 0db37c96f5
commit ab4dca82fd
3 changed files with 18 additions and 1 deletions

View File

@ -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
}));
});

View File

@ -0,0 +1,3 @@
export default function simpleContentType(str) {
return str.replace(/;.*$/, '');
}

View File

@ -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');
});