diff --git a/.vscode/launch.json b/.vscode/launch.json index 0ea07b8..1a25dd6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,7 +6,7 @@ "type": "go", "debugAdapter": "dlv-dap", "request": "launch", - "port": 34933, + "port": 33107, "host": "127.0.0.1", "mode": "exec", "program": "${workspaceFolder}/dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service" diff --git a/service/1panel.go b/service/1panel.go index b062f70..e407613 100644 --- a/service/1panel.go +++ b/service/1panel.go @@ -14,6 +14,11 @@ type OnePanelService interface { Login(m model2.OnePanelCredentials, baseURL string) (model2.LoginResponse, []*http.Cookie, error) Logout(m model2.OnePanelCredentials, baseURL string) (model2.LogoutResponse, error) HealthCheck(baseURL string) (string, error) + SearchInstalledApp(p model2.InstalledAppRequest, baseURL string) (model2.InstalledAppResponse, error) + // InstallApp() + // SearchWebsite() + // CreateWebsite() + // DeleteWebsite() } var ( @@ -23,6 +28,33 @@ var ( type onePanelService struct { } +func (o *onePanelService) SearchInstalledApp(m model2.InstalledAppRequest, baseUrl string) (model2.InstalledAppResponse, error) { + path := baseUrl + "/api/v1/websites/search" + reqBody, err := json.Marshal(m) + if err != nil { + return model2.InstalledAppResponse{}, fmt.Errorf("error marshaling request body: %v", err) + } + req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody)) + // req.AddCookie() + if err != nil { + return model2.InstalledAppResponse{}, fmt.Errorf("error creating request: %v", err) + } + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return model2.InstalledAppResponse{}, fmt.Errorf("error making request: %v", err) + } + defer resp.Body.Close() + if resp.StatusCode < 200 || resp.StatusCode >= 300 { + return model2.InstalledAppResponse{}, fmt.Errorf("HTTP error: %s", resp.Status) + } + var result model2.InstalledAppResponse + if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { + return model2.InstalledAppResponse{}, fmt.Errorf("error decoding response: %v", err) + } + + return result, nil +} func (o *onePanelService) Login(m model2.OnePanelCredentials, baseURL string) (model2.LoginResponse, []*http.Cookie, error) { path := baseURL + prefixV1 + "/auth/login" diff --git a/service/model/dto_onepanel_app.go b/service/model/dto_onepanel_app.go new file mode 100644 index 0000000..9ed69fb --- /dev/null +++ b/service/model/dto_onepanel_app.go @@ -0,0 +1,47 @@ +package model + +import "time" + +type InstalledAppRequest struct { + Page int `json:"page"` + PageSize int `json:"pageSize"` + Name string `json:"name"` + Tags []interface{} `json:"tags"` + Update bool `json:"update"` + Sync bool `json:"sync"` +} + +type InstalledAppResponse struct { + Code int `json:"code"` + Message string `json:"message"` + Data struct { + Total int `json:"total"` + Items []struct { + ID int `json:"id"` + Name string `json:"name"` + AppID int `json:"appID"` + AppDetailID int `json:"appDetailID"` + Version string `json:"version"` + Status string `json:"status"` + Message string `json:"message"` + HTTPPort int `json:"httpPort"` + HTTPSPort int `json:"httpsPort"` + Path string `json:"path"` + CanUpdate bool `json:"canUpdate"` + Icon string `json:"icon"` + AppName string `json:"appName"` + Ready int `json:"ready"` + Total int `json:"total"` + AppKey string `json:"appKey"` + AppType string `json:"appType"` + AppStatus string `json:"appStatus"` + DockerCompose string `json:"dockerCompose"` + CreatedAt time.Time `json:"createdAt"` + App struct { + Website string `json:"website"` + Document string `json:"document"` + Github string `json:"github"` + } `json:"app"` + } `json:"items"` + } `json:"data"` +} diff --git a/service/model/dto_onepanel_ssl.go b/service/model/dto_onepanel_ssl.go new file mode 100644 index 0000000..2f3259c --- /dev/null +++ b/service/model/dto_onepanel_ssl.go @@ -0,0 +1,47 @@ +package model + +type CreateSSLRequest struct { + ID int `json:"id"` + PrimaryDomain string `json:"primaryDomain"` + OtherDomains string `json:"otherDomains"` + Provider string `json:"provider"` + WebsiteID int `json:"websiteId"` + AcmeAccountID int `json:"acmeAccountId"` + AutoRenew bool `json:"autoRenew"` + KeyType string `json:"keyType"` + PushDir bool `json:"pushDir"` + Dir string `json:"dir"` + Description string `json:"description"` + DisableCNAME bool `json:"disableCNAME"` + SkipDNS bool `json:"skipDNS"` + Nameserver1 string `json:"nameserver1"` + Nameserver2 string `json:"nameserver2"` + ExecShell bool `json:"execShell"` + Shell string `json:"shell"` +} + +type CreateSSLResponse struct { + Code int `json:"code"` + Message string `json:"message"` + Data struct { + PrimaryDomain string `json:"primaryDomain"` + OtherDomains string `json:"otherDomains"` + Provider string `json:"provider"` + AcmeAccountID int `json:"acmeAccountId"` + DNSAccountID int `json:"dnsAccountId"` + AutoRenew bool `json:"autoRenew"` + KeyType string `json:"keyType"` + Apply bool `json:"apply"` + PushDir bool `json:"pushDir"` + Dir string `json:"dir"` + ID int `json:"id"` + Description string `json:"description"` + DisableCNAME bool `json:"disableCNAME"` + SkipDNS bool `json:"skipDNS"` + Nameserver1 string `json:"nameserver1"` + Nameserver2 string `json:"nameserver2"` + ExecShell bool `json:"execShell"` + Shell string `json:"shell"` + } `json:"data"` +} + diff --git a/service/model/dtop_onepanel_website.go b/service/model/dtop_onepanel_website.go new file mode 100644 index 0000000..bb5fa26 --- /dev/null +++ b/service/model/dtop_onepanel_website.go @@ -0,0 +1,87 @@ +package model + +import "time" + +type SearchWebsiteRequest struct { + Name string `json:"name"` + Page int `json:"page"` + PageSize int `json:"pageSize"` + OrderBy string `json:"orderBy"` + Order string `json:"order"` + WebsiteGroupID int `json:"websiteGroupId"` +} + +type SearchWebsiteResponse struct { + Code int `json:"code"` + Message string `json:"message"` + Data struct { + Total int `json:"total"` + Items []struct { + ID int `json:"id"` + CreatedAt time.Time `json:"createdAt"` + Protocol string `json:"protocol"` + PrimaryDomain string `json:"primaryDomain"` + Type string `json:"type"` + Alias string `json:"alias"` + Remark string `json:"remark"` + Status string `json:"status"` + ExpireDate time.Time `json:"expireDate"` + SitePath string `json:"sitePath"` + AppName string `json:"appName"` + RuntimeName string `json:"runtimeName"` + SslExpireDate time.Time `json:"sslExpireDate"` + SslStatus string `json:"sslStatus"` + AppInstallID int `json:"appInstallId"` + RuntimeType string `json:"runtimeType"` + } `json:"items"` + } `json:"data"` +} + +type CreateWebsiteRequest struct { + PrimaryDomain string `json:"primaryDomain"` + Type string `json:"type"` + Alias string `json:"alias"` + Remark string `json:"remark"` + AppType string `json:"appType"` + WebSiteGroupID int `json:"webSiteGroupId"` + OtherDomains string `json:"otherDomains"` + Proxy string `json:"proxy"` + Appinstall struct { + AppID int `json:"appId"` + Name string `json:"name"` + AppDetailID int `json:"appDetailId"` + Params struct { + } `json:"params"` + Version string `json:"version"` + Appkey string `json:"appkey"` + Advanced bool `json:"advanced"` + CPUQuota int `json:"cpuQuota"` + MemoryLimit int `json:"memoryLimit"` + MemoryUnit string `json:"memoryUnit"` + ContainerName string `json:"containerName"` + AllowPort bool `json:"allowPort"` + } `json:"appinstall"` + IPV6 bool `json:"IPV6"` + EnableFtp bool `json:"enableFtp"` + FtpUser string `json:"ftpUser"` + FtpPassword string `json:"ftpPassword"` + ProxyType string `json:"proxyType"` + Port int `json:"port"` + ProxyProtocol string `json:"proxyProtocol"` + ProxyAddress string `json:"proxyAddress"` + RuntimeType string `json:"runtimeType"` +} + +type DeleteWebsiteRequest struct { + ID int `json:"id"` + DeleteApp bool `json:"deleteApp"` + DeleteBackup bool `json:"deleteBackup"` + ForceDelete bool `json:"forceDelete"` +} + +type GenericResponse struct { + Code int `json:"code"` + Message string `json:"message"` + Data struct { + } `json:"data"` +}