Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adapt universal picgo config path
- Loading branch information
Showing
15 changed files
with
268 additions
and
27 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
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
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { IConfig, IPicGo } from "../types" | ||
import { JSONStore } from "universal-picgo-store/src" | ||
import { IJSON } from "universal-picgo-store" | ||
|
||
class DB { | ||
private readonly ctx: IPicGo | ||
private readonly db: JSONStore | ||
constructor(ctx: IPicGo) { | ||
this.ctx = ctx | ||
this.db = new JSONStore(this.ctx.configPath) | ||
|
||
if (!this.db.has("picBed")) { | ||
try { | ||
this.db.set("picBed", { | ||
uploader: "smms", | ||
current: "smms", | ||
}) | ||
} catch (e: any) { | ||
this.ctx.log.error(e) | ||
throw e | ||
} | ||
} | ||
if (!this.db.has("picgoPlugins")) { | ||
try { | ||
this.db.set("picgoPlugins", {}) | ||
} catch (e: any) { | ||
this.ctx.log.error(e) | ||
throw e | ||
} | ||
} | ||
} | ||
|
||
read(flush?: boolean): IJSON { | ||
return this.db.read(flush) | ||
} | ||
|
||
get(key: ""): any { | ||
this.read(true) | ||
return this.db.get(key) | ||
} | ||
|
||
set(key: string, value: any): void { | ||
this.read(true) | ||
return this.db.set(key, value) | ||
} | ||
|
||
has(key: string): boolean { | ||
this.read(true) | ||
return this.db.has(key) | ||
} | ||
|
||
unset(key: string, value: any): boolean { | ||
this.read(true) | ||
return this.db.unset(key, value) | ||
} | ||
|
||
saveConfig(config: Partial<IConfig>): void { | ||
Object.keys(config).forEach((name: string) => { | ||
this.set(name, config[name]) | ||
}) | ||
} | ||
|
||
removeConfig(config: IConfig): void { | ||
Object.keys(config).forEach((name: string) => { | ||
this.unset(name, config[name]) | ||
}) | ||
} | ||
} | ||
|
||
export default DB |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
/** | ||
* 实现 fs.pathExistsSync 函数 | ||
* | ||
* @param fs | ||
* @param path | ||
* @param filePath | ||
*/ | ||
export const pathExistsSync = (fs: any, path: any, filePath: string) => { | ||
try { | ||
fs.accessSync(path.join(filePath), fs.constants.F_OK) | ||
return true | ||
} catch (err: any) { | ||
if (err && err.code === "ENOENT") { | ||
return false | ||
} else { | ||
throw err | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* 实现 fs.ensureFileSync 函数 | ||
* | ||
* @param fs | ||
* @param path | ||
* @param filePath | ||
*/ | ||
export const ensureFileSync = (fs: any, path: any, filePath: string) => { | ||
const directory = path.dirname(filePath) | ||
if (!fs.existsSync(directory)) { | ||
fs.mkdirSync(directory, { recursive: true }) | ||
} | ||
if (!fs.existsSync(filePath)) { | ||
fs.writeFileSync(filePath, "") | ||
} | ||
} |
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,4 +1,22 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["./node_modules/@terwer/eslint-config-custom/typescript/index.cjs"], | ||
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "turbo", "prettier"], | ||
|
||
parser: "@typescript-eslint/parser", | ||
|
||
plugins: ["@typescript-eslint", "prettier"], | ||
|
||
rules: { | ||
// Note: you must disable the base rule as it can report incorrect errors | ||
semi: "off", | ||
quotes: "off", | ||
"no-undef": "off", | ||
"@typescript-eslint/no-var-requires": "off", | ||
"@typescript-eslint/no-this-alias": "off", | ||
"@typescript-eslint/no-non-null-assertion": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/no-explicit-any": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"turbo/no-undeclared-env-vars": "off", | ||
"prettier/prettier": "error", | ||
}, | ||
} |
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,2 +1,3 @@ | ||
.idea | ||
.DS_Store | ||
.DS_Store | ||
dist |
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,13 +1,7 @@ | ||
import { simpleLogger, MainFunction } from "zhi-lib-base" | ||
import { JSONStore } from "./lib/JSONStore" | ||
import { win, hasNodeEnv } from "./lib/utils" | ||
import { IJSON } from "./types" | ||
|
||
/** | ||
* 初始化入口 | ||
* | ||
* @param args | ||
*/ | ||
const main: MainFunction = async (args: any[]) => { | ||
const logger = simpleLogger("main", "zhi", false) | ||
return "ok" | ||
} | ||
|
||
export default main | ||
export { type IJSON } | ||
export { JSONStore } | ||
export { win, hasNodeEnv } |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
import { IJSON } from "../types" | ||
|
||
class JSONStore { | ||
constructor(dbPath: string) { | ||
if (!dbPath) { | ||
throw Error("Please provide valid dbPath") | ||
} | ||
} | ||
|
||
read(flush = false): IJSON { | ||
throw Error("Not Implemented") | ||
} | ||
|
||
get(key = ""): any { | ||
throw Error("get Not Implemented for json store") | ||
} | ||
|
||
set(key: string, value: any): void { | ||
throw Error("Not Implemented") | ||
} | ||
|
||
has(key: string): boolean { | ||
throw Error("Not Implemented") | ||
} | ||
|
||
unset(key: string, value: any): boolean { | ||
throw Error("Not Implemented") | ||
} | ||
} | ||
|
||
export { JSONStore } |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
const currentWin = (window || globalThis || undefined) as any | ||
const parentWin = (window?.parent || window?.top || window?.self || undefined) as any | ||
export const win = currentWin?.fs ? currentWin : parentWin?.fs ? parentWin : currentWin | ||
export const hasNodeEnv = typeof win?.fs !== "undefined" |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* GNU GENERAL PUBLIC LICENSE | ||
* Version 3, 29 June 2007 | ||
* | ||
* Copyright (C) 2024 Terwer, Inc. <https://terwer.space/> | ||
* Everyone is permitted to copy and distribute verbatim copies | ||
* of this license document, but changing it is not allowed. | ||
*/ | ||
|
||
export interface IJSON { | ||
[propsName: string]: string | number | IJSON | ||
} |
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
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
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
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
Oops, something went wrong.