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

update components

This commit is contained in:
Luke Pulverenti 2016-04-03 15:16:39 -04:00
parent 746135c2f7
commit 95e11bfdf0
4 changed files with 63 additions and 9 deletions

View file

@ -54,12 +54,66 @@ define(['cryptojs-md5'], function () {
imageCacheDirectoryEntry = dirEntry;
// TODO: find a better time to schedule this
setTimeout(cleanCache, 60000);
});
});
});
function toArray(list) {
return Array.prototype.slice.call(list || [], 0);
}
function cleanCache() {
var dirReader = imageCacheDirectoryEntry.createReader();
var entries = [];
var onReadFail = function () {
console.log('dirReader.readEntries failed');
};
// Keep calling readEntries() until no more results are returned.
var readEntries = function () {
dirReader.readEntries(function (results) {
if (!results.length) {
entries.forEach(cleanFile);
} else {
entries = entries.concat(toArray(results));
readEntries();
}
}, onReadFail);
};
// Start reading the directory.
readEntries();
}
function cleanFile(fileEntry) {
if (!fileEntry.isFile) {
return;
}
fileEntry.file(function (file) {
var elapsed = new Date().getTime() - file.lastModifiedDate.getTime();
// 60 days
var maxElapsed = 5184000000;
if (elapsed >= maxElapsed) {
var fullPath = fileEntry.fullPath;
console.log('deleting file: ' + fullPath);
fileEntry.remove(function () {
console.log('File deleted: ' + fullPath);
}, function () {
console.log('Failed to delete file: ' + fullPath);
});
}
});
}
function getCacheKey(url) {
// Try to strip off the domain to share the cache between local and remote connections