Przeglądaj źródła

wip:上传附件 格式调整

wangshan 1 rok temu
rodzic
commit
af408eecc6

+ 2 - 0
rpc/etc/filesystem.yaml

@@ -18,3 +18,5 @@ FileSystemConf:
 #redis
 RedisAddress: "jyfs=192.168.3.149:1712"
 FileSize: 41943040
+ContentType:
+  txt: utf-8

+ 5 - 6
rpc/filesystem.go

@@ -20,18 +20,17 @@ var configFile = flag.String("f", "etc/filesystem.yaml", "the config file")
 func main() {
 	flag.Parse()
 
-	var c config.Config
-	conf.MustLoad(*configFile, &c)
-	ctx := svc.NewServiceContext(c)
+	conf.MustLoad(*configFile, &config.Cf)
+	ctx := svc.NewServiceContext(config.Cf)
 	srv := server.NewFileSystemServer(ctx)
-	size := c.FileSize
-	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
+	size := config.Cf.FileSize
+	s := zrpc.MustNewServer(config.Cf.RpcServerConf, func(grpcServer *grpc.Server) {
 		filesystem.RegisterFileSystemServer(grpcServer, srv)
 	})
 	s.AddOptions(grpc.MaxRecvMsgSize(size))
 	s.AddOptions(grpc.MaxSendMsgSize(size))
 	defer s.Stop()
 
-	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
+	fmt.Printf("Starting rpc server at %s...\n", config.Cf.ListenOn)
 	s.Start()
 }

+ 5 - 0
rpc/internal/config/config.go

@@ -10,4 +10,9 @@ type Config struct {
 	FileSystemConf     zrpc.RpcClientConf
 	RedisAddress       string
 	FileSize           int
+	ContentType        map[string]string
 }
+
+var (
+	Cf Config
+)

+ 8 - 0
rpc/internal/logic/savefilelogic.go

@@ -1,9 +1,11 @@
 package logic
 
 import (
+	"app.yhyue.com/moapp/jyfs/rpc/internal/config"
 	"compress/gzip"
 	"context"
 	"errors"
+	"fmt"
 	"io/ioutil"
 	"strings"
 
@@ -57,6 +59,12 @@ func (l *SaveFileLogic) SaveFile(in *filesystem.SaveFileReq) (*filesystem.FileOp
 		// oss.ObjectACL(oss.ACLPublicRead),
 		// oss.Meta("MyProp", "MyPropVal"),
 	}
+	if fs := strings.Split(in.FileId, "."); len(fs) > 1 {
+		suffix := fs[1]
+		if charset := config.Cf.ContentType[suffix]; charset != "" {
+			options = append(options, oss.ContentType(fmt.Sprintf("text/plain; charset=%s", charset)))
+		}
+	}
 	for k, v := range in.Meta {
 		options = append(options, oss.Meta(k, v))
 	}