vanilla deepsearch
This commit is contained in:
parent
a144909fbf
commit
ac412b798c
15 changed files with 725 additions and 78 deletions
|
|
@ -2,13 +2,13 @@ import JSONC from "jsonc-parser"
|
|||
import fsp from "fs/promises"
|
||||
import fs from "fs"
|
||||
|
||||
if (!fs.existsSync("prefetch")) fs.mkdirSync("prefetch")
|
||||
if (!fs.existsSync("cache")) fs.mkdirSync("cache")
|
||||
|
||||
export const Github = {
|
||||
readFile: async (user: string, repo: string, branches: string, path: string) => {
|
||||
try {
|
||||
return fetch(`https://raw.githubusercontent.com/${user}/${repo}/refs/heads/${branches}/${path}`).then(res =>
|
||||
res.text()
|
||||
res.text(),
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
|
|
@ -21,7 +21,7 @@ export const PFFS = {
|
|||
// Sync
|
||||
readFile: (file: string) => {
|
||||
try {
|
||||
return fs.readFileSync(`prefetch/${file}`, "utf-8")
|
||||
return fs.readFileSync(`cache/${file}`, "utf-8")
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
|
|
@ -31,11 +31,11 @@ export const PFFS = {
|
|||
writeFile: (file: string, data: string) => {
|
||||
try {
|
||||
file.split("/").reduce((a, b) => {
|
||||
if (!fs.existsSync(a)) fs.mkdirSync(a)
|
||||
return `prefetch/${a}/${b}`
|
||||
if (!fs.existsSync("cache/" + a)) fs.mkdirSync("cache/" + a)
|
||||
return `${a}/${b}`
|
||||
})
|
||||
|
||||
return fsp.writeFile(`prefetch/${file}`, data)
|
||||
return fsp.writeFile(`cache/${file}`, data)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
|
|
|
|||
Reference in a new issue