Example #1
0
func Auth(ctx *middleware.Context) {
	if len(setting.AccessToken) == 0 ||
		ctx.GetCookie("access_token") != setting.AccessToken {
		ctx.Data["PageIsAuth"] = true
		ctx.HTML(200, "auth")
	}
}
Example #2
0
func LargeRevisions(ctx *middleware.Context) {
	ctx.Data["PageIsPackages"] = true
	ctx.Data["PageIsPackagesLarges"] = true

	models.GetLocalRevisions()

	ctx.HTML(200, "packages/larges")
}
Example #3
0
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")
}
Example #4
0
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")
}
Example #5
0
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")
}
Example #6
0
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")
}
Example #7
0
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")
}
Example #8
0
func BlockPackage(ctx *middleware.Context) {
	ctx.Data["PageIsBlocks"] = true
	ctx.Data["PageIsBlocksList"] = true
	ctx.HTML(200, "blocks/new")
}
Example #9
0
func NewBlockRule(ctx *middleware.Context) {
	ctx.Data["PageIsBlocks"] = true
	ctx.Data["PageIsBlocksRules"] = true
	ctx.HTML(200, "blocks/rules_new")
}
Example #10
0
func Dashboard(ctx *middleware.Context) {
	ctx.Data["PageIsDashboard"] = true
	ctx.HTML(200, "dashboard")
}
Example #11
0
func About(ctx *middleware.Context) {
	ctx.Data["Title"] = ctx.Locale.Tr("about_lower")
	ctx.Data["PageIsAbout"] = true
	ctx.HTML(200, "about")
}
Example #12
0
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")
}
Example #13
0
func Revisions(ctx *middleware.Context) {
	ctx.Data["PageIsPackages"] = true
	ctx.Data["PageIsPackagesList"] = true
	ctx.HTML(200, "packages/list")
}