120
APPENDIX A. HTML5 JAVASCRIPT SOURCE CODE
77
411
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
412
window.requestFileSystem(window.PERSISTENT, GRANTED_BYTES, function n (fs) {
413
fs.root.getFile(row.fileName, { create: false }, function (fileEntry) {
414
fileEntry.remove(function () {
415
console.log(row.fileName, ’ File e removed.’);
416
}, errorHandlerF);
417
}, errorHandlerF);
418
}, errorHandlerF);
419
}, false);
420
p.addEventListener("click", function () {
421
console.log("Uploading torrent t to o server");
422
$.post("http://html5p2p-1.cs.hut.fi/tracker/PublishServlet", "torrent=" +
423
JSON.stringify(row), function (data) {
424
console.log("Server returned", JSON.parse(data));
425
populateTorrents();
426
//li.appendChild(u);
427
//$(’a’, ’#db’).css(’cursor’, ’pointer’);
428
});
429
}, false);
430
431
v.textContent = " [View]";
432
d.textContent = " [Del]";
433
p.textContent = " [Publish]";
434
//
u.textContent = " [Upload]";
435
li.appendChild(v);
436
li.appendChild(p);
437
li.appendChild(d);
438
li.appendChild(t);
439
440
441
$(’#db’).append(li)
442
$(’a’, ’#db’).css(’cursor’, , ’pointer’);
443
}
444
445
function populateTorrents() {
446
$(’#torrents’).html("");
447
$.get("http://html5p2p-1.cs.hut.fi/tracker/GetTorrentsServlet", "", , function (data) {
448
$(’#torrents’).html(data);
449
});
450
}
451
452
function renameFileAndAddToDb() {
453
var fileName = movie_object.fileName;
454
var fileMimeType = movie_object.fileMimeType;
455
var fileDuration = movie_object.fileDuration;
456
movie_object.fileName = "";
457
movie_object.fileURL = "";
458
459
460
var extension = movie_object.fileMimeType.substring(movie_object.fileMimeType.lastIndexOf(’/’) + 1,
461
movie_object.fileMimeType.length);
462
movie_object.fileMimeType = "";
463
movie_object.fileDuration = "";
464
var unique_movie_object_string = JSON.stringify(movie_object);
465
movie_object.fileID = MD5(unique_movie_object_string, unique_movie_object_string.length);
466
movie_object.fileName = movie_object.fileID + "." + extension;
467
movie_object.fileMimeType = fileMimeType;
468
movie_object.fileDuration = fileDuration;
469
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
470
window.requestFileSystem(window.PERSISTENT, GRANTED_BYTES, function n (fs) {
471
rename(fs.root, fileName, movie_object.fileName);
472
function rename(cwd, src, newName) {