fix: path not allowed on the configured scope

This commit is contained in:
lencx
2022-12-23 20:02:32 +08:00
parent d93079f682
commit a7c4545dbf

4
src/utils.ts vendored
View File

@@ -52,12 +52,12 @@ export const readJSON = async (path: string, opts: readJSONOpts = {}) => {
type writeJSONOpts = { dir?: string, isRoot?: boolean }; type writeJSONOpts = { dir?: string, isRoot?: boolean };
export const writeJSON = async (path: string, data: Record<string, any>, opts: writeJSONOpts = {}) => { export const writeJSON = async (path: string, data: Record<string, any>, opts: writeJSONOpts = {}) => {
const { isRoot = false, dir = '' } = opts; const { isRoot = false } = opts;
const root = await chatRoot(); const root = await chatRoot();
const file = await join(isRoot ? '' : root, path); const file = await join(isRoot ? '' : root, path);
if (isRoot && !await exists(await dirname(file))) { if (isRoot && !await exists(await dirname(file))) {
await createDir(await join('.chatgpt', dir), { dir: BaseDirectory.Home }); await createDir(await dirname(file), { recursive: true });
} }
await writeTextFile(file, JSON.stringify(data, null, 2)); await writeTextFile(file, JSON.stringify(data, null, 2));