Skip to content

Commit

Permalink
dev: finished mount_all_ser_storage
Browse files Browse the repository at this point in the history
  • Loading branch information
peacewang017 committed Jan 23, 2025
1 parent a1a9800 commit cc7b943
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion 3.upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
os.system("rclone copy -P dist remote:/teledeploy/bin_telego/ --exclude telego_linux_amd64 --exclude telego_linux_arm64")
exit(0)
if sys.argv[1]=="onlylinuxamd":
print("upload onlylinux")
print("upload onlylinuxamd")
os.system("rclone copy -P dist remote:/teledeploy/bin_telego/ --exclude telego_windows_amd64.exe --exclude telego_linux_arm64")
exit(0)

Expand Down
9 changes: 5 additions & 4 deletions app/job_mount_all_user_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ func (m ModJobMountAllUserStorageStruct) getLocalRootStorage() (string, error) {
// // 检查是否是文件
info, err := os.Stat(localRootStorage)
if err != nil {
return "", fmt.Errorf("ModJobMountAllUserStorageStruct.getLocalRootStorage: Error opening %s\n", localRootStorage)
return "", fmt.Errorf("ModJobMountAllUserStorageStruct.getLocalRootStorage: Error opening %s", localRootStorage)
}

if !info.IsDir() {
return "", fmt.Errorf("ModJobMountAllUserStorageStruct.getLocalRootStorage: %s is a file, not a directory\n", localRootStorage)
return "", fmt.Errorf("ModJobMountAllUserStorageStruct.getLocalRootStorage: %s is a file, not a directory", localRootStorage)
}

files, err := os.ReadDir(localRootStorage)
Expand Down Expand Up @@ -178,14 +178,15 @@ func (m ModJobMountAllUserStorageStruct) Run() {

// 执行请求,拿到 AllUserStorageLink
serverUrl, err := (util.MainNodeConfReader{}).ReadPubConf(util.PubConfMountAllUserStorageServerUrl{})
serverUrl = strings.TrimSpace(serverUrl)
if err != nil {
fmt.Printf("ModJobMountAllUserStorageStruct.Run: Get server ip error")
return
}
client := &http.Client{Timeout: 60 * time.Second} // 设置 60 秒超时
httpResp, err := client.Post(path.Join(serverUrl, "/mount_all_user_storage_server_url"), "application/json", bytes.NewBuffer(reqBody))
httpResp, err := client.Post(util.UrlJoin(serverUrl, "/mount_all_user_storage_server_url"), "application/json", bytes.NewBuffer(reqBody))
if err != nil {
fmt.Printf("ModJobMountAllUserStorageStruct.Run: Error getting response")
fmt.Printf("ModJobMountAllUserStorageStruct.Run: Error getting response (server_url: %s, fullUrl: %s)", serverUrl, util.UrlJoin(serverUrl, "/mount_all_user_storage_server_url"))
return
}
defer httpResp.Body.Close()
Expand Down
42 changes: 36 additions & 6 deletions app/job_mount_all_user_storage_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package app
import (
"fmt"
"net/http"
"strings"
"telego/util"
"telego/util/gemini"
"telego/util/storage_interface"
Expand Down Expand Up @@ -35,6 +36,22 @@ func (m ModJobMountAllUserStorageServerStruct) getSftpServerByType(SecretConfTyp
return
}

func (m ModJobMountAllUserStorageServerStruct) printfUserStorageSets(userStorageSets []util.UserOneStorageSet) string {
var builder strings.Builder

builder.WriteString("\n--------------------------------------------------\n")
for idx, userStorage := range userStorageSets {
builder.WriteString(fmt.Sprintf("Storage-%d\n", idx))
builder.WriteString(fmt.Sprintf("type: %s, root-storage: %s\n", userStorage.Type, userStorage.RootStorage))
for idx1, subPath := range userStorage.SubPaths {
builder.WriteString(fmt.Sprintf("subpath-%d: %s\n", idx1, subPath))
}
}
builder.WriteString("\n--------------------------------------------------\n")

return builder.String()
}

func (m ModJobMountAllUserStorageServerStruct) doSftp(userStorageSets []util.UserOneStorageSet, username, password string) ([]util.UserMountsInfo, error) {
SecretConfTypeStorageViewYaml := util.SecretConfTypeStorageViewYaml{}
SecretConfTypeStorageViewYamlString, err := (util.MainNodeConfReader{}).ReadSecretConf(util.SecretConfTypeStorageViewYaml{})
Expand All @@ -61,7 +78,7 @@ func (m ModJobMountAllUserStorageServerStruct) doSftp(userStorageSets []util.Use

err = util.ModSftpgo.CreateUserSpace(SecretConfTypeStorageViewYaml, username, password, userMountsInfos)
if err != nil {
return nil, fmt.Errorf("ModJobMountAllUserStorageServerStruct.doSftp: Error CreateUserSpace: %v", err)
return nil, fmt.Errorf("ModJobMountAllUserStorageServerStruct.doSftp: Error CreateUserSpace (userStorageSets: %s): %v", m.printfUserStorageSets(userStorageSets), err)
}
return userMountsInfos, nil
}
Expand All @@ -70,31 +87,44 @@ func (m ModJobMountAllUserStorageServerStruct) handleGetPath(c *gin.Context) {
var req GetAllUserStorageLinkRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"error": fmt.Sprintf("Invalid request payload: %v", err),
"error": fmt.Sprintf("ModJobMountAllUserStorageServerStruct.handleGetPath: Invalid request payload: %v", err),
})
return
}

gBaseUrl, err := (util.MainNodeConfReader{}).ReadSecretConf(util.SecretConfTypeGeminiAPIUrl{})
if err != nil {
fmt.Printf("ModJobGetAllUserStorageLinkServerStruct.handleGetPath: Error reading gemini url")
c.JSON(http.StatusInternalServerError, gin.H{
"error": fmt.Sprintf("ModJobMountAllUserStorageServerStruct.handleGetPath: Error reading gemini url: %v", err),
})
return
}
gBaseUrl = strings.TrimSpace(gBaseUrl)

gServer, err := gemini.NewGeminiServer(gBaseUrl)
if err != nil {
fmt.Printf("ModJobGetAllUserStorageLinkServerStruct.handleGetPath: Error Initialize gemini server")
c.JSON(http.StatusInternalServerError, gin.H{
"error": fmt.Sprintf("ModJobMountAllUserStorageServerStruct.handleGetPath: Error initializing gemini server: %v", err),
})
return
}

// 与 Gemini 交互
userStorageSets, err := storage_interface.GetAllStorageByUser(gServer, req.UserName, req.PassWord)
if err != nil {
fmt.Printf("ModJobMountAllUserStorageServerStruct.handleGetPath: Error GetAllStorageByUser: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{
"error": fmt.Sprintf("ModJobMountAllUserStorageServerStruct.handleGetPath: Error getting all storage by user (username: %s, password: %s): %v", req.UserName, req.PassWord, err),
})
return
}

// 返回集群信息,集群存储根目录列表
userMountInfos, err := m.doSftp(userStorageSets, req.UserName, req.PassWord)
if err != nil {
fmt.Printf("ModJobMountAllUserStorageServerStruct.handleGetPath: Error doSftp: %v", err)
c.JSON(http.StatusInternalServerError, gin.H{
"error": fmt.Sprintf("ModJobMountAllUserStorageServerStruct.handleGetPath: Error performing SFTP operations: %v", err),
})
return
}

// 返回可挂载列表
Expand Down
2 changes: 1 addition & 1 deletion util/gemini/user_auth_passwd_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (req *PasswdLoginRequest) ToHttpRequest(baseURL string) (*http.Request, err

httpReq, err := http.NewRequest("POST", fullURL, bytes.NewBuffer(jsonBody))
if err != nil {
return nil, fmt.Errorf("PasswdLoginRequest.httpRequest: error creating new http request")
return nil, fmt.Errorf("PasswdLoginRequest.httpRequest: error creating new http request (fullURL: %s)", fullURL)
}

// Header
Expand Down
2 changes: 1 addition & 1 deletion util/gemini/web_api_user_joined_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
)

var UserJoinedSpaceEndpoint = "/admin/user/join/list"
var UserJoinedSpaceEndpoint = "/user/space/join/list"

var _ Request = &UserJoinedSpaceRequest{}

Expand Down
1 change: 1 addition & 0 deletions util/main_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func ReadStrFromMainNode(remotePath string) (string, error) {
if err != nil {
return "", err
}
content = strings.TrimSpace(content)
return content, nil
}

Expand Down

0 comments on commit cc7b943

Please sign in to comment.