diff options
author | rtz12 <koenig@fagott.pw> | 2015-12-29 19:51:43 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2015-12-29 19:51:43 (UTC) |
commit | 989ab00b731d659aa17d6a626efb899f8e400936 (patch) | |
tree | 8f31f5987a0ee6232b730dfad3fdd4d75f9ce153 /modules/grils/gril.go | |
parent | c2498d562d3e30e4795056058fc3d8a5cec4ec11 (diff) | |
parent | 1354a3a30c1639c1441e79356df12601151630a6 (diff) |
Merge branch 'master' of projekte.fagott.pw:grilist
Diffstat (limited to 'modules/grils/gril.go')
-rw-r--r-- | modules/grils/gril.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/grils/gril.go b/modules/grils/gril.go index c8c6538..89dd7c4 100644 --- a/modules/grils/gril.go +++ b/modules/grils/gril.go | |||
@@ -3,6 +3,7 @@ package grils | |||
3 | import ( | 3 | import ( |
4 | "database/sql" | 4 | "database/sql" |
5 | "fmt" | 5 | "fmt" |
6 | "os" | ||
6 | "strconv" | 7 | "strconv" |
7 | "strings" | 8 | "strings" |
8 | "time" | 9 | "time" |
@@ -39,3 +40,27 @@ func (g *Gril) Slug() string { | |||
39 | g.ID, | 40 | g.ID, |
40 | strings.Replace(g.RomajiName, " ", "", -1)) | 41 | strings.Replace(g.RomajiName, " ", "", -1)) |
41 | } | 42 | } |
43 | |||
44 | func (g *Gril) ImagePath(prioritizeThumbnail bool) string { | ||
45 | var big string | ||
46 | exts := []string{"png", "jpg", "gif", "jpeg"} | ||
47 | for _, ext := range exts { | ||
48 | path := fmt.Sprintf("assets/img/gril/%d/0.%s", g.ID, ext) | ||
49 | if _, err := os.Stat(path); err == nil { | ||
50 | if prioritizeThumbnail { | ||
51 | big = path | ||
52 | } else { | ||
53 | return path | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | |||
58 | for _, ext := range exts { | ||
59 | path := fmt.Sprintf("assets/img/gril/%d/1.%s", g.ID, ext) | ||
60 | if _, err := os.Stat(path); err == nil { | ||
61 | return path | ||
62 | } | ||
63 | } | ||
64 | |||
65 | return big | ||
66 | } | ||