You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

70 lines
1.4 KiB
JavaScript

class Model {
constructor(http) {
4 years ago
// Initialize isomorphic-git with a file system
window.fs = new LightningFS("fs");
// I prefer using the Promisified version honestly
window.pfs = window.fs.promises;
window.dir = "/";
window.http = http;
4 years ago
}
async dirList(dir = "/") {
let list = await pfs.readdir(dir);
4 years ago
for (let u = 0; u < list.length; u++) {
let re = /^\..*$/;
if (re.test(list[u])) {
4 years ago
list.splice(u, 1);
u--;
}
}
let dirtree = [dir];
for (let i = 0; i < list.length; i++) {
dirtree[i + 1] = list[i];
4 years ago
let itemStat = await pfs.stat(dirtree[0] + dirtree[i + 1]);
if (itemStat.isDirectory()) {
4 years ago
dirtree[i + 1] = await this.dirList(dirtree[0] + dirtree[i + 1] + "/");
}
}
return dirtree;
}
async dirTree() {
let baseDir = localStorage.getItem("baseDir");
var tree = await this.dirList(baseDir);
return tree;
}
4 years ago
4 years ago
wipeFS() {
4 years ago
delete window.fs;
window.fs = new LightningFS("fs", { wipe: true });
}
async cloneRep() {
this.wipeFS();
await git.clone({
fs,
http,
dir,
url: localStorage.getItem("repo"),
corsProxy: "https://cors.isomorphic-git.org",
});
}
setRepo(repoURL) {
localStorage.setItem("repo", repoURL);
}
setBaseDir(baseDir) {
localStorage.setItem("baseDir", baseDir);
}
}