Skip to content

BillionMail gives you open-source MailServer, NewsLetter, Email Marketing — fully self-hosted, dev-friendly, and free from monthly fees. Join the discord: https://discord.gg/asfXzBUhZr

Read the content of the specified file.

lotkf477fa4dae47
diff --git a/core/api/files/files.go b/core/api/files/files.go
index aca0df0c..811c8d9d 100644
--- a/core/api/files/files.go
+++ b/core/api/files/files.go
@@ -12,4 +12,5 @@ import (
type IFilesV1 interface {
DownloadFile(ctx context.Context, req *v1.DownloadFileReq) (res *v1.DownloadFileRes, err error)
+ ReadFile(ctx context.Context, req *v1.ReadFileReq) (res *v1.ReadFileRes, err error)
}
diff --git a/core/api/files/v1/files.go b/core/api/files/v1/files.go
index 83204cf2..6ffe6509 100644
--- a/core/api/files/v1/files.go
+++ b/core/api/files/v1/files.go
@@ -5,30 +5,6 @@ import (
"github.com/gogf/gf/v2/frame/g"
)
-//// UploadFileReq File upload request
-//type UploadFileReq struct {
-// g.Meta `path:"/file/upload" method:"post" tags:"Files" summary:"Upload file with support for chunked upload and base64 data"`
-// Authorization string `json:"authorization" dc:"Authorization" in:"header" v:"required"`
-// FName string `json:"f_name" v:"required" dc:"File name, no special characters allowed, max length 256 bytes"`
-// FPath string `json:"f_path" v:"required" dc:"File save path, root path '/' and './' not allowed"`
-// FSize int64 `json:"f_size" v:"required" dc:"Total file size in bytes"`
-// FStart int64 `json:"f_start" dc:"Start position for resumable upload in bytes, used for validation"`
-// B64Data string `json:"b64_data" dc:"Base64 encoded file content, mutually exclusive with blob parameter"`
-// Blob *ghttp.UploadFile `json:"blob" dc:"File content, mutually exclusive with b64_data parameter"`
-// DirMode string `json:"dir_mode" dc:"Directory permission mode, e.g.: '0755'"`
-// FileMode string `json:"file_mode" dc:"File permission mode, e.g.: '0644'"`
-//}
-//
-//// UploadFileRes File upload response
-//type UploadFileRes struct {
-// api_v1.StandardRes
-// Data struct {
-// FileId string `json:"file_id" dc:"Unique file identifier"`
-// UploadSize int64 `json:"upload_size" dc:"Number of bytes uploaded"`
-// FileUrl string `json:"file_url" dc:"File access URL"`
-// } `json:"data"`
-//}
-
// DownloadFileReq File download request
type DownloadFileReq struct {
g.Meta `path:"/file/download" method:"get" tags:"Files" summary:"Download file by path"`
@@ -40,3 +16,14 @@ type DownloadFileReq struct {
type DownloadFileRes struct {
api_v1.StandardRes
}
+
+type ReadFileReq struct {
+ g.Meta `path:"/file/read" method:"get" tags:"Files" summary:"Read file by path"`
+ Authorization string `json:"authorization" dc:"Authorization" in:"header" v:"required"`
+ FilePath string `json:"file_path" v:"required" dc:"File path for read"`
+}
+
+// ReadFileRes File read response
+type ReadFileRes struct {
+ api_v1.StandardRes
+}
diff --git a/core/internal/controller/files/files_v1_read_file.go b/core/internal/controller/files/files_v1_read_file.go
new file mode 100644
index 00000000..ff79150b
--- /dev/null
+++ b/core/internal/controller/files/files_v1_read_file.go
@@ -0,0 +1,32 @@
+package files
+
+import (
+ "billionmail-core/internal/service/public"
+ "context"
+ "github.com/gogf/gf/v2/errors/gerror"
+
+ "github.com/gogf/gf/os/gfile"
+
+ "billionmail-core/api/files/v1"
+)
+
+func (c *ControllerV1) ReadFile(ctx context.Context, req *v1.ReadFileReq) (res *v1.ReadFileRes, err error) {
+ res = &v1.ReadFileRes{}
+
+ exists1 := public.FileExists(req.FilePath)
+ if !exists1 {
+ res.Data = ""
+ res.SetSuccess(public.LangCtx(ctx, "Success"))
+ return
+ }
+
+ content := gfile.GetContents(req.FilePath)
+ if err != nil {
+ res.SetError(gerror.New(public.LangCtx(ctx, "Failed to read file: {}", err.Error())))
+ return res, nil
+ }
+
+ res.Data = content
+ res.SetSuccess(public.LangCtx(ctx, "Success"))
+ return res, nil
+}