2015-01-13 10:18:13 +00:00
|
|
|
angular.module('myApp.services', []).
|
2015-01-13 21:50:17 +00:00
|
|
|
factory('Desirae', ['$q', '$http', function ($q, $http) {
|
2015-01-15 06:41:52 +00:00
|
|
|
var Desi = window.Desirae || require('./deardesi').Desirae
|
2015-01-13 21:50:17 +00:00
|
|
|
, desi = {/*TODO api_base: '/api'*/}
|
2015-01-13 10:18:13 +00:00
|
|
|
;
|
|
|
|
|
2015-01-13 21:50:17 +00:00
|
|
|
function getBlogdir () {
|
|
|
|
return $http.get('/api/fs/rootdir').then(function (resp) {
|
|
|
|
desi.blogdir = resp.data;
|
|
|
|
return resp.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getBlogdir();
|
|
|
|
|
2015-01-13 10:18:13 +00:00
|
|
|
return {
|
|
|
|
reset: function () {
|
|
|
|
desi = {};
|
2015-01-13 21:50:17 +00:00
|
|
|
return getBlogdir();
|
2015-01-13 10:18:13 +00:00
|
|
|
}
|
|
|
|
, toDesiDate: Desi.toLocaleDate
|
|
|
|
, meta: function () {
|
|
|
|
var d = $q.defer()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (desi.meta) {
|
|
|
|
d.resolve(desi);
|
|
|
|
return d.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
Desi.init(desi).then(function () {
|
|
|
|
d.resolve(desi);
|
|
|
|
});
|
|
|
|
|
|
|
|
return d.promise;
|
|
|
|
}
|
|
|
|
, build: function (env) {
|
|
|
|
var d = $q.defer()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (desi.built) {
|
|
|
|
d.resolve(desi);
|
|
|
|
return d.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
Desi.buildAll(desi, env).then(function () {
|
|
|
|
d.resolve(desi);
|
|
|
|
});
|
|
|
|
|
|
|
|
return d.promise;
|
|
|
|
}
|
|
|
|
, write: function (env) {
|
|
|
|
var d = $q.defer()
|
|
|
|
;
|
|
|
|
|
|
|
|
if (desi.written) {
|
|
|
|
d.resolve(desi);
|
|
|
|
return d.promise;
|
|
|
|
}
|
|
|
|
|
|
|
|
Desi.write(desi, env).then(function () {
|
|
|
|
d.resolve(desi);
|
|
|
|
});
|
|
|
|
|
|
|
|
return d.promise;
|
|
|
|
}
|
|
|
|
, putFiles: function (files) {
|
2015-01-15 06:41:52 +00:00
|
|
|
return $q.when(Desi.fsapi.putFiles(files));
|
2015-01-13 10:18:13 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}]
|
|
|
|
);
|