Skip to content

Commit

Permalink
oopsie daisies
Browse files Browse the repository at this point in the history
  • Loading branch information
novafurry committed May 9, 2024
1 parent 4634dd4 commit 5330993
Showing 1 changed file with 9 additions and 53 deletions.
62 changes: 9 additions & 53 deletions libraries/foxyfs.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,11 @@
// foxyfs.js
var currentStore = localStorage.getItem('fs');
function jsonPathToValue(jsonData, path) {
if (!(jsonData instanceof Object) || typeof path === 'undefined') {
throw 'InvalidArgumentException';
}
path = path.replace(/\[(\w+)\]/g, '.$1'); // convert indexes to properties
path = path.replace(/^\./, ''); // strip a leading dot
var pathArray = path.split('.');
for (var i = 0, n = pathArray.length; i < n; ++i) {
var key = pathArray[i];
if (key in jsonData) {
if (jsonData[key] !== null) {
jsonData = jsonData[key];
} else {
return null;
}
} else {
return key;
}
}
return jsonData;
}
if (currentStore == null) {
localStorage.setItem(
'fs',
'{"d_home":{"d_Documents":{"f_README․html":"data:text/html;base64,PGgxIGlkPSJ3ZWxjb21lLXRvLW9ueXhvcyI+V2VsY29tZSB0byBPbnl4T1M8L2gxPg0KPHA+VGhpcyBpcyBhIHRlc3Qgb2YgdGhlIEZTPC9wPg0KDQo="},"d_Downloads":{},"d_Pics":{}}}'
);
}
export default function initFFS(){
window.foxyfs = {
save: function(path, content) {
currentStore = JSON.parse(localStorage.getItem('fs'));
path2 = "['" + path.replaceAll('.', "']['") + "']";
eval('currentStore' + path2 + " = '" + encodeURIComponent(content) + "'");
localStorage.fs = JSON.stringify(currentStore);
currentStore = localStorage.fs;
},
load: function(path) {
return jsonPathToValue(JSON.parse(localStorage.fs), path);
},
rm: function(path) {
var fs = JSON.parse(localStorage.fs);
if (path.split('')[0] == '.') {
eval('delete fs.' + path.slice(1) + '');
} else {
eval('delete fs.' + path + '');
}
console.log(fs);
localStorage.fs2 = fs;
}

const opfsRoot = await navigator.storage.getDirectory();
window.foxyfs = {
init: async function () {
var directoryHandle = await opfsRoot.getDirectoryHandle('sys', { create: true });
directoryHandle = await opfsRoot.getDirectoryHandle('user', { create: true });
},
ls: async function (dir) {
return await opfsRoot.getDirectoryHandle(dir);
}
}
initFFS()
foxyfs.init()

0 comments on commit 5330993

Please sign in to comment.