当前位置: 首页>>代码示例>>Golang>>正文


Golang Dbh.GetAlbum方法代码示例

本文整理汇总了Golang中pixelrelay/db.Dbh.GetAlbum方法的典型用法代码示例。如果您正苦于以下问题:Golang Dbh.GetAlbum方法的具体用法?Golang Dbh.GetAlbum怎么用?Golang Dbh.GetAlbum使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pixelrelay/db.Dbh的用法示例。


在下文中一共展示了Dbh.GetAlbum方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Verify

func Verify(res http.ResponseWriter, req *http.Request, r render.Render, dbh *db.Dbh) {
	pk := req.FormValue("user_private_key")
	a := req.FormValue("file_album")

	album := dbh.GetAlbum(a)

	if album.Id > 0 && album.Privatekey == pk {
		return
	}

	if pk == "" || pk != utils.ImageCfg.SecretKey() {
		log.Printf("Upload failed: Invalid Private Key (%s)\n", pk)
		r.JSON(http.StatusUnauthorized, Response{"error": http.StatusUnauthorized, "code": "Invalid Private Key", "name": a})
		return
	}

	if a == "" {
		log.Printf("Upload failed: Invalid Album Name (%s)\n", a)
		r.JSON(http.StatusUnauthorized, Response{"error": http.StatusUnauthorized, "code": "Invalid Album Name", "name": a})
		return
	}

	log.Println("verify: good")
	return
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:25,代码来源:verify.go

示例2: ListDB

func ListDB(args martini.Params, su models.User, r render.Render, p *models.Page, dbh *db.Dbh) {

	images := dbh.GetAllImages()

	var album models.Album
	for _, image := range images {
		album = dbh.GetAlbum(image.Album)
		image.AlbumId = album.Id
		nImage := dbh.UpdateImage(image)
		log.Println(nImage)
	}

	return
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:14,代码来源:listdb.go

示例3: QR

func QR(args martini.Params, su models.User, dbh *db.Dbh, session sessions.Session, r render.Render, res http.ResponseWriter, req *http.Request) {
	name := args["name"]

	album := dbh.GetAlbum(name)

	key := album.Privatekey
	private := album.Private

	if private && su.Id != album.User || album.Id == 0 {
		session.Set("flash", "Login Required")
		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "login"}, "/"), http.StatusFound)
		return
	}

	log.Printf("name: %s key: %s private: %t\n", name, key, private)

	file := createQR(name, key)

	dir := http.Dir(utils.ImageCfg.QR())
	f, err := dir.Open(file)
	if err != nil {
		// discard the error?
		return
	}
	defer f.Close()

	fi, err := f.Stat()
	if err != nil {
		return
	}

	res.Header().Set("X-Content-Type-Options", "nosniff")
	res.Header().Set("Expires", utils.ExpiresHeader())
	res.Header().Add("Content-Type", "image/png")
	http.ServeContent(res, req, file, fi.ModTime(), f)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:36,代码来源:qr.go

示例4: UploadImage

func UploadImage(w http.ResponseWriter, upload models.ImageUpload, req *http.Request, r render.Render, dbh *db.Dbh) {
	ur := &models.UploadResult{}

	rEmail := upload.Email
	rAlbum := upload.Album
	rPrivateKey := upload.PrivateKey

	fiName := upload.File.Filename

	upload_time := time.Now().Unix()

	ur.SetCode(200)
	ur.SetResult("success")
	ur.SetName(fiName)

	tmp_file := utils.ImageCfg.Root() + ur.GetName()

	if Exists(tmp_file) {
		log.Println("Error: File exists. (" + tmp_file + ")")
		ur.SetCode(2)
		ur.SetResult("File exists")
		r.JSON(500, ur)
		return
	}

	out, err := os.Create(tmp_file)
	if err != nil {
		log.Println("Error: Unable to open file.")
		ur.SetCode(500)
		ur.SetResult("Failed to open the file for writing.")
		r.JSON(500, ur)
		return
	}
	defer out.Close()

	fi, err := upload.File.Open()
	if err != nil {
		log.Println("fi err: ", err)
		ur.SetCode(500)
		ur.SetResult(err.Error())
		r.JSON(500, ur)
		return
	}
	defer fi.Close()

	_, err = io.Copy(out, fi)
	if err != nil {
		log.Println("Error: Failed to copy file.")
		ur.SetCode(500)
		ur.SetResult("Failed to copy file to new location.")
		r.JSON(500, ur)
		return
	}

	log.Printf("tmp_file: %s\n", tmp_file)

	// Add image uploader to database
	dbh.AddUploader(models.Uploader{Email: rEmail, Timestamp: upload_time})

	// Setup hashid to create unique file name
	var hid models.HashID
	hid.Init(utils.AppCfg.SecretKey(), 10)

	// Get user id
	user := dbh.GetUserByEmail(rEmail)
	log.Println("user: ", user.Id)
	if user.Id > 0 {
		// Add user id to hashid - seg 1
		hid.AddId(int(user.Id))
	} else {
		hid.AddId(0)
	}

	// Get uploader id
	user2 := dbh.GetUploaderByEmail(rEmail)
	log.Println("uploader user: ", user2.Id)
	if user2.Id > 0 {
		// Add uploader id to hashid - seg 2
		hid.AddId(int(user2.Id))
	} else {
		hid.AddId(0)
	}

	// Create default album description
	album := models.Album{
		Name:       rAlbum,
		User:       user.Id,
		Privatekey: rPrivateKey,
		Private:    true,
		Timestamp:  upload_time}
	album.DefaultDescription()
	log.Println(album)

	// Add album
	dbh.AddAlbum(album)

	log.Println("album: ", album)

	nAlbum := dbh.GetAlbum(rAlbum)

//.........这里部分代码省略.........
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:101,代码来源:upload.go


注:本文中的pixelrelay/db.Dbh.GetAlbum方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。