func Auth(ctx *middleware.Context) { if len(setting.AccessToken) == 0 || ctx.GetCookie("access_token") != setting.AccessToken { ctx.Data["PageIsAuth"] = true ctx.HTML(200, "auth") } }
func LargeRevisions(ctx *middleware.Context) { ctx.Data["PageIsPackages"] = true ctx.Data["PageIsPackagesLarges"] = true models.GetLocalRevisions() ctx.HTML(200, "packages/larges") }
func Search(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Locale.Tr("search") ctx.Data["SearchKeyword"] = ctx.Query("q") pkgs, err := models.SearchPackages(ctx.Query("q")) if err != nil { ctx.Handle(500, "SearchPackages", err) return } ctx.Data["ResultPackages"] = pkgs ctx.HTML(200, "search") }
func BlockRules(ctx *middleware.Context) { ctx.Data["PageIsBlocks"] = true ctx.Data["PageIsBlocksRules"] = true rules, err := models.ListBlockRules(0) if err != nil { ctx.Handle(500, "ListBlockRules", err) return } ctx.Data["Rules"] = rules ctx.HTML(200, "blocks/rules") }
func Blocks(ctx *middleware.Context) { ctx.Data["PageIsBlocks"] = true ctx.Data["PageIsBlocksList"] = true blocks, err := models.ListBlockedPackages(0) if err != nil { ctx.Handle(500, "ListBlockedPackages", err) return } ctx.Data["Blocks"] = blocks ctx.HTML(200, "blocks/list") }
func Package(ctx *middleware.Context) { importPath := ctx.Params("*") _, err := models.GetPakcageByPath(importPath) if err != nil { if err == models.ErrPackageNotExist { ctx.Handle(404, "Package", nil) } else { ctx.Handle(500, "Package", err) } return } ctx.Data["Title"] = importPath ctx.Data["ImportPath"] = importPath ctx.HTML(200, "package") }
func Download(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("download") ctx.Data["PageIsDownload"] = true importPath := archive.GetRootPath(ctx.Query("pkgname")) if ctx.Req.Method == "POST" { rev := ctx.Query("revision") r, err := models.CheckPkg(importPath, rev) if err != nil { ctx.Data["pkgname"] = importPath ctx.Data["revision"] = rev errMsg := err.Error() if err == archive.ErrNotMatchAnyService { ctx.Data["Err_PkgName"] = true errMsg = ctx.Tr("download.err_not_match_service") } else if _, ok := err.(*models.BlockError); ok { errMsg = ctx.Tr("download.err_package_blocked", err.Error()) } ctx.RenderWithErr(errMsg, "download", nil) return } if err = models.IncreasePackageDownloadCount(importPath); err != nil { ctx.Handle(500, "IncreasePackageDownloadCount", err) return } else if err = models.AddDownloader(ctx.RemoteAddr()); err != nil { ctx.Handle(500, "AddDownloader", err) return } ext := archive.GetExtension(importPath) serveName := path.Base(importPath) + "-" + base.ShortSha(r.Revision) + ext switch r.Storage { case models.LOCAL: ctx.ServeFile(path.Join(setting.ArchivePath, importPath, r.Revision+ext), serveName) case models.QINIU: ctx.Redirect("http://" + setting.BucketUrl + "/" + importPath + "-" + r.Revision + ext) } return } ctx.Data["pkgname"] = importPath ctx.HTML(200, "download") }
func BlockPackage(ctx *middleware.Context) { ctx.Data["PageIsBlocks"] = true ctx.Data["PageIsBlocksList"] = true ctx.HTML(200, "blocks/new") }
func NewBlockRule(ctx *middleware.Context) { ctx.Data["PageIsBlocks"] = true ctx.Data["PageIsBlocksRules"] = true ctx.HTML(200, "blocks/rules_new") }
func Dashboard(ctx *middleware.Context) { ctx.Data["PageIsDashboard"] = true ctx.HTML(200, "dashboard") }
func About(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Locale.Tr("about_lower") ctx.Data["PageIsAbout"] = true ctx.HTML(200, "about") }
func Home(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("app_title") ctx.Data["PageIsHome"] = true ctx.Data["Stats"] = models.Statistic ctx.HTML(200, "home") }
func Revisions(ctx *middleware.Context) { ctx.Data["PageIsPackages"] = true ctx.Data["PageIsPackagesList"] = true ctx.HTML(200, "packages/list") }