Files
rustdesk-api/http/controller/admin/file.go
T
thomasandClaude Opus 4.8 16e97c8efa i18n: Translate all Chinese to English across the codebase
Translate Chinese comments, log/error messages, validator labels and
Swagger annotations to English throughout the source code, generated
Swagger docs, config files and CI workflows.

Make the English README primary: README.md now holds the English docs
and README_EN.md holds the Chinese version, with cross-language links
updated accordingly.

Note: the generated docs/ swagger files were translated in place; run
`go generate ./...` (swag init) to regenerate them from the now-English
annotations when a Go toolchain is available.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 12:17:04 +02:00

84 lines
1.9 KiB
Go

package admin
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/lejianwen/rustdesk-api/v2/global"
"github.com/lejianwen/rustdesk-api/v2/http/response"
"github.com/lejianwen/rustdesk-api/v2/lib/upload"
"os"
"time"
)
type File struct {
}
// OssToken file
// @Tags file
// @Summary getossToken
// @Description getossToken
// @Accept json
// @Produce json
// @Success 200 {object} response.Response
// @Failure 500 {object} response.Response
// @Router /admin/file/oss_token [get]
// @Security token
func (f *File) OssToken(c *gin.Context) {
token := global.Oss.GetPolicyToken("")
response.Success(c, token)
}
type FileBack struct {
upload.CallbackBaseForm
Url string `json:"url"`
}
// Notify callback after successful upload
func (f *File) Notify(c *gin.Context) {
res := global.Oss.Verify(c.Request)
if !res {
response.Fail(c, 101, response.TranslateMsg(c, "NoAccess"))
return
}
fm := &FileBack{}
if err := c.ShouldBind(fm); err != nil {
fmt.Println(err)
}
fm.Url = global.Config.Oss.Host + "/" + fm.Filename
response.Success(c, fm)
}
// Upload upload file to local
// @Tags file
// @Summary upload file to local
// @Description upload file to local
// @Accept multipart/form-data
// @Produce json
// @Param file formData file true "file upload example"
// @Success 200 {object} response.Response
// @Failure 500 {object} response.Response
// @Router /admin/file/upload [post]
// @Security token
func (f *File) Upload(c *gin.Context) {
file, _ := c.FormFile("file")
timePath := time.Now().Format("20060102") + "/"
webPath := "/upload/" + timePath
path := global.Config.Gin.ResourcesPath + webPath
dst := path + file.Filename
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
return
}
// upload the file to the specified directory
err = c.SaveUploadedFile(file, dst)
if err != nil {
return
}
// return filewebaddress
response.Success(c, gin.H{
"url": webPath + file.Filename,
})
}