|
@@ -70,13 +70,15 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
//Load in base template
|
|
//Load in base template
|
|
baseTemplate, err := os.Open("./system/share/default_opg.png")
|
|
baseTemplate, err := os.Open("./system/share/default_opg.png")
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
base, _, err := image.Decode(baseTemplate)
|
|
base, _, err := image.Decode(baseTemplate)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -88,13 +90,15 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
//Append filename to the image
|
|
//Append filename to the image
|
|
fontBytes, err := ioutil.ReadFile("./system/share/fonts/TaipeiSansTCBeta-Light.ttf")
|
|
fontBytes, err := ioutil.ReadFile("./system/share/fonts/TaipeiSansTCBeta-Light.ttf")
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
utf8Font, err := freetype.ParseFont(fontBytes)
|
|
utf8Font, err := freetype.ParseFont(fontBytes)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -130,7 +134,7 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
pt := freetype.Pt(100, (j+1)*60+int(ctx.PointToFixed(fontSize)>>6))
|
|
pt := freetype.Pt(100, (j+1)*60+int(ctx.PointToFixed(fontSize)>>6))
|
|
_, err = ctx.DrawString(line, pt)
|
|
_, err = ctx.DrawString(line, pt)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -140,7 +144,8 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
pt := freetype.Pt(100, (len(lines)+1)*60+int(ctx.PointToFixed(fontSize)>>6))
|
|
pt := freetype.Pt(100, (len(lines)+1)*60+int(ctx.PointToFixed(fontSize)>>6))
|
|
_, err = ctx.DrawString(shareMeta, pt)
|
|
_, err = ctx.DrawString(shareMeta, pt)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -149,7 +154,8 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
pt := freetype.Pt(100, 60+int(ctx.PointToFixed(fontSize)>>6))
|
|
pt := freetype.Pt(100, 60+int(ctx.PointToFixed(fontSize)>>6))
|
|
_, err = ctx.DrawString(filenameOnly, pt)
|
|
_, err = ctx.DrawString(filenameOnly, pt)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
@@ -158,7 +164,8 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
pt = freetype.Pt(100, 120+int(ctx.PointToFixed(fontSize)>>6))
|
|
pt = freetype.Pt(100, 120+int(ctx.PointToFixed(fontSize)>>6))
|
|
_, err = ctx.DrawString(shareMeta, pt)
|
|
_, err = ctx.DrawString(shareMeta, pt)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -169,13 +176,33 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
|
|
//We got a thumbnail for this file. Render it as well
|
|
//We got a thumbnail for this file. Render it as well
|
|
thumbnailFile, err := os.Open(cacheFileImagePath)
|
|
thumbnailFile, err := os.Open(cacheFileImagePath)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ thumb, _, err := image.Decode(thumbnailFile)
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ resizedThumb := resize.Resize(250, 0, thumb, resize.Lanczos3)
|
|
|
|
+ draw.Draw(resultopg, resultopg.Bounds(), resizedThumb, image.Point{-(resultopg.Bounds().Dx() - resizedThumb.Bounds().Dx() - 90), -60}, draw.Over)
|
|
|
|
+ } else if isDir(shareEntry.FileRealPath) {
|
|
|
|
+ //Is directory but no thumbnail. Use default foldr share thumbnail
|
|
|
|
+ thumbnailFile, err := os.Open("./system/share/folder.png")
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
thumb, _, err := image.Decode(thumbnailFile)
|
|
thumb, _, err := image.Decode(thumbnailFile)
|
|
if err != nil {
|
|
if err != nil {
|
|
- fmt.Println(err)
|
|
|
|
|
|
+ fmt.Println("[share/opg] " + err.Error())
|
|
|
|
+ http.NotFound(w, r)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|