实现基础的实名认证功能(商业版本专有,开源版本只显示认证状态)

This commit is contained in:
GoEdgeLab
2022-07-24 09:57:26 +08:00
parent 8e5019d8d2
commit 687e667070
8 changed files with 163 additions and 5 deletions

View File

@@ -0,0 +1,62 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package files
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/types"
"mime"
"path/filepath"
)
type FileAction struct {
actionutils.ParentAction
}
func (this *FileAction) Init() {
this.Nav("", "", "")
}
func (this *FileAction) RunGet(params struct {
FileId int64
}) {
fileResp, err := this.RPC().FileRPC().FindEnabledFile(this.AdminContext(), &pb.FindEnabledFileRequest{FileId: params.FileId})
if err != nil {
this.ErrorPage(err)
return
}
var file = fileResp.File
if file == nil {
this.NotFound("File", params.FileId)
return
}
chunkIdsResp, err := this.RPC().FileChunkRPC().FindAllFileChunkIds(this.AdminContext(), &pb.FindAllFileChunkIdsRequest{FileId: file.Id})
if err != nil {
this.ErrorPage(err)
return
}
this.AddHeader("Content-Length", types.String(file.Size))
if len(file.MimeType) > 0 {
this.AddHeader("Content-Type", file.MimeType)
} else if len(file.Filename) > 0 {
var ext = filepath.Ext(file.Filename)
var mimeType = mime.TypeByExtension(ext)
this.AddHeader("Content-Type", mimeType)
}
for _, chunkId := range chunkIdsResp.FileChunkIds {
chunkResp, err := this.RPC().FileChunkRPC().DownloadFileChunk(this.AdminContext(), &pb.DownloadFileChunkRequest{FileChunkId: chunkId})
if err != nil {
this.ErrorPage(err)
return
}
if chunkResp.FileChunk == nil {
continue
}
this.Write(chunkResp.FileChunk.Data)
}
}

View File

@@ -0,0 +1,14 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package files
import "github.com/iwind/TeaGo"
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Prefix("/files").
Get("/file", new(FileAction)).
EndAll()
})
}