domain.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import type { CertificateInfo } from '@/api/cert'
  2. import type { NgxConfig } from '@/api/ngx'
  3. import type { ChatComplicationMessage } from '@/api/openai'
  4. import type { PrivateKeyType } from '@/constants'
  5. import Curd from '@/api/curd'
  6. import http from '@/lib/http'
  7. export interface Site {
  8. modified_at: string
  9. advanced: boolean
  10. enabled: boolean
  11. name: string
  12. filepath: string
  13. config: string
  14. auto_cert: boolean
  15. chatgpt_messages: ChatComplicationMessage[]
  16. tokenized?: NgxConfig
  17. cert_info?: Record<number, CertificateInfo[]>
  18. }
  19. export interface AutoCertRequest {
  20. dns_credential_id: number | null
  21. challenge_method: string
  22. domains: string[]
  23. key_type: PrivateKeyType
  24. }
  25. class Domain extends Curd<Site> {
  26. // eslint-disable-next-line ts/no-explicit-any
  27. enable(name: string, config?: any) {
  28. return http.post(`${this.baseUrl}/${name}/enable`, undefined, config)
  29. }
  30. disable(name: string) {
  31. return http.post(`${this.baseUrl}/${name}/disable`)
  32. }
  33. get_template() {
  34. return http.get('template')
  35. }
  36. add_auto_cert(domain: string, data: AutoCertRequest) {
  37. return http.post(`auto_cert/${domain}`, data)
  38. }
  39. remove_auto_cert(domain: string) {
  40. return http.delete(`auto_cert/${domain}`)
  41. }
  42. duplicate(name: string, data: { name: string }): Promise<{ dst: string }> {
  43. return http.post(`${this.baseUrl}/${name}/duplicate`, data)
  44. }
  45. advance_mode(name: string, data: { advanced: boolean }) {
  46. return http.post(`${this.baseUrl}/${name}/advance`, data)
  47. }
  48. }
  49. const domain = new Domain('/domains')
  50. export default domain