-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
9 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |