mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: sync
This commit is contained in:
28
src/utils.ts
vendored
28
src/utils.ts
vendored
@@ -1,8 +1,9 @@
|
||||
import { readTextFile, writeTextFile, exists } from '@tauri-apps/api/fs';
|
||||
import { homeDir, join } from '@tauri-apps/api/path';
|
||||
import { readTextFile, writeTextFile, exists, createDir, BaseDirectory } from '@tauri-apps/api/fs';
|
||||
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_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 = {
|
||||
@@ -19,18 +20,24 @@ 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 chatPromptsPath = async (): Promise<string> => {
|
||||
return join(await chatRoot(), CHAT_PROMPTS_CSV);
|
||||
}
|
||||
|
||||
export const readJSON = async (path: string, defaultVal = {}) => {
|
||||
type readJSONOpts = { defaultVal?: Record<string, any>, isRoot?: boolean };
|
||||
export const readJSON = async (path: string, opts: readJSONOpts = {}) => {
|
||||
const { defaultVal = {}, isRoot = false } = opts;
|
||||
const root = await chatRoot();
|
||||
const file = await join(root, path);
|
||||
const file = await join(isRoot ? '' : root, path);
|
||||
|
||||
if (!await exists(file)) {
|
||||
writeTextFile(file, JSON.stringify({
|
||||
name: 'ChatGPT',
|
||||
link: 'https://github.com/lencx/ChatGPT/blob/main/chat.model.md',
|
||||
link: 'https://github.com/lencx/ChatGPT',
|
||||
...defaultVal,
|
||||
}, null, 2))
|
||||
}
|
||||
@@ -42,9 +49,16 @@ export const readJSON = async (path: string, defaultVal = {}) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const writeJSON = async (path: string, data: Record<string, any>) => {
|
||||
type writeJSONOpts = { dir?: string, isRoot?: boolean };
|
||||
export const writeJSON = async (path: string, data: Record<string, any>, opts: writeJSONOpts = {}) => {
|
||||
const { isRoot = false, dir = '' } = opts;
|
||||
const root = await chatRoot();
|
||||
const file = await join(root, path);
|
||||
const file = await join(isRoot ? '' : root, path);
|
||||
|
||||
if (isRoot && !await exists(await dirname(file))) {
|
||||
await createDir(await join('.chatgpt', dir), { dir: BaseDirectory.Home });
|
||||
}
|
||||
|
||||
await writeTextFile(file, JSON.stringify(data, null, 2));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user