Open BakaFT opened 9 months ago
We have added a sync-blocking PluginFS
implementation in #75
API Docs: https://beta.pengu.lol/runtime-api/plugin-fs
There's a way to isolate the PluginFS for scoped plugin folder.
First remove the global PluginFS
and turn it into a class.
class PluginFS {
constructor(name) { }
read(path) { /*do path check*/ }
// ...
}
Pass an instance for each plugin init call.
function loadPlugin(name) {
// ...
ctx.fs = new PluginFS(name)
// ...
}
export function init(ctx) {
ctx.read('some/path/to/file')
}
[!IMPORTANT] With top-level JS files (aka single file plugins), they should not access
fs
and skip this prop.
Community devs often need to access the file system to complete certain operations, such as opening a folder for users to add or delete files, outputting logs to a file, and so on.
So a PluginFS API is needed, and it should be plugin scoped meaning that a plugin only have permission on it's own folder. In this case top-level js will not have any permission because it don't have its own folder.
Actually I've done some job on that using
std::filesystem
from C++17, so I think if is ok we can move to C++17 to gain more convenience and improved cross-platform compatibility.