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:
2
src/hooks/useChatModel.ts
vendored
2
src/hooks/useChatModel.ts
vendored
@@ -1,5 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { clone } from 'lodash';
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
|
||||
import { CHAT_MODEL_JSON, readJSON, writeJSON } from '@/utils';
|
||||
import useInit from '@/hooks/useInit';
|
||||
@@ -16,6 +17,7 @@ export default function useChatModel(key: string) {
|
||||
const oData = clone(modelJson);
|
||||
oData[key] = data;
|
||||
await writeJSON(CHAT_MODEL_JSON, oData);
|
||||
await invoke('window_reload', { label: 'core' });
|
||||
setModelJson(oData);
|
||||
}
|
||||
|
||||
|
||||
28
src/hooks/useEvent.ts
vendored
Normal file
28
src/hooks/useEvent.ts
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import { invoke, http, fs, dialog } from '@tauri-apps/api';
|
||||
|
||||
import useInit from '@/hooks/useInit';
|
||||
import useChatModel from '@/hooks/useChatModel';
|
||||
import { GITHUB_PROMPTS_CSV_URL, chatPromptsPath, genCmd } from '@/utils';
|
||||
|
||||
export default function useEvent() {
|
||||
const { modelSet } = useChatModel('sys_sync_prompts');
|
||||
// Using `emit` and `listen` will be triggered multiple times in development mode.
|
||||
// So here we use `eval` to call `__sync_prompt`
|
||||
useInit(() => {
|
||||
(window as any).__sync_prompts = async () => {
|
||||
const res = await http.fetch(GITHUB_PROMPTS_CSV_URL, {
|
||||
method: 'GET',
|
||||
responseType: http.ResponseType.Text,
|
||||
});
|
||||
const data = (res.data || '') as string;
|
||||
if (res.ok) {
|
||||
await fs.writeTextFile(await chatPromptsPath(), data);
|
||||
const list: Record<string, string>[] = await invoke('parse_prompt', { data });
|
||||
modelSet(list.map(i => ({ cmd: genCmd(i.act), enable: true, tags: ['chatgpt-prompts'], ...i })));
|
||||
dialog.message('ChatGPT Prompts data has been synchronized!');
|
||||
} else {
|
||||
dialog.message('ChatGPT Prompts data sync failed, please try again!');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user