Ver código fonte

提交分享

wangkaiyue 4 anos atrás
pai
commit
ecc522f9cb

+ 2 - 1
jydocs-back/config.json

@@ -32,5 +32,6 @@
         "127.0.0.1:2379"
       ]
     }
-  }
+  },
+  "shareUrl": "https://web-jydev-wky.jianyu360.cn/swordfish/docs/index/content/%s"
 }

+ 1 - 0
jydocs-back/config/config.go

@@ -17,6 +17,7 @@ type appConfig struct {
 		Points  rpcConfig `json:"points"`  //剑鱼积分rpc接口
 		JyFile  rpcConfig `json:"jyFile"`  //剑鱼文件rpc接口
 	} `json:"rpcServers"` //rpc服务配置
+	ShareUrl string `json:"shareUrl"`
 }
 
 type rpcConfig struct {

+ 1 - 0
jydocs-back/go.mod

@@ -7,5 +7,6 @@ require (
 	app.yhyue.com/moapp/jy_docs v0.0.0-20210319063914-d48d51e0cc46
 	app.yhyue.com/moapp/jybase v0.0.0-20210319015107-fe59d2046cf8
 	app.yhyue.com/moapp/jyfs v0.0.0-20210319011832-6cf539ddc5cd
+	github.com/SKatiyar/qr v0.0.0-20151201054752-25b6bdf44e67
 	github.com/tal-tech/go-zero v1.1.5
 )

+ 1 - 1
jydocs-back/rpc/fileSystemRpc.go

@@ -26,7 +26,7 @@ func init() {
 //获取用户对话pdf文件地址
 func GetFileContext(userId, ossId string) (string, error) {
 	resp, err := jyFilelLib.GetOssUril(context.Background(), &filesystem.LoadFileReq{
-		Domain: config.JyDocsAppConfig.OssAdmin,
+		Domain: config.JyDocsAppConfig.OssBucket.Std,
 		FileId: ossId,
 	})
 	if err != nil {

+ 1 - 0
jydocs-back/servers/a_init.go

@@ -21,6 +21,7 @@ func init() {
 	xweb.RootApp().BasePath = "/jydocs"
 
 	xweb.AddAction(&Ad{})
+	xweb.AddAction(&Share{})
 	xweb.AddAction(&StdDoc{})
 	xweb.AddAction(&UserDoc{})
 }

+ 49 - 0
jydocs-back/servers/share.go

@@ -0,0 +1,49 @@
+package servers
+
+import (
+	. "app.yhyue.com/moapp/jybase/api"
+	"app.yhyue.com/moapp/jybase/common"
+	"app.yhyue.com/moapp/jybase/go-xweb/xweb"
+	"fmt"
+	"github.com/SKatiyar/qr"
+	"jy-docs/config"
+	"log"
+)
+
+type Share struct {
+	*xweb.Action
+	shareUrl xweb.Mapper `xweb:"/share/url"` //地址分享
+	shareImg xweb.Mapper `xweb:"/share/img"` //链接分享
+}
+
+func (share *Share) ShareUrl() {
+	userId := common.ObjToString(share.GetSession("userId"))
+	rData, errMsg := func() (interface{}, error) {
+		docId := share.GetString("docId") //分享地址
+		return map[string]interface{}{
+			"url": getShareUrl(userId, docId),
+		}, nil
+	}()
+	if errMsg != nil {
+		log.Printf("%s Share  err:%s\n", errMsg.Error(), userId)
+	}
+	share.ServeJson(NewResult(rData, errMsg))
+}
+
+func (share *Share) ShareImg() {
+	userId := common.ObjToString(share.GetSession("userId"))
+	docId := share.GetString("docId") //分享地址
+	data := getShareUrl(userId, docId)
+
+	w := share.ResponseWriter
+	w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
+	w.Header().Set("Pragma", "no-cache")
+	w.Header().Set("Expires", "0")
+	w.Header().Set("Content-Type", "image/png")
+	r, _ := qr.Encode(data, qr.M)
+	_, _ = w.Write(r.PNG())
+}
+
+func getShareUrl(userId, docId string) string {
+	return fmt.Sprintf(config.JyDocsAppConfig.ShareUrl+"?userId=%s", docId, userId)
+}