You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

125 lines
7.3 KiB

  1. package aiping
  2. import "net/http"
  3. const (
  4. ActionText2Video = "kling-text2video"
  5. ActionImage2Video = "kling-image2video"
  6. ActionMotionControl = "kling-motion-control"
  7. ActionOmniVideo = "kling-omni-video"
  8. ActionMultiImage2Video = "kling-multi-image2video"
  9. ActionMultiElements = "kling-multi-elements"
  10. ActionAdvancedElements = "kling-advanced-elements-create"
  11. ActionVoicesCreate = "kling-voices-create"
  12. ActionDeleteElements = "kling-delete-elements"
  13. ActionDeleteVoices = "kling-voices-delete"
  14. )
  15. const (
  16. RouteKindSubmit = "submit"
  17. RouteKindFetch = "fetch"
  18. RouteKindList = "list"
  19. RouteKindProxy = "proxy"
  20. )
  21. const (
  22. ModelKlingElements = "kling-elements"
  23. ModelKlingAdvancedElements = "kling-advanced-elements"
  24. ModelCustomVoices = "custom-voices"
  25. )
  26. type Route struct {
  27. Method string
  28. PathPattern string
  29. Action string
  30. UpstreamPath string
  31. Kind string
  32. BillingModel string
  33. }
  34. var Routes = []Route{
  35. {http.MethodPost, "/v1/videos/text2video", ActionText2Video, "/v1/videos/kling/text2video", RouteKindSubmit, ""},
  36. {http.MethodGet, "/v1/videos/text2video/:task_id", ActionText2Video, "/v1/videos/kling/text2video/:task_id", RouteKindFetch, ""},
  37. {http.MethodGet, "/v1/videos/text2video", ActionText2Video, "/v1/videos/kling/text2video", RouteKindList, ""},
  38. {http.MethodPost, "/v1/videos/image2video", ActionImage2Video, "/v1/videos/kling/image2video", RouteKindSubmit, ""},
  39. {http.MethodGet, "/v1/videos/image2video/:task_id", ActionImage2Video, "/v1/videos/kling/image2video/:task_id", RouteKindFetch, ""},
  40. {http.MethodGet, "/v1/videos/image2video", ActionImage2Video, "/v1/videos/kling/image2video", RouteKindList, ""},
  41. {http.MethodPost, "/v1/videos/motion-control", ActionMotionControl, "/v1/videos/kling/motion-control", RouteKindSubmit, "kling-v2-6"},
  42. {http.MethodGet, "/v1/videos/motion-control/:task_id", ActionMotionControl, "/v1/videos/kling/motion-control/:task_id", RouteKindFetch, "kling-v2-6"},
  43. {http.MethodGet, "/v1/videos/motion-control", ActionMotionControl, "/v1/videos/kling/motion-control", RouteKindList, "kling-v2-6"},
  44. {http.MethodPost, "/v1/videos/omni-video", ActionOmniVideo, "/v1/videos/kling/omni-video", RouteKindSubmit, ""},
  45. {http.MethodGet, "/v1/videos/omni-video/:task_id", ActionOmniVideo, "/v1/videos/kling/omni-video/:task_id", RouteKindFetch, ""},
  46. {http.MethodGet, "/v1/videos/omni-video", ActionOmniVideo, "/v1/videos/kling/omni-video", RouteKindList, ""},
  47. {http.MethodPost, "/v1/videos/multi-image2video", ActionMultiImage2Video, "/v1/videos/kling/multi-image2video", RouteKindSubmit, ""},
  48. {http.MethodGet, "/v1/videos/multi-image2video/:task_id", ActionMultiImage2Video, "/v1/videos/kling/multi-image2video/:task_id", RouteKindFetch, ""},
  49. {http.MethodGet, "/v1/videos/multi-image2video", ActionMultiImage2Video, "/v1/videos/kling/multi-image2video", RouteKindList, ""},
  50. {http.MethodPost, "/v1/videos/multi-elements", ActionMultiElements, "/v1/videos/kling/multi-elements", RouteKindSubmit, "kling-v1-6"},
  51. {http.MethodGet, "/v1/videos/multi-elements/:task_id", ActionMultiElements, "/v1/videos/kling/multi-elements/:task_id", RouteKindFetch, "kling-v1-6"},
  52. {http.MethodGet, "/v1/videos/multi-elements", ActionMultiElements, "/v1/videos/kling/multi-elements", RouteKindList, "kling-v1-6"},
  53. {http.MethodPost, "/v1/videos/multi-elements/init-selection", "kling-multi-elements-init-selection", "/v1/videos/kling/multi-elements/init-selection", RouteKindProxy, ModelKlingElements},
  54. {http.MethodPost, "/v1/videos/multi-elements/add-selection", "kling-multi-elements-add-selection", "/v1/videos/kling/multi-elements/add-selection", RouteKindProxy, ModelKlingElements},
  55. {http.MethodPost, "/v1/videos/multi-elements/delete-selection", "kling-multi-elements-delete-selection", "/v1/videos/kling/multi-elements/delete-selection", RouteKindProxy, ModelKlingElements},
  56. {http.MethodPost, "/v1/videos/multi-elements/clear-selection", "kling-multi-elements-clear-selection", "/v1/videos/kling/multi-elements/clear-selection", RouteKindProxy, ModelKlingElements},
  57. {http.MethodPost, "/v1/videos/multi-elements/preview-selection", "kling-multi-elements-preview-selection", "/v1/videos/kling/multi-elements/preview-selection", RouteKindProxy, ModelKlingElements},
  58. {http.MethodPost, "/v1/elements/custom", "kling-elements-custom-create", "/v1/elements/custom", RouteKindProxy, ModelKlingElements},
  59. {http.MethodGet, "/v1/elements/custom", "kling-elements-custom-list", "/v1/elements/custom", RouteKindProxy, ModelKlingElements},
  60. {http.MethodGet, "/v1/elements/:id", "kling-elements-get", "/v1/elements/:id", RouteKindProxy, ModelKlingElements},
  61. {http.MethodGet, "/v1/elements/presets", "kling-elements-presets", "/v1/elements/presets", RouteKindProxy, ModelKlingElements},
  62. {http.MethodPost, "/v1/elements/delete", "kling-elements-delete", "/v1/elements/delete", RouteKindProxy, ModelKlingElements},
  63. {http.MethodPost, "/v1/kling/general/advanced-custom-elements", ActionAdvancedElements, "/v1/kling/general/advanced-custom-elements", RouteKindSubmit, ModelKlingAdvancedElements},
  64. {http.MethodGet, "/v1/kling/general/advanced-custom-elements/:task_id", ActionAdvancedElements, "/v1/kling/general/advanced-custom-elements/:task_id", RouteKindFetch, ModelKlingAdvancedElements},
  65. {http.MethodGet, "/v1/kling/general/advanced-custom-elements", "kling-advanced-elements-list", "/v1/kling/general/advanced-custom-elements", RouteKindProxy, ModelKlingAdvancedElements},
  66. {http.MethodGet, "/v1/kling/general/advanced-presets-elements", "kling-advanced-elements-presets", "/v1/kling/general/advanced-presets-elements", RouteKindProxy, ModelKlingAdvancedElements},
  67. {http.MethodPost, "/v1/kling/general/delete-elements", ActionDeleteElements, "/v1/kling/general/delete-elements", RouteKindProxy, ModelKlingAdvancedElements},
  68. {http.MethodPost, "/v1/kling/general/custom-voices", ActionVoicesCreate, "/v1/kling/general/custom-voices", RouteKindSubmit, ModelCustomVoices},
  69. {http.MethodGet, "/v1/kling/general/custom-voices/:task_id", ActionVoicesCreate, "/v1/kling/general/custom-voices/:task_id", RouteKindFetch, ModelCustomVoices},
  70. {http.MethodGet, "/v1/kling/general/custom-voices", "kling-voices-list", "/v1/kling/general/custom-voices", RouteKindProxy, ModelCustomVoices},
  71. {http.MethodGet, "/v1/kling/general/presets-voices", "kling-voices-presets", "/v1/kling/general/presets-voices", RouteKindProxy, ModelCustomVoices},
  72. {http.MethodPost, "/v1/kling/general/delete-voices", ActionDeleteVoices, "/v1/kling/general/delete-voices", RouteKindProxy, ModelCustomVoices},
  73. }
  74. func FindRoute(method, pathPattern, kind string) (Route, bool) {
  75. for _, route := range Routes {
  76. if route.Method == method && route.PathPattern == pathPattern && route.Kind == kind {
  77. return route, true
  78. }
  79. }
  80. return Route{}, false
  81. }
  82. func FindRouteByAction(action string) (Route, bool) {
  83. for _, route := range Routes {
  84. if route.Action == action && route.Kind == RouteKindSubmit {
  85. return route, true
  86. }
  87. }
  88. return Route{}, false
  89. }
  90. func FindFetchRouteByAction(action string) (Route, bool) {
  91. for _, route := range Routes {
  92. if route.Action == action && route.Kind == RouteKindFetch {
  93. return route, true
  94. }
  95. }
  96. return Route{}, false
  97. }
  98. func Models() []string {
  99. return []string{
  100. "kling-v1",
  101. "kling-v1-6",
  102. "kling-v2-6",
  103. "kling-v3",
  104. "kling-video-o1",
  105. "kling-v3-omni",
  106. ModelKlingElements,
  107. ModelKlingAdvancedElements,
  108. ModelCustomVoices,
  109. }
  110. }