chore: sync

This commit is contained in:
lencx
2022-12-23 15:27:05 +08:00
parent 2be560e69a
commit 389e00a5e0
17 changed files with 260 additions and 252 deletions

15
src/utils.ts vendored
View File

@@ -3,7 +3,7 @@ import { homeDir, join, dirname } from '@tauri-apps/api/path';
import dayjs from 'dayjs';
export const CHAT_MODEL_JSON = 'chat.model.json';
export const CHAT_MODEL_SYNC_JSON = 'chat.model.sync.json';
export const CHAT_MODEL_CMD_JSON = 'chat.model.cmd.json';
export const CHAT_PROMPTS_CSV = 'chat.prompts.csv';
export const GITHUB_PROMPTS_CSV_URL = 'https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv';
export const DISABLE_AUTO_COMPLETE = {
@@ -20,22 +20,23 @@ export const chatModelPath = async (): Promise<string> => {
return join(await chatRoot(), CHAT_MODEL_JSON);
}
export const chatModelSyncPath = async (): Promise<string> => {
return join(await chatRoot(), CHAT_MODEL_SYNC_JSON);
}
// export const chatModelSyncPath = async (): Promise<string> => {
// return join(await chatRoot(), CHAT_MODEL_SYNC_JSON);
// }
export const chatPromptsPath = async (): Promise<string> => {
return join(await chatRoot(), CHAT_PROMPTS_CSV);
}
type readJSONOpts = { defaultVal?: Record<string, any>, isRoot?: boolean };
type readJSONOpts = { defaultVal?: Record<string, any>, isRoot?: boolean, isList?: boolean };
export const readJSON = async (path: string, opts: readJSONOpts = {}) => {
const { defaultVal = {}, isRoot = false } = opts;
const { defaultVal = {}, isRoot = false, isList = false } = opts;
const root = await chatRoot();
const file = await join(isRoot ? '' : root, path);
if (!await exists(file)) {
writeTextFile(file, JSON.stringify({
await createDir(await dirname(file), { recursive: true });
await writeTextFile(file, isList ? '[]' : JSON.stringify({
name: 'ChatGPT',
link: 'https://github.com/lencx/ChatGPT',
...defaultVal,