diff --git a/app/routes/index.js b/app/routes/index.js index 1f7a1aa..76b2cf7 100644 --- a/app/routes/index.js +++ b/app/routes/index.js @@ -1,8 +1,6 @@ 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({ @@ -16,27 +14,12 @@ export default Route.extend({ model(params) { let path = params.path; - let items = []; if (isEmpty(params.path)) { return null; } if (path.substr(-1) !== '/') { path += '/'; } - 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: type, - size: item['Content-Length'] || null - })); - }); - - return items; - }); + return this.get('storage').fetchListing(path); }, setupController(controller, model) { diff --git a/app/services/storage.js b/app/services/storage.js index a7248c5..09fd518 100644 --- a/app/services/storage.js +++ b/app/services/storage.js @@ -1,6 +1,8 @@ +import EmberObject from '@ember/object'; import Service from '@ember/service'; import RemoteStorage from 'npm:remotestoragejs'; import Widget from 'npm:remotestorage-widget'; +import simpleContentType from 'inspektor/utils/simple-content-type'; export default Service.extend({ @@ -81,6 +83,26 @@ export default Service.extend({ this.set('categories', categories); }); + }, + + fetchListing(path) { + let items = []; + + return this.get('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: type, + size: item['Content-Length'] || null + })); + }); + + return items; + }); } });