| | |
| | | type AppApi struct{ |
| | | |
| | | } |
| | | type AppWithShop struct { |
| | | protomsg.App |
| | | RemoteVersion string `json:"remoteVersion"` //商城仓库版本号 |
| | | Installed bool `json:"installed"` //是否已安装 |
| | | IsUpgrade bool `json:"isUpgrade"` //是否需要升级 |
| | | ProgressMsg string `json:"progressMsg"` //安装或升级进度 |
| | | } |
| | | |
| | | func (api AppApi) FindAll(appName string) (list []protomsg.App) { |
| | | url := DATA_URL_PREFIX + "/app/findAllApp" |
| | |
| | | return res.Success, res.Data |
| | | } |
| | | |
| | | // id传算法或者应用的id,下载安装或升级 |
| | | func (api AppApi) Upgrade(id string) (bool, interface{}) { |
| | | url := DATA_URL_PREFIX + "/sdk/sdkDownload" |
| | | netNode := getNetNode(url2Topic(Topic_AppCenter_Service, url)) |
| | | client := NewClient(WithNodes(netNode)) |
| | | paramMap := map[string]string { |
| | | "path": id, |
| | | } |
| | | body, err := client.DoGetRequest(url,paramMap,nil) |
| | | if err != nil { |
| | | return false, err.Error() |
| | | } |
| | | |
| | | var res Result |
| | | if err = json.Unmarshal(body, &res); err != nil { |
| | | return false, err.Error() |
| | | } |
| | | return res.Success, res.Data |
| | | } |
| | | |
| | | //获取所有已安装的app列表,以package为key |
| | | func (api AppApi) FindAppMap() map[string]protomsg.App { |
| | | m := make(map[string]protomsg.App) |
| | |
| | | } |
| | | |
| | | return m |
| | | } |
| | | |
| | | //获取带安装状态的app列表 |
| | | func (api AppApi) FindAppWithInstallStatus(appName string) (list []AppWithShop) { |
| | | url := DATA_URL_PREFIX + "/app/findAllApp" |
| | | netNode := getNetNode(url2Topic(Topic_AppCenter_Service, url)) |
| | | logPrint("netNode:", netNode) |
| | | client := NewClient(WithNodes(netNode)) |
| | | paramMap := make(map[string]string, 0) |
| | | paramMap["appName"] = appName |
| | | respBody, err := client.DoGetRequest(url, paramMap, nil) |
| | | logPrint("DoGetRequest err:", err) |
| | | if err !=nil { |
| | | return nil |
| | | } |
| | | var res Result |
| | | if err = json.Unmarshal(respBody, &res); err != nil { |
| | | logPrint(err) |
| | | return nil |
| | | } |
| | | bytes, _ := json.Marshal(res.Data) |
| | | err = json.Unmarshal(bytes, &list) |
| | | if err == nil { |
| | | return list |
| | | } else { |
| | | logPrint("unmarshal err:", err) |
| | | return nil |
| | | } |
| | | } |