Move dir listing fetch to service
This commit is contained in:
parent
d834f5c8e9
commit
2bd918655d
@ -1,8 +1,6 @@
|
|||||||
import Route from '@ember/routing/route';
|
import Route from '@ember/routing/route';
|
||||||
import EmberObject from '@ember/object';
|
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { isEmpty } from '@ember/utils';
|
import { isEmpty } from '@ember/utils';
|
||||||
import simpleContentType from 'inspektor/utils/simple-content-type';
|
|
||||||
|
|
||||||
export default Route.extend({
|
export default Route.extend({
|
||||||
|
|
||||||
@ -16,27 +14,12 @@ export default Route.extend({
|
|||||||
|
|
||||||
model(params) {
|
model(params) {
|
||||||
let path = params.path;
|
let path = params.path;
|
||||||
let items = [];
|
|
||||||
|
|
||||||
if (isEmpty(params.path)) { return null; }
|
if (isEmpty(params.path)) { return null; }
|
||||||
|
|
||||||
if (path.substr(-1) !== '/') { path += '/'; }
|
if (path.substr(-1) !== '/') { path += '/'; }
|
||||||
|
|
||||||
return this.get('storage.client').getListing(path).then(listing => {
|
return this.get('storage').fetchListing(path);
|
||||||
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;
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setupController(controller, model) {
|
setupController(controller, model) {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
|
import EmberObject from '@ember/object';
|
||||||
import Service from '@ember/service';
|
import Service from '@ember/service';
|
||||||
import RemoteStorage from 'npm:remotestoragejs';
|
import RemoteStorage from 'npm:remotestoragejs';
|
||||||
import Widget from 'npm:remotestorage-widget';
|
import Widget from 'npm:remotestorage-widget';
|
||||||
|
import simpleContentType from 'inspektor/utils/simple-content-type';
|
||||||
|
|
||||||
export default Service.extend({
|
export default Service.extend({
|
||||||
|
|
||||||
@ -81,6 +83,26 @@ export default Service.extend({
|
|||||||
|
|
||||||
this.set('categories', categories);
|
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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user