```
feat(config): 添加七牛云配置支持 - 在配置结构体中添加Qiniu字段用于七牛云配置 - 添加七牛云相关配置参数(AccessKey, SecretKey, Bucket, CDN) - 更新配置初始化逻辑以支持七牛云配置项 feat(login): 集成七牛云SDK并实现文件列表获取 - 添加七牛云SDK依赖(github.com/qiniu/go-sdk/v7) - 创建BucketManager用于文件管理操作 - 实
This commit is contained in:
@@ -6,20 +6,35 @@ import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/qiniu/go-sdk/v7/auth/qbox"
|
||||
"github.com/qiniu/go-sdk/v7/storage"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
type ServerService struct {
|
||||
*cool.Service
|
||||
manager *storage.BucketManager
|
||||
bucket string
|
||||
}
|
||||
|
||||
func NewServerService() *ServerService {
|
||||
return &ServerService{
|
||||
&cool.Service{
|
||||
cf := &ServerService{
|
||||
Service: &cool.Service{
|
||||
Model: model.NewServerList(),
|
||||
},
|
||||
}
|
||||
cfg := storage.Config{
|
||||
Zone: &storage.ZoneHuadong,
|
||||
UseHTTPS: true,
|
||||
UseCdnDomains: true,
|
||||
}
|
||||
mac := qbox.NewMac("DzMpomnPxqBHkIcvxTbC-hl_8LjVB0LXZuhCky_u", "bhoxrpG1s7MBmSS2I1k5t9zMpuiderpBDZoIPQKU")
|
||||
cf.bucket = "blazingt"
|
||||
|
||||
cf.manager = storage.NewBucketManager(mac, &cfg)
|
||||
return cf
|
||||
}
|
||||
func (s *ServerService) GetPort() []model.ServerList {
|
||||
var item []model.ServerList
|
||||
@@ -29,6 +44,52 @@ func (s *ServerService) GetPort() []model.ServerList {
|
||||
|
||||
}
|
||||
|
||||
func (s *ServerService) GetFileList() []File {
|
||||
var files []File
|
||||
prefix := "logic"
|
||||
delimiter := "" // 用于分隔目录
|
||||
marker := "" // 初始标记为空
|
||||
for {
|
||||
entries, _, nextMarker, hasNext, err := s.manager.ListFiles(s.bucket, prefix, delimiter, marker, 100)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
// 添加文件到结果列表
|
||||
for _, entry := range entries {
|
||||
files = append(files, File{
|
||||
Name: entry.Key,
|
||||
Size: entry.Fsize,
|
||||
Path: entry.Key,
|
||||
Time: entry.PutTime,
|
||||
})
|
||||
}
|
||||
|
||||
// 如果没有更多文件,结束循环
|
||||
if !hasNext {
|
||||
break
|
||||
}
|
||||
|
||||
// 更新标记,继续下一页
|
||||
marker = nextMarker
|
||||
}
|
||||
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
return files[i].Time > files[j].Time
|
||||
})
|
||||
|
||||
return files
|
||||
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Url string `json:"url"`
|
||||
Size int64 `json:"size"`
|
||||
Modified string `json:"modified"`
|
||||
Time int64 `json:"time"`
|
||||
}
|
||||
|
||||
// RemoteExecuteScript 远程执行脚本并实时显示输出
|
||||
// ip: 服务器IP
|
||||
// sshPort: SSH端口
|
||||
|
||||
Reference in New Issue
Block a user