| @@ -150,6 +150,38 @@ sendjob: | |||||
| return &getImagesResult, nil | return &getImagesResult, nil | ||||
| } | } | ||||
| func GetPublicImages() (*models.GetImagesResult, error) { | |||||
| checkSetting() | |||||
| client := getRestyClient() | |||||
| var getImagesResult models.GetImagesResult | |||||
| retry := 0 | |||||
| sendjob: | |||||
| res, err := client.R(). | |||||
| SetHeader("Content-Type", "application/json"). | |||||
| SetAuthToken(TOKEN). | |||||
| SetBody(map[string]interface{}{"pageIndex": 1, "pageSize": 50}). | |||||
| SetResult(&getImagesResult). | |||||
| Get(HOST + "/rest-server/api/v1/image/public/list/") | |||||
| if err != nil { | |||||
| return nil, fmt.Errorf("resty GetPublicImages: %v", err) | |||||
| } | |||||
| if getImagesResult.Code == "S401" && retry < 1 { | |||||
| retry++ | |||||
| _ = loginCloudbrain() | |||||
| goto sendjob | |||||
| } | |||||
| if getImagesResult.Code != Success { | |||||
| return &getImagesResult, fmt.Errorf("getImgesResult err: %s", res.String()) | |||||
| } | |||||
| return &getImagesResult, nil | |||||
| } | |||||
| func CommitImage(jobID string, params models.CommitImageParams) error { | func CommitImage(jobID string, params models.CommitImageParams) error { | ||||
| checkSetting() | checkSetting() | ||||
| client := getRestyClient() | client := getRestyClient() | ||||
| @@ -101,6 +101,23 @@ func CloudBrainNew(ctx *context.Context) { | |||||
| ctx.Data["images"] = result.Payload.ImageInfo | ctx.Data["images"] = result.Payload.ImageInfo | ||||
| resultPublic, err := cloudbrain.GetPublicImages() | |||||
| if err != nil { | |||||
| ctx.Data["error"] = err.Error() | |||||
| log.Error("cloudbrain.GetPublicImages failed:", err.Error()) | |||||
| } | |||||
| for i, payload := range resultPublic.Payload.ImageInfo { | |||||
| log.Info(resultPublic.Payload.ImageInfo[i].Place) | |||||
| if strings.HasPrefix(resultPublic.Payload.ImageInfo[i].Place, "192.168") { | |||||
| resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place[strings.Index(payload.Place, "/"):len(payload.Place)] | |||||
| } else { | |||||
| resultPublic.Payload.ImageInfo[i].PlaceView = payload.Place | |||||
| } | |||||
| } | |||||
| ctx.Data["public_images"] = resultPublic.Payload.ImageInfo | |||||
| attachs, err := models.GetAllUserAttachments(ctx.User.ID) | attachs, err := models.GetAllUserAttachments(ctx.User.ID) | ||||
| if err != nil { | if err != nil { | ||||
| ctx.ServerError("GetAllUserAttachments failed:", err) | ctx.ServerError("GetAllUserAttachments failed:", err) | ||||
| @@ -126,6 +126,9 @@ | |||||
| {{range .images}} | {{range .images}} | ||||
| <option name="image" value="{{.Place}}">{{.PlaceView}}</option> | <option name="image" value="{{.Place}}">{{.PlaceView}}</option> | ||||
| {{end}} | {{end}} | ||||
| {{range .public_images}} | |||||
| <option name="image" value="{{.Place}}">{{.PlaceView}}</option> | |||||
| {{end}} | |||||
| </select> | </select> | ||||
| </div> | </div> | ||||