mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
feat: chatgpt prompts
This commit is contained in:
39
src/utils.ts
vendored
Normal file
39
src/utils.ts
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
import { readTextFile, writeTextFile, exists } from '@tauri-apps/api/fs';
|
||||
import { homeDir, join } from '@tauri-apps/api/path';
|
||||
|
||||
export const CHAT_MODEL_JSON = 'chat.model.json';
|
||||
export const DISABLE_AUTO_COMPLETE = {
|
||||
autoCapitalize: 'off',
|
||||
autoComplete: 'off',
|
||||
spellCheck: false
|
||||
};
|
||||
|
||||
const chatRoot = async () => {
|
||||
return join(await homeDir(), '.chatgpt')
|
||||
}
|
||||
|
||||
export const readJSON = async (path: string, defaultVal = {}) => {
|
||||
const root = await chatRoot();
|
||||
const file = await join(root, path);
|
||||
|
||||
if (!await exists(file)) {
|
||||
writeTextFile(file, JSON.stringify({
|
||||
name: 'ChatGPT',
|
||||
link: 'https://github.com/lencx/ChatGPT/blob/main/chat.model.md',
|
||||
data: null,
|
||||
...defaultVal,
|
||||
}, null, 2))
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(await readTextFile(file));
|
||||
} catch(e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
export const writeJSON = async (path: string, data: Record<string, any>) => {
|
||||
const root = await chatRoot();
|
||||
const file = await join(root, path);
|
||||
await writeTextFile(file, JSON.stringify(data, null, 2));
|
||||
}
|
||||
Reference in New Issue
Block a user