@@ -2,7 +2,6 @@ package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
"image/color"
|
||||
_ "image/jpeg"
|
||||
@@ -21,7 +20,7 @@ func loadBaseImage(c *Context, id string) {
|
||||
infile, err := os.Open(path.Join("savedData", id, "baseimage.png"))
|
||||
if err != nil {
|
||||
c.Logger.Errorf("Failed to read image for model with id %s\n", id)
|
||||
c.Logger.Error(err)
|
||||
c.Logger.Error(err)
|
||||
ModelUpdateStatus(c, id, FAILED_PREPARING)
|
||||
return
|
||||
}
|
||||
@@ -30,7 +29,7 @@ func loadBaseImage(c *Context, id string) {
|
||||
src, format, err := image.Decode(infile)
|
||||
if err != nil {
|
||||
c.Logger.Errorf("Failed to decode image for model with id %s\n", id)
|
||||
c.Logger.Error(err)
|
||||
c.Logger.Error(err)
|
||||
ModelUpdateStatus(c, id, FAILED_PREPARING)
|
||||
return
|
||||
}
|
||||
@@ -38,8 +37,8 @@ func loadBaseImage(c *Context, id string) {
|
||||
case "png":
|
||||
case "jpeg":
|
||||
default:
|
||||
// TODO better logging
|
||||
fmt.Printf("Found unkown format '%s'\n", format)
|
||||
ModelUpdateStatus(c, id, FAILED_PREPARING)
|
||||
c.Logger.Error("Found unkown format '%s'\n", "format", format)
|
||||
panic("Handle diferent files than .png")
|
||||
}
|
||||
|
||||
@@ -53,24 +52,26 @@ func loadBaseImage(c *Context, id string) {
|
||||
fallthrough
|
||||
case color.GrayModel:
|
||||
model_color = "greyscale"
|
||||
case color.NRGBAModel:
|
||||
fallthrough
|
||||
case color.YCbCrModel:
|
||||
model_color = "rgb"
|
||||
default:
|
||||
fmt.Println("Do not know how to handle this color model")
|
||||
c.Logger.Error("Do not know how to handle this color model")
|
||||
|
||||
if src.ColorModel() == color.RGBA64Model {
|
||||
fmt.Println("Color is rgb")
|
||||
} else if src.ColorModel() == color.NRGBAModel {
|
||||
fmt.Println("Color is nrgb")
|
||||
c.Logger.Error("Color is rgb")
|
||||
} else if src.ColorModel() == color.NRGBA64Model {
|
||||
c.Logger.Error("Color is nrgb 64")
|
||||
} else if src.ColorModel() == color.AlphaModel {
|
||||
fmt.Println("Color is alpha")
|
||||
c.Logger.Error("Color is alpha")
|
||||
} else if src.ColorModel() == color.CMYKModel {
|
||||
fmt.Println("Color is cmyk")
|
||||
c.Logger.Error("Color is cmyk")
|
||||
} else {
|
||||
fmt.Println("Other so assuming color")
|
||||
c.Logger.Error("Other so assuming color")
|
||||
}
|
||||
|
||||
ModelUpdateStatus(c, id, -1)
|
||||
ModelUpdateStatus(c, id, FAILED_PREPARING)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ func handleAdd(handle *Handle) {
|
||||
return nil
|
||||
}
|
||||
if c.Mode == JSON {
|
||||
// TODO json
|
||||
// TODO json
|
||||
panic("TODO JSON")
|
||||
}
|
||||
|
||||
@@ -130,7 +131,7 @@ func handleAdd(handle *Handle) {
|
||||
|
||||
row, err := handle.Db.Query("select id from models where name=$1 and user_id=$2;", name, c.User.Id)
|
||||
if err != nil {
|
||||
return Error500(err)
|
||||
return c.Error500(err)
|
||||
}
|
||||
|
||||
if row.Next() {
|
||||
@@ -143,12 +144,12 @@ func handleAdd(handle *Handle) {
|
||||
|
||||
_, err = handle.Db.Exec("insert into models (user_id, name) values ($1, $2)", c.User.Id, name)
|
||||
if err != nil {
|
||||
return Error500(err)
|
||||
return c.Error500(err)
|
||||
}
|
||||
|
||||
row, err = handle.Db.Query("select id from models where name=$1 and user_id=$2;", name, c.User.Id)
|
||||
if err != nil {
|
||||
return Error500(err)
|
||||
return c.Error500(err)
|
||||
}
|
||||
|
||||
if !row.Next() {
|
||||
@@ -158,7 +159,7 @@ func handleAdd(handle *Handle) {
|
||||
var id string
|
||||
err = row.Scan(&id)
|
||||
if err != nil {
|
||||
return Error500(err)
|
||||
return c.Error500(err)
|
||||
}
|
||||
|
||||
// TODO mk this path configurable
|
||||
@@ -166,17 +167,17 @@ func handleAdd(handle *Handle) {
|
||||
|
||||
err = os.Mkdir(dir_path, os.ModePerm)
|
||||
if err != nil {
|
||||
return Error500(err)
|
||||
return c.Error500(err)
|
||||
}
|
||||
f, err := os.Create(path.Join(dir_path, "baseimage.png"))
|
||||
if err != nil {
|
||||
return Error500(err)
|
||||
return c.Error500(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
f.Write(file)
|
||||
|
||||
fmt.Printf("Created model with id %s! Started to proccess image!\n", id)
|
||||
c.Logger.Warn("Created model with id %s! Started to proccess image!\n", "id", id)
|
||||
go loadBaseImage(c, id)
|
||||
|
||||
Redirect("/models/edit?id="+id, c.Mode, w, r)
|
||||
|
||||
Reference in New Issue
Block a user