300 lines
10 KiB
HTML
300 lines
10 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<script src="http://oxjs.org/js/jquery-1.4.2.min.js"></script>
|
|
<script type="text/javascript" src="/static/oxjs/build/js/ox.js"></script>
|
|
<script>
|
|
function absolute_url(url) {
|
|
var base = document.location.href;
|
|
if (url.substring(0, 1) == '/') {
|
|
url = document.location.href.substring(0, document.location.href.length-document.location.pathname.length) + url;
|
|
}
|
|
else {
|
|
if(base.substring(base.length-1) == '/')
|
|
url = base + url;
|
|
else
|
|
url = base + '/' + url;
|
|
}
|
|
return url;
|
|
}
|
|
|
|
pandora = {};
|
|
pandora.request_url = '/api/';
|
|
|
|
pandora.request = function(fn, data, callback) {
|
|
data = JSON.stringify(data);
|
|
return jQuery.ajax({
|
|
type: "POST",
|
|
url: this.request_url,
|
|
dataType: "json",
|
|
data: {"action": fn, data: data},
|
|
success: function(response) {
|
|
if (typeof callback != "undefined")
|
|
callback(response);
|
|
//console.log(response);
|
|
},
|
|
error: function (xhr, ajaxOptions, thrownError){
|
|
var response = {};
|
|
response.status = {code:xhr.status, text:xhr.statusText};
|
|
|
|
//FIXME: this should only happen if debugging/admin
|
|
error = jQuery('<iframe>').css({width:'99%', height: '99%'});
|
|
var debug = new Ox.Dialog({
|
|
title: "API Request failed: " + fn,
|
|
buttons: [
|
|
new Ox.Button({value:'Close'})
|
|
.click(function() {
|
|
debug.close();
|
|
})
|
|
],
|
|
width: 1000,
|
|
height: 310
|
|
}).append(error).open();
|
|
|
|
//write error response from server into iframe
|
|
//this might be required instead
|
|
/*
|
|
var ifrm = error[0];
|
|
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
|
|
var ifrm = error[0].contentWindow;
|
|
ifrm.document.open();
|
|
ifrm.document.write(xhr.responseText);
|
|
ifrm.document.close();
|
|
*/
|
|
|
|
var doc = error[0].contentDocument || error[0].contentWindow.document;
|
|
doc.open();
|
|
doc.write(xhr.responseText);
|
|
doc.close();
|
|
|
|
if (typeof callback != "undefined")
|
|
callback(response);
|
|
console.log(response);
|
|
|
|
}
|
|
});
|
|
};
|
|
</script>
|
|
<script>
|
|
|
|
var _ids = new Array();
|
|
|
|
var ox = new OxFF();
|
|
ox.access(true);
|
|
//ox.get('b2c8f0aa3a447d09', 'stills', function(result) { console.log(result);});
|
|
//ox.files(function(result) { console.log(result);});
|
|
|
|
function safe_id(id) {
|
|
var _id = _ids.indexOf(id);
|
|
if(_id < 0) {
|
|
_ids.push(id);
|
|
_id = _ids.indexOf(id);
|
|
}
|
|
return _id;
|
|
}
|
|
|
|
function for_each_sorted(elements, callback) {
|
|
function pad(str) {
|
|
var len = 10;
|
|
while (str.length < len) {
|
|
str = '0' + str;
|
|
}
|
|
return str;
|
|
};
|
|
var keys = new Array();
|
|
$.each(elements, function(k) {
|
|
keys.push(k);
|
|
});
|
|
keys.sort(function(a,b) {
|
|
a = a.replace(/\d+/, pad);
|
|
b = b.replace(/\d+/, pad);
|
|
return a > b;
|
|
});
|
|
$.each(keys, function(i, k) {
|
|
var v = elements[k];
|
|
callback(k, v);
|
|
});
|
|
}
|
|
|
|
function uploadFile(oshash) {
|
|
var url = absolute_url('/api/');
|
|
ox.upload(JSON.stringify({
|
|
url: url,
|
|
data: {action: 'upload', oshash: oshash},
|
|
oshash: oshash,
|
|
action: 'file'
|
|
}),
|
|
function(result) {
|
|
$('#' + oshash).css('background', '#fff');
|
|
console.log(result);
|
|
}
|
|
);
|
|
}
|
|
|
|
function extract(oshash) {
|
|
/*
|
|
ox.extract(oshash, 'stills', function(result) {
|
|
console.log(result);
|
|
});
|
|
*/
|
|
var url = absolute_url('/api/');
|
|
ox.upload(JSON.stringify({
|
|
url: url,
|
|
data: {action: 'upload', oshash: oshash},
|
|
oshash: oshash,
|
|
action: 'frames'
|
|
}),
|
|
function(result) {
|
|
//FIXME: check result before posting video
|
|
profile = '96p.webm';
|
|
var url = absolute_url('/api/upload/') + '?profile=' + profile + '&oshash=' + oshash;
|
|
|
|
$('<div>').attr('id', 'progress_'+oshash)
|
|
.appendTo('#' + oshash);
|
|
|
|
ox.upload(JSON.stringify({
|
|
oshash: oshash,
|
|
action: 'video',
|
|
profile: profile,
|
|
url: url
|
|
}),
|
|
function(result) {
|
|
console.log(result);
|
|
$('#' + oshash).css('background', '#fff');
|
|
$('#' + oshash).parent().css('background', '#fff');
|
|
$('#progress_'+oshash).remove();
|
|
}, function(result) {
|
|
try {
|
|
var data = JSON.parse(result);
|
|
$('#progress_'+oshash).html(data.status +': '+ data.progress);
|
|
} catch(e) {
|
|
console.log('progress failed', e);
|
|
}
|
|
});
|
|
}
|
|
);
|
|
}
|
|
|
|
function update() {
|
|
var username = $('#username').val();
|
|
var password = $('#password').val();
|
|
ox.login(username);
|
|
pandora.request('login', {'username': username, 'password': password});
|
|
var updating = true;
|
|
ox.update(function(result) {
|
|
updating = false;
|
|
ox.volumes(function(result) {
|
|
var volumes = JSON.parse(result);
|
|
for(volume in volumes) {
|
|
ox.files(volume, function(result) {
|
|
var data = JSON.parse(result);
|
|
pandora.request('update', {
|
|
'volume': volume, 'files': data.files
|
|
}, function(result) {
|
|
var post = {'info': {}};
|
|
function highlight_resulsts(result) {
|
|
$.each(result.data.data, function(i, oshash) {
|
|
if($('#' + oshash).css('background') != 'red') {
|
|
$('#' + oshash).unbind('click').click(function() {
|
|
$(this).unbind('click');
|
|
extract(this.id);
|
|
return true;
|
|
});
|
|
}
|
|
$('#' + oshash).css('background', 'red');
|
|
$('#' + oshash).parent().css('background', 'orange');
|
|
});
|
|
$.each(result.data.file, function(i, oshash) {
|
|
$('#' + oshash).css('background', 'blue');
|
|
$('#' + oshash).unbind('click').click(function() {
|
|
$(this).unbind('click');
|
|
uploadFile(this.id);
|
|
return true;
|
|
});
|
|
|
|
});
|
|
}
|
|
if (result.data.info.length>0) {
|
|
$.each(data.info, function(oshash, info) {
|
|
if($.inArray(oshash, result.data.info) >= 0) {
|
|
post.info[oshash] = info;
|
|
}
|
|
});
|
|
pandora.request('update', post, function(result) {
|
|
highlight_resulsts(result);
|
|
});
|
|
} else {
|
|
highlight_resulsts(result);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
});
|
|
var getFiles = function() {
|
|
ox.volumes(function(result) {
|
|
var volumes = JSON.parse(result);
|
|
for(volume in volumes) {
|
|
(function(volume) {
|
|
var volumeId = "volume_"+safe_id(volume);
|
|
var $volume = $('#'+volumeId);
|
|
if($volume.length==0) {
|
|
$volume = $('<div>').attr('id', volumeId).html('<h2>'+volume+'</h2>');
|
|
$volume.find('h2').click(function() { $(this).parent().find('div').toggle();});
|
|
}
|
|
$('#files').append($volume);
|
|
ox.files(volume, function(result) {
|
|
var data = JSON.parse(result);
|
|
var _files = [];
|
|
$.each(data.files, function(i, file) {
|
|
var folder = file.path.split('/');
|
|
folder.pop();
|
|
if(folder.length==0) {
|
|
folder.push("rootfolder");
|
|
}
|
|
//FIXME: this is also done on the backend but might require more sub options
|
|
if (folder[folder.length-1] == "Extras" || folder[folder.length-1] == "Versions")
|
|
folder.pop();
|
|
folder = folder.join('/');
|
|
|
|
var folderId = 'folder_'+safe_id(folder);
|
|
var $folder = $('#'+folderId);
|
|
if($folder.length==0) {
|
|
$folder = $('<div>').attr('id', folderId).html('<h3>'+folder+'</h3>');
|
|
$folder.find('h3').click(function() { $(this).parent().find('.file').toggle();});
|
|
$volume.append($folder);
|
|
}
|
|
var fileId = file.oshash;
|
|
var $file = $('#'+fileId);
|
|
if($file.length==0) {
|
|
$file = $('<div>').attr('id', fileId).addClass('file').html(file.path).hide();
|
|
$folder.append($file);
|
|
}
|
|
});
|
|
});
|
|
}(volume));
|
|
}
|
|
if(updating) {
|
|
setTimeout(getFiles, 2000);
|
|
}
|
|
});
|
|
}
|
|
getFiles();
|
|
}
|
|
|
|
function setLocation(name) {
|
|
console.log(ox.setLocation(name))
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
Username: <input type="text" id="username" value="">
|
|
Password: <input type="password" id="password" value="">
|
|
<br>
|
|
<input type="button" onClick="setLocation('test')" value="Set Location">
|
|
<input type="button" onClick="update()" value="Update">
|
|
<div id="files">
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|