diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4164c3a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: Check TeleYard + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: "1.22" # 设置 Go 版本为 1.22 + + - name: Install dependencies + run: | + go mod tidy # 更新并安装所有依赖 + + - name: Run tests + run: | + go test ./... -v # 运行所有测试 diff --git a/app/job_filepath_server.go b/app/job_filepath_server.go deleted file mode 100644 index 015b10d..0000000 --- a/app/job_filepath_server.go +++ /dev/null @@ -1,53 +0,0 @@ -package app - -// - -import ( - "encoding/json" - "fmt" - "net/http" - - "github.com/spf13/cobra" -) - -type ModJobFilePathServerStruct struct{} - -var ModJobFilePathServer ModJobFilePathServerStruct - -func (m ModJobFilePathServerStruct) JobCmdName() string { - return "filepath-server" -} - -func (m ModJobFilePathServerStruct) handleGetPath(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - http.Error(w, "Invalid Request Method", http.StatusMethodNotAllowed) - fmt.Println("handleGetPath: Invalid Request Method") - return - } - - var req PathRequest - if err := json.NewDecoder(r.Body).Decode(&req); err != nil { - http.Error(w, "Failed to parse request", http.StatusBadRequest) - fmt.Println("handleGetPath: Failed to Parse Request") - return - } - - // Gemini 交互,鉴权 - -} - -func (m ModJobFilePathServerStruct) listenRequest() { - http.HandleFunc("/getpath", m.handleGetPath) -} - -func (m ModJobFilePathServerStruct) Run() { - go listenRequest() - -} - -func (m ModJobFilePathServerStruct) ParseJob(filePathServerCmd *cobra.Command) *cobra.Command { - filePathServerCmd.Run = func(_ *cobra.Command, _ []string) { - m.Run() - } - return filePathServerCmd -} diff --git a/app/job_get_all_user_storage_link_server.go b/app/job_get_all_user_storage_link_server.go new file mode 100644 index 0000000..becee3c --- /dev/null +++ b/app/job_get_all_user_storage_link_server.go @@ -0,0 +1,53 @@ +package app + +// 本模块为一个 + +import ( + "fmt" + + "github.com/gin-gonic/gin" + "github.com/spf13/cobra" +) + +type ModJobGetAllUserStorageLinkServerStruct struct{} + +var ModJobGetAllUserStorageLinkServer ModJobGetAllUserStorageLinkServerStruct + +func (m ModJobGetAllUserStorageLinkServerStruct) JobCmdName() string { + return "get-all-user-storage-server" +} + +func (m ModJobGetAllUserStorageLinkServerStruct) handleGetPath(c *gin.Context) { + userName := c.DefaultQuery("username", "") + if userName == "" { + c.JSON(400, gin.H{ + "error": "username is required", + }) + return + } + + // 处理 + + // 未完成 + c.JSON(200, GetAllUserStorageLinkResponse{ + RemoteLinks: []string{"path1", "path2", "path3"}, + }) +} + +func (m ModJobGetAllUserStorageLinkServerStruct) listenRequest(port int) { + r := gin.Default() + r.GET("/getalluserstoragelink", m.handleGetPath) + r.Run(fmt.Sprintf(":%d", port)) +} + +func (m ModJobGetAllUserStorageLinkServerStruct) Run() { + go m.listenRequest(8083) +} + +func (m ModJobGetAllUserStorageLinkServerStruct) ParseJob(getAllUserStorageLinkServerCmd *cobra.Command) *cobra.Command { + getAllUserStorageLinkServerCmd.Run = func(_ *cobra.Command, _ []string) { + m.Run() + } + + return getAllUserStorageLinkServerCmd +} diff --git a/app/job_mount_all_user_storage.go b/app/job_mount_all_user_storage.go index 41c2e53..12bebb1 100644 --- a/app/job_mount_all_user_storage.go +++ b/app/job_mount_all_user_storage.go @@ -1,11 +1,6 @@ package app import ( - "fmt" - "os" - "telego/util" - - "github.com/fatih/color" "github.com/spf13/cobra" ) @@ -17,37 +12,20 @@ func (m ModJobMountAllUserStorageStruct) JobCmdName() string { return "mount-all-user-storage" } -type PathRequest struct { - UserName string - PassWord string +// 请求结构体 +type GetAllUserStorageLinkRequest struct { + UserName string `json:"username"` // Telego 用户名 } -type PathResponse struct { - RemotePaths []string `json: "remote_paths"` +// 返回结构体 +type GetAllUserStorageLinkResponse struct { + RemoteLinks []string `json:"remote_links"` // 供 SshFs 进行挂载的远程链接 } func (m ModJobMountAllUserStorageStruct) Run() { - ok, userName := util.StartTemporaryInputUI( - color.GreenString("Mount 用户存储空间需要鉴权,userName"), - "输入 userName", - "回车确认,ctrl + c 取消", - ) - if !ok { - fmt.Println("User caceled input") - os.Exit(1) - } + // 填入 GetAllUserStorageLinkRequest - ok, passWord := util.StartTemporaryInputUI( - color.GreenString("Mount 用户存储空间需要鉴权,passWord"), - "输入 passWord", - "回车确认,ctrl + c 取消", - ) - if !ok { - fmt.Println("User caceled input") - os.Exit(1) - } - - // 进行 http 请求 server + // 进行 http Get 请求 // 接收结果,调用 ssh / rclone 进行挂载 } @@ -56,6 +34,5 @@ func (m ModJobMountAllUserStorageStruct) ParseJob(mountAllUserStorageCmd *cobra. mountAllUserStorageCmd.Run = func(_ *cobra.Command, _ []string) { m.Run() } - return mountAllUserStorageCmd } diff --git a/app/joblist.go b/app/joblist.go index a0082b0..18d7b0a 100644 --- a/app/joblist.go +++ b/app/joblist.go @@ -17,5 +17,5 @@ var jobmods = []JobModInterface{ ModJobApplyDist, ModJobInfraExporterSingle, ModJobMountAllUserStorage, - ModJobFilePathServer, + ModJobGetAllUserStorageLinkServer, } diff --git a/app/menu.go b/app/menu.go index 8aba66e..001454b 100644 --- a/app/menu.go +++ b/app/menu.go @@ -46,15 +46,6 @@ var MenuTreeData = `children: name: install comment: "\u6A21\u677F\u9879\u76EE" name: bin_rclone - - children: - - children: [] - comment: "\u6839\u636E\u6A21\u677F\u751F\u6210\u9879\u76EE" - name: generate - - children: [] - comment: "\u76F4\u63A5\u5B89\u88C5\u8BE5\u9879\u76EE" - name: install - comment: "\u6A21\u677F\u9879\u76EE" - name: bin_winfsp - children: - children: [] comment: "\u6839\u636E\u6A21\u677F\u751F\u6210\u9879\u76EE" diff --git a/util/log.go b/util/log.go index 88495ea..9234d1d 100644 --- a/util/log.go +++ b/util/log.go @@ -23,7 +23,11 @@ func LogDir() string { logDir := filepath.Join(WorkspaceDir(), "logs") if !createdLogDir { PrintStep("log", "create log dir") - os.MkdirAll(logDir, 0755) + err := os.MkdirAll(logDir, 0755) + if err != nil || func() bool { _, err = os.Stat(logDir); return err != nil }() { + fmt.Println("LogDir: MkdirAll error") + os.Exit(1) + } createdLogDir = true } return logDir @@ -35,7 +39,7 @@ func SetupFileLog() *os.File { Logger.SetLevel(logrus.DebugLevel) // time stamp curtime := time.Now().Format("2006-01-02-15h04m05s") - file, err := os.OpenFile(path.Join(LogDir(), fmt.Sprintf("%s.log", curtime)), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0666) + file, err := os.OpenFile(path.Join(LogDir(), fmt.Sprintf("%s.log", curtime)), os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0755) if err != nil { fmt.Printf("Error opening log file: %v\n", err) return nil diff --git a/util/storage_interface/interface.go b/util/storage_interface/interface.go new file mode 100644 index 0000000..49b5d30 --- /dev/null +++ b/util/storage_interface/interface.go @@ -0,0 +1,4 @@ +package storage_interface + +type UserStorageInfoGetter interface { +}