ox.setInterval, move permission check into function

This commit is contained in:
j 2010-08-17 12:03:20 +02:00
parent 7abbd82c07
commit 3524e6abac
2 changed files with 27 additions and 14 deletions

View file

@ -176,21 +176,15 @@ OxFF.prototype = {
}
return this._access;
},
api: function(action, data, callback) {
var _this = this;
if (typeof(data) == 'function') {
callback = data;
data = {};
}
if(!this._access) {
this.debug('permission deinied', action, data);
return false;
}
if(!this._user) {
this.debug('login first', action, data);
return false;
}
if(!this.canAccess())
return false;
data["site"] = this._site;
data["user"] = this._user;
@ -269,11 +263,15 @@ OxFF.prototype = {
},
uploadVideo: function(oshash, url, profile, callback, progress) {
var _this = this;
if(!this.canAccess())
return false;
if(progress)
progress = progress.callback;
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(function() {
return _this.api('extract', {'oshash': oshash, 'media': profile}, function(result) {
var timer = ox.setInterval(function() {
_this.api('extract', {'oshash': oshash, 'media': profile}, function(result) {
var data = JSON.parse(result);
if (data.status == 'extracting') {
if(progress) {
@ -289,8 +287,7 @@ OxFF.prototype = {
}
}
});
} ,2000, Ci.nsITimer.TYPE_REPEATING_SLACK);
}, 2000);
return true;
},
files: function(volume, callback) {
@ -356,6 +353,17 @@ OxFF.prototype = {
this._access = false;
oxff.access(this._site, this._access);
},
canAccess: function() {
if(!this._access) {
this.debug('permission deinied', action, data);
return false;
}
if(!this._user) {
this.debug('login first', action, data);
return false;
}
return true;
},
startDaemon: function() {
var _this = this;
//if daemon is already running to not start it again

View file

@ -11,6 +11,11 @@ let ox = {
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_ONE_SHOT);
},
setInterval: function(callback, timeout) {
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
timer.initWithCallback(callback, timeout, Ci.nsITimer.TYPE_REPEATING_SLACK);
return timer;
},
glob: function (path) {
/*
return array of all files(in all subdirectories) for given directory