config.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import type { GetListResponse } from '@/api/curd'
  2. import type { ChatComplicationMessage } from '@/api/openai'
  3. import { extendCurdApi, http, useCurdApi } from '@uozi-admin/request'
  4. export interface ModelBase {
  5. id: number
  6. created_at: string
  7. updated_at: string
  8. }
  9. export interface Config {
  10. name: string
  11. content: string
  12. chatgpt_messages: ChatComplicationMessage[]
  13. filepath: string
  14. modified_at: string
  15. sync_node_ids?: number[]
  16. sync_overwrite?: false
  17. dir: string
  18. }
  19. export interface ConfigBackup extends ModelBase {
  20. name: string
  21. filepath: string
  22. content: string
  23. }
  24. const config = extendCurdApi(useCurdApi<Config>('/configs'), {
  25. get_base_path: () => http.get('/config_base_path'),
  26. mkdir: (basePath: string, name: string) => http.post('/config_mkdir', { base_path: basePath, folder_name: name }),
  27. rename: (basePath: string, origName: string, newName: string, syncNodeIds?: number[]) => http.post('/config_rename', {
  28. base_path: basePath,
  29. orig_name: origName,
  30. new_name: newName,
  31. sync_node_ids: syncNodeIds,
  32. }),
  33. delete: (basePath: string, name: string, syncNodeIds?: number[]) => http.post('/config_delete', {
  34. base_path: basePath,
  35. name,
  36. sync_node_ids: syncNodeIds,
  37. }),
  38. get_history: (filepath: string, params?: { page: number, page_size: number }) => {
  39. return http.get<GetListResponse<ConfigBackup>>('/config_histories', { params: { filepath, ...params } })
  40. },
  41. })
  42. export default config