1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update access denied exceptions

This commit is contained in:
Luke Pulverenti 2015-09-25 22:31:13 -04:00
parent 294281602e
commit ad38cf4783
17 changed files with 154 additions and 138 deletions

View file

@ -350,7 +350,7 @@
var deferred = DeferredBuilder.Deferred();
Logger.log('Deleting ' + path);
resolveFile(path, function (fileEntry) {
resolveFile(path, null, function (fileEntry) {
fileEntry.remove(function () {
Logger.log('Deleted ' + path);
@ -370,18 +370,27 @@
return deferred.promise();
}
function resolveFile(path, success, fail) {
function resolveFile(path, options, success, fail) {
getFileSystem().done(function (fileSystem) {
fileSystem.root.getFile(path, { create: false }, success, fail);
fileSystem.root.getFile(path, options || { create: false }, success, fail);
});
}
function createLocalItem(libraryItem, serverInfo, originalFileName) {
var path = getDirectoryPath(libraryItem, serverInfo);
path.push(getLocalFileName(libraryItem, originalFileName));
var enableFriendlyPath = false;
var path = getDirectoryPath(libraryItem, serverInfo, enableFriendlyPath);
if (enableFriendlyPath) {
path.push(getLocalFileName(libraryItem, originalFileName));
} else {
var nameParts = originalFileName.split('.');
var ext = nameParts.length > 1 ? ('.' + nameParts[nameParts.length - 1]) : '';
path.push('media' + ext);
}
var item = {};
@ -407,7 +416,11 @@
return deferred.promise();
}
function getDirectoryPath(item, server) {
function getDirectoryPath(item, server, enableFriendlyPath) {
if (!enableFriendlyPath) {
return ['sync', item.Id];
}
var parts = [];
parts.push("sync");
@ -462,58 +475,6 @@
function downloadFile(url, localPath, enableBackground) {
return downloadWithFileTransfer(url, localPath, enableBackground);
if (!enableBackground) {
return downloadWithFileTransfer(url, localPath);
}
var deferred = DeferredBuilder.Deferred();
if (localStorage.getItem('sync-' + url) == '1') {
Logger.log('file was downloaded previously');
deferred.resolveWith(null, [localPath]);
return deferred.promise();
}
Logger.log('downloading: ' + url + ' to ' + localPath);
getFileSystem().done(function (fileSystem) {
createDirectory(getParentDirectoryPath(localPath)).done(function () {
fileSystem.root.getFile(localPath, { create: true }, function (targetFile) {
var downloader = new BackgroundTransfer.BackgroundDownloader();
// Create a new download operation.
var download = downloader.createDownload(url, targetFile);
var isQueued = true;
// Start the download and persist the promise to be able to cancel the download.
var downloadPromise = download.startAsync().then(function () {
// on success
Logger.log('Downloaded local url: ' + localPath);
localStorage.setItem('sync-' + url, '1');
isQueued = false;
}, function () {
// on error
Logger.log('download failed: ' + url + ' to ' + localPath);
deferred.reject();
}, function (value) {
// on progress
//Logger.log('download progress: ' + value);
});
});
}).fail(getOnFail(deferred));;
}).fail(getOnFail(deferred));
return deferred.promise();
}
var activeDownloads = [];
@ -544,57 +505,58 @@
Logger.log('downloading: ' + url + ' to ' + localPath);
getFileSystem().done(function (fileSystem) {
createDirectory(getParentDirectoryPath(localPath)).done(function () {
createDirectory(getParentDirectoryPath(localPath)).done(function () {
resolveFile(localPath, { create: true }, function (targetFile) {
fileSystem.root.getFile(localPath, { create: true }, function (targetFile) {
var isQueued = enableBackground;
var isError = false;
var isQueued = enableBackground;
var isError = false;
var ft = new FileTransfer();
activeDownloads.push(downloadKey);
ft.download(url, targetFile.toURL(), function (entry) {
var ft = new FileTransfer();
ft.download(url, targetFile.toURL(), function (entry) {
removeDownload(downloadKey);
if (enableBackground) {
Logger.log('Downloaded local url: ' + localPath);
localStorage.setItem('sync-' + url, '1');
isQueued = false;
} else {
deferred.resolveWith(null, [localPath]);
}
}, function () {
removeDownload(downloadKey);
Logger.log('Error downloading url: ' + url);
if (enableBackground) {
isError = true;
} else {
deferred.reject();
}
});
activeDownloads.push(downloadKey);
removeDownload(downloadKey);
if (enableBackground) {
// Give it a short period of time to see if it has already been completed before. Either way, move on and resolve it.
setTimeout(function () {
Logger.log('Downloaded local url: ' + localPath);
localStorage.setItem('sync-' + url, '1');
isQueued = false;
} else {
deferred.resolveWith(null, [localPath]);
}
if (isError) {
deferred.reject();
} else {
// true indicates that it's queued
deferred.resolveWith(null, [localPath, isQueued]);
}
}, 1500);
}, function () {
removeDownload(downloadKey);
Logger.log('Error downloading url: ' + url);
if (enableBackground) {
isError = true;
} else {
deferred.reject();
}
});
}).fail(getOnFail(deferred));
if (enableBackground) {
// Give it a short period of time to see if it has already been completed before. Either way, move on and resolve it.
setTimeout(function () {
if (isError) {
deferred.reject();
} else {
// true indicates that it's queued
deferred.resolveWith(null, [localPath, isQueued]);
}
}, 2000);
}
}, function () {
Logger.log('getFile failed for ' + localPath);
deferred.reject();
});
}).fail(getOnFail(deferred));
@ -761,7 +723,7 @@
return deferred.promise();
}
resolveFile(path, function (fileEntry) {
resolveFile(path, null, function (fileEntry) {
Logger.log('fileExists: true - path: ' + path);
deferred.resolveWith(null, [true]);
@ -806,7 +768,7 @@
return deferred.promise();
}
resolveFile(path, function (fileEntry) {
resolveFile(path, null, function (fileEntry) {
Logger.log('translateFilePath fileExists: true - path: ' + path);
Logger.log('translateFilePath resolving with: ' + fileEntry.toURL());
deferred.resolveWith(null, [fileEntry.toURL()]);