mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-10 01:10:29 +08:00
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
|
|
package iplibrary
|
||
|
|
|
||
|
|
import (
|
||
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||
|
|
)
|
||
|
|
|
||
|
|
type DownloadAction struct {
|
||
|
|
actionutils.ParentAction
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *DownloadAction) Init() {
|
||
|
|
this.Nav("", "", "")
|
||
|
|
}
|
||
|
|
|
||
|
|
func (this *DownloadAction) RunGet(params struct {
|
||
|
|
LibraryId int64
|
||
|
|
}) {
|
||
|
|
libraryResp, err := this.RPC().IPLibraryRPC().FindEnabledIPLibrary(this.AdminContext(), &pb.FindEnabledIPLibraryRequest{IpLibraryId: params.LibraryId})
|
||
|
|
if err != nil {
|
||
|
|
this.ErrorPage(err)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if libraryResp.IpLibrary == nil || libraryResp.IpLibrary.File == nil {
|
||
|
|
this.NotFound("ipLibrary", params.LibraryId)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
file := libraryResp.IpLibrary.File
|
||
|
|
chunkIdsResp, err := this.RPC().FileChunkRPC().FindAllFileChunkIds(this.AdminContext(), &pb.FindAllFileChunkIdsRequest{FileId: file.Id})
|
||
|
|
if err != nil {
|
||
|
|
this.ErrorPage(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
this.AddHeader("Content-Disposition", "attachment; filename=\""+file.Filename+"\";")
|
||
|
|
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 {
|
||
|
|
this.Write(chunkResp.FileChunk.Data)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|