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