mirror of
https://github.com/FranP-code/ChatGPT.git
synced 2025-10-13 00:13:25 +00:00
chore: optim
This commit is contained in:
2
src/hooks/useData.ts
vendored
2
src/hooks/useData.ts
vendored
@@ -18,8 +18,6 @@ export default function useData(oData: any[]) {
|
||||
|
||||
const opInit = (val: any[] = []) => {
|
||||
if (!val || !Array.isArray(val)) return;
|
||||
console.log('«20» /src/hooks/useData.ts ~> ', val);
|
||||
|
||||
const nData = val.map(i => ({ [safeKey]: v4(), ...i }));
|
||||
setData(nData);
|
||||
};
|
||||
|
||||
34
src/hooks/useEvent.ts
vendored
34
src/hooks/useEvent.ts
vendored
@@ -1,34 +0,0 @@
|
||||
import { invoke, path, http, fs, dialog } from '@tauri-apps/api';
|
||||
|
||||
import useInit from '@/hooks/useInit';
|
||||
import useChatModel, { useCacheModel } from '@/hooks/useChatModel';
|
||||
import { GITHUB_PROMPTS_CSV_URL, chatRoot, genCmd } from '@/utils';
|
||||
|
||||
export default function useEvent() {
|
||||
const { modelSet } = useChatModel('sync_prompts');
|
||||
const { modelCacheSet } = useCacheModel();
|
||||
// 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) {
|
||||
const file = await path.join(await chatRoot(), 'cache_model', 'chatgpt_prompts.json');
|
||||
const list: Record<string, string>[] = await invoke('parse_prompt', { data });
|
||||
const fmtList = list.map(i => ({ ...i, cmd: i.cmd ? i.cmd : genCmd(i.act), enable: true, tags: ['chatgpt-prompts'] }));
|
||||
await modelCacheSet(fmtList, file);
|
||||
modelSet({
|
||||
id: 'chatgpt_prompts',
|
||||
last_updated: Date.now(),
|
||||
});
|
||||
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