Stackedit/public/res/fileSystem.js

24 lines
655 B
JavaScript
Raw Permalink Normal View History

2013-06-16 10:47:35 +00:00
define([
2013-06-19 20:33:46 +00:00
"underscore",
2013-06-16 10:47:35 +00:00
"utils",
"classes/FileDescriptor",
"storage",
], function(_, utils, FileDescriptor, storage) {
2013-06-16 10:47:35 +00:00
var fileSystem = {};
2013-06-19 20:33:46 +00:00
// Retrieve file descriptors from localStorage
utils.retrieveIndexArray("file.list").forEach(function(fileIndex) {
2013-06-19 20:33:46 +00:00
fileSystem[fileIndex] = new FileDescriptor(fileIndex);
2013-06-16 10:47:35 +00:00
});
// Clean fields from deleted files in local storage
Object.keys(storage).forEach(function(key) {
var match = key.match(/(file\.\S+?)\.\S+/);
if(match && !fileSystem.hasOwnProperty(match[1])) {
storage.removeItem(key);
}
});
2013-06-16 10:47:35 +00:00
return fileSystem;
});