本文整理汇总了Golang中pixelrelay/db.Dbh.UpdateImage方法的典型用法代码示例。如果您正苦于以下问题:Golang Dbh.UpdateImage方法的具体用法?Golang Dbh.UpdateImage怎么用?Golang Dbh.UpdateImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pixelrelay/db.Dbh
的用法示例。
在下文中一共展示了Dbh.UpdateImage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: AlbumMove
func AlbumMove(req *http.Request, r render.Render, su models.User, dbh *db.Dbh, p *models.Page) {
// Default status
var status string = "Permission Denied"
var code int = 401
var reader io.Reader = req.Body
b, e := ioutil.ReadAll(reader)
if e != nil {
log.Println(e)
}
var f Data
err := json.Unmarshal(b, &f)
if err != nil {
log.Println(err)
}
log.Println(f)
albumId := f.Md.AlbumId
album := dbh.GetAlbumById(albumId)
log.Println("album: ", albumId)
if album.User == su.Id {
status = "Success"
code = 200
var image models.Image
for _, f := range f.Md.Images {
imageId, err := strconv.ParseInt(f.Id, 10, 10)
if err != nil {
log.Println("invalid image id: ", f.Id)
}
log.Println("Moving: ", f.Name, imageId)
image = dbh.GetImageById(imageId)
if image.User != su.Id {
status = "Permission Denied"
code = 401
continue
}
fromId := image.AlbumId
image.AlbumId = albumId
_ = dbh.UpdateImage(image)
log.Printf("Moved %s from: %d to: %d status: %s code: %d\n", f.Name, fromId, albumId, status, code)
}
}
p.Data = status
encoder.Render("json", code, "", p, r)
}
示例3: ImageTrash
func ImageTrash(args martini.Params, su models.User, dbh *db.Dbh, r render.Render, p *models.Page) {
album := args["album"]
name := args["name"]
// Default status
var status string = "Permission Denied"
var code int = 401
log.Printf("Trashing image: %s from %s", name, album)
image := dbh.FirstImageByName(name)
if su.Id == image.User {
image.Trashed = true
dbh.UpdateImage(image)
status = "Success"
code = 200
}
p.SetUser(su)
p.Data = TrashRecover{Name: name, Album: album, Action: "Trash", Status: status}
encoder.Render("json", code, "", p, r)
}
示例4: UploadImage
//.........这里部分代码省略.........
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)
// Add image
image := dbh.AddImage(models.Image{
Name: fiName,
Album: rAlbum,
User: user.Id,
AlbumId: nAlbum.Id,
Timestamp: upload_time})
// Add image id to hashid - seg 3
hid.AddId(int(image.Id))
// Add upload time to hashid - seg 4
hid.AddId(int(upload_time))
// Get file extension and create new file name
extension := filepath.Ext(fiName)
nname := hid.Encrypt() + extension
log.Printf("New name: %s\n", nname)
image.HashId = nname
dbh.UpdateImage(image)
// Rename file to new name
hash_name := utils.ImageCfg.Root() + nname
os.Rename(tmp_file, hash_name)
ur.SetName(utils.AppCfg.Url() + "/image/" + nname)
// Create Thumb
tname := utils.ImageCfg.Thumbs() + nname
if !Exists(string(tname)) {
okc := make(chan bool, 1)
utils.CreateThumb(okc, hash_name, tname, 150, 150)
<-okc
}
log.Printf("%# v\n", pretty.Formatter(album))
log.Printf("%# v\n", image)
log.Printf("%# v\n", pretty.Formatter(ur))
r.JSON(200, ur)
}