浏览代码

Added folder opg

Toby Chui 3 年之前
父节点
当前提交
4560ccb423
共有 5 个文件被更改,包括 88 次插入11 次删除
  1. 37 10
      mod/share/share.go
  2. 二进制
      system/share/folder.png
  3. 12 1
      web/img/desktop/system_icon/folder.svg
  4. 27 0
      web/img/system/folder.ai
  5. 12 0
      web/img/system/folder.svg

+ 37 - 10
mod/share/share.go

@@ -70,13 +70,15 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
 	//Load in base template
 	baseTemplate, err := os.Open("./system/share/default_opg.png")
 	if err != nil {
-		fmt.Println(err)
+		fmt.Println("[share/opg] " + err.Error())
+		http.NotFound(w, r)
 		return
 	}
 
 	base, _, err := image.Decode(baseTemplate)
 	if err != nil {
-		fmt.Println(err)
+		fmt.Println("[share/opg] " + err.Error())
+		http.NotFound(w, r)
 		return
 	}
 
@@ -88,13 +90,15 @@ func (s *Manager) HandleOPGServing(w http.ResponseWriter, r *http.Request, share
 	//Append filename to the image
 	fontBytes, err := ioutil.ReadFile("./system/share/fonts/TaipeiSansTCBeta-Light.ttf")
 	if err != nil {
-		fmt.Println(err)
+		fmt.Println("[share/opg] " + err.Error())
+		http.NotFound(w, r)
 		return
 	}
 
 	utf8Font, err := freetype.ParseFont(fontBytes)
 	if err != nil {
-		fmt.Println(err)
+		fmt.Println("[share/opg] " + err.Error())
+		http.NotFound(w, r)
 		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))
 			_, err = ctx.DrawString(line, pt)
 			if err != nil {
-				fmt.Println(err)
+				fmt.Println("[share/opg] " + err.Error())
 				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))
 		_, err = ctx.DrawString(shareMeta, pt)
 		if err != nil {
-			fmt.Println(err)
+			fmt.Println("[share/opg] " + err.Error())
+			http.NotFound(w, r)
 			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))
 		_, err = ctx.DrawString(filenameOnly, pt)
 		if err != nil {
-			fmt.Println(err)
+			fmt.Println("[share/opg] " + err.Error())
+			http.NotFound(w, r)
 			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))
 		_, err = ctx.DrawString(shareMeta, pt)
 		if err != nil {
-			fmt.Println(err)
+			fmt.Println("[share/opg] " + err.Error())
+			http.NotFound(w, r)
 			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
 		thumbnailFile, err := os.Open(cacheFileImagePath)
 		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
 		}
 
 		thumb, _, err := image.Decode(thumbnailFile)
 		if err != nil {
-			fmt.Println(err)
+			fmt.Println("[share/opg] " + err.Error())
+			http.NotFound(w, r)
 			return
 		}
 

二进制
system/share/folder.png


+ 12 - 1
web/img/desktop/system_icon/folder.svg

@@ -1 +1,12 @@
-<svg id="Capa_1" enable-background="new 0 0 470.674 470.674" height="512" viewBox="0 0 470.674 470.674" width="512" xmlns="http://www.w3.org/2000/svg"><g><path d="m398.444 118.266v290.582c.302 5.627-4.014 10.434-9.641 10.736-.006 0-.011.001-.017.001h-379.114c-5.625-.312-9.942-5.11-9.658-10.737v-347.034c-.264-5.62 4.042-10.407 9.658-10.737h119.097c3.411.065 6.519 1.977 8.115 4.993l29.652 51.488h222.251c5.612.312 9.924 5.092 9.657 10.708z" fill="#eab54e"/><path d="m470.018 191.636-68.165 217.16c-1.698 6.211-7.246 10.59-13.681 10.8h-374.541c-5.848-.465-10.212-5.583-9.747-11.431.077-.973.289-1.931.628-2.847l67.551-215.128c2.026-7.373 8.616-12.567 16.258-12.815h372.606c5.847.484 10.194 5.616 9.71 11.463-.079.957-.287 1.898-.619 2.798z" fill="#f6c863"/></g></svg>
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="128px"
+	 height="128px" viewBox="0 0 128 128" enable-background="new 0 0 128 128" xml:space="preserve">
+<g id="圖層_2">
+	<polygon fill="#DBAC50" points="104.03,38.089 104.03,101.074 22.388,101.074 22.388,27.94 49.702,27.75 55.666,38.345 	"/>
+</g>
+<g id="圖層_3">
+	<polygon fill="#E5BD64" points="104.328,101.97 22.836,101.97 38.209,52.716 118.806,52.716 	"/>
+</g>
+</svg>

文件差异内容过多而无法显示
+ 27 - 0
web/img/system/folder.ai


+ 12 - 0
web/img/system/folder.svg

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="128px"
+	 height="128px" viewBox="0 0 128 128" enable-background="new 0 0 128 128" xml:space="preserve">
+<g id="圖層_2">
+	<polygon fill="#DBAC50" points="104.03,38.089 104.03,101.074 22.388,101.074 22.388,27.94 49.702,27.75 55.666,38.345 	"/>
+</g>
+<g id="圖層_3">
+	<polygon fill="#E5BD64" points="104.328,101.97 22.836,101.97 38.209,52.716 118.806,52.716 	"/>
+</g>
+</svg>

部分文件因为文件数量过多而无法显示