func PkgList(ctx *middleware.Context) { rs, err := models.GetAllLastRepoByOsArch(ctx.Query("os"), ctx.Query("arch")) if err != nil { ctx.JSON(400, nil) return } var result []*PackageItem var lastRid int64 = 0 for _, lr := range rs { if lr.Rid == lastRid { if pos := len(result) - 1; pos >= 0 { r := result[pos] r.Branches = append(r.Branches, Branch{lr.TagBranch, lr.PushURI, fmtTime(lr.Updated), lr.Os, lr.Arch, lr.ZipBallUrl}) } continue } lastRid = lr.Rid repo, err := models.GetRepositoryById(lr.Rid) if err != nil { log.Errorf("a missing repo in last_repo_update: %v", lr) continue } br := Branch{lr.TagBranch, lr.PushURI, fmtTime(lr.Updated), lr.Os, lr.Arch, lr.ZipBallUrl} result = append(result, &PackageItem{ Name: repo.Uri, // "github.com/nsf/gocode", Description: repo.Brief, // "golang code complete", Branches: []Branch{br}, }) } ctx.JSON(200, result) }
func Download(ctx *middleware.Context) { rid, _ := strconv.Atoi(ctx.Request.FormValue("rid")) os := ctx.Request.FormValue("os") arch := ctx.Request.FormValue("arch") task, err := models.GetOneDownloadableTask(int64(rid), os, arch) if err != nil { log.Errorf("get download task: %v", err) http.Error(ctx.ResponseWriter, err.Error(), http.StatusNotFound) return } models.RefreshPageView("/d/" + ctx.Query("rid")) ctx.Redirect(302, task.ZipBallUrl) }
func History(ctx *middleware.Context, params martini.Params, req *http.Request) { id, _ := strconv.Atoi(req.FormValue("id")) tid := int64(id) task, err := models.GetTaskById(tid) if err != nil { log.Errorf("get task by id error: %v", err) } history, err := models.GetAllBuildHistoryByTid(tid) if err != nil { log.Errorf("get task history error: %v", err) } ctx.Data = map[string]interface{}{ "Task": task, "History": history, "AutoRefresh": ctx.Query("auto_refresh") == "true", } ctx.HTML(200, "history") }