fix cached urls after download is finished

This commit is contained in:
j 2015-04-11 12:31:36 +02:00
parent a8a4191f1a
commit d8e23fe6d1

View file

@ -35,7 +35,7 @@ pandora.fs = (function() {
function downloadPart(part) { function downloadPart(part) {
if (that.getVideoURL(id, pandora.user.ui.videoResolution, part + 1)) { if (that.getVideoURL(id, pandora.user.ui.videoResolution, part + 1)) {
done(); done();
else { } else {
that.downloadVideoURL(id, pandora.user.ui.videoResolution, part + 1, false, function(result) { that.downloadVideoURL(id, pandora.user.ui.videoResolution, part + 1, false, function(result) {
result.progress = 1/parts * (part + result.progress); result.progress = 1/parts * (part + result.progress);
that.downloads[id].progress = result.progress; that.downloads[id].progress = result.progress;
@ -75,7 +75,9 @@ pandora.fs = (function() {
function renameFile(old, name, callback) { function renameFile(old, name, callback) {
that.fs.root.getFile(old, {}, function(fileEntry) { that.fs.root.getFile(old, {}, function(fileEntry) {
fileEntry.moveTo(that.fs.root, name); fileEntry.moveTo(that.fs.root, name);
callback(); setTimeout(function() {
that.fs.root.getFile(name, {}, callback, function() { callback() });
});
}, function() { }, function() {
Ox.Log('FS', 'failed to move', old, name); Ox.Log('FS', 'failed to move', old, name);
callback(); callback();
@ -150,8 +152,7 @@ pandora.fs = (function() {
fileEntry.createWriter(function(fileWriter) { fileEntry.createWriter(function(fileWriter) {
append && fileWriter.seek(fileWriter.length); append && fileWriter.seek(fileWriter.length);
fileWriter.onwriteend = function(e) { fileWriter.onwriteend = function(e) {
that.local[name] = fileEntry.toURL(); callback({progress: 1});
callback({progress: 1, url: that.local[name]});
}; };
fileWriter.onerror = function(event) { fileWriter.onerror = function(event) {
Ox.Log('FS', 'Write failed: ' + event.toString()); Ox.Log('FS', 'Write failed: ' + event.toString());
@ -234,8 +235,15 @@ pandora.fs = (function() {
if (offset + blobSize < total) { if (offset + blobSize < total) {
partialDownload(offset + blobSize + 1); partialDownload(offset + blobSize + 1);
} else { } else {
renameFile(partialName, name, function() { renameFile(partialName, name, function(fileEntry) {
callback(response); if (fileEntry) {
that.local[name] = fileEntry.toURL();
response.url = that.local[name];
callback(response);
} else {
Ox.print('rename failed');
callback({progress: -1, error: 'rename failed'});
}
}); });
} }
}, true); }, true);