Move dir listing fetch to service

This commit is contained in:
Basti 2017-11-12 18:03:07 +01:00
parent d834f5c8e9
commit 2bd918655d
2 changed files with 23 additions and 18 deletions

View File

@ -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) {

View File

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