Compare commits

...

5 Commits

Author SHA1 Message Date
ns2kracy
1cb6ef1d3f fix: update response format to HTML for error messages in recovery process 2024-12-16 12:00:31 +08:00
David Wood
5ea588b813 chore: fix problematic comments (#2030)
Some checks failed
Collect Code Coverage / build (push) Has been cancelled
Auto Publish Website / goreleaser (push) Has been cancelled
2024-12-04 11:04:17 +08:00
Lauren
7da0f0d49e Update README.md
Signed-off-by: Lauren <Lauren-ED209@users.noreply.github.com>
2024-10-17 18:59:41 +08:00
Ns2Kracy
2adb795896 Update to 0.4.13 (#2004) 2024-09-18 15:53:41 +08:00
Ns2Kracy
8b251dc407 fix: get file content twice (#2000) 2024-09-14 23:21:03 +08:00
5 changed files with 19 additions and 23 deletions

View File

@@ -194,9 +194,6 @@ CasaOS is a community-driven open source project and the people involved are Cas
- See <https://wiki.casaos.io/en/contribute> for ways of contributing to CasaOS
- See <https://wiki.casaos.io/en/contribute/development> if you want to be involved in code contribution specifically
## Donate
<p ><a href="https://www.buymeacoffee.com/icewhaletech"> <img align="center" src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" height="50" width="210" alt="bappi2097" target="_blank" /></a></p>
## Credits

View File

@@ -2,7 +2,7 @@ package common
const (
SERVICENAME = "casaos"
VERSION = "0.4.12"
VERSION = "0.4.13"
BODY = " "
RANW_NAME = "IceWhale-RemoteAccess"
)

View File

@@ -179,7 +179,7 @@ func CreateFileAndWriteContent(path string, content string) error {
return nil
}
// IsNotExistMkDir create a directory if it does not exist
// IsNotExistCreateFile create a file if it does not exist
func IsNotExistCreateFile(src string) error {
if notExist := CheckNotExist(src); notExist {
if err := CreateFile(src); err != nil {

View File

@@ -257,7 +257,6 @@ func GetDownloadSingleFile(ctx echo.Context) error {
ctx.Request().Header.Add("Content-Length", strconv.FormatInt(node.Size(), 10))
}
http.ServeContent(ctx.Response().Writer, ctx.Request(), fileName, node.ModTime(), fi)
// http.ServeFile(c.Writer, ctx.Request(), filePath)
defer fi.Close()
fileTmp, err := os.Open(filePath)
if err != nil {
@@ -268,7 +267,7 @@ func GetDownloadSingleFile(ctx echo.Context) error {
}
defer fileTmp.Close()
return ctx.File(filePath)
return nil
}
// @Summary 获取目录列表

View File

@@ -24,7 +24,7 @@ func GetRecoverStorage(ctx echo.Context) error {
google_drive := google_drive.GetConfig()
google_drive.Code = ctx.QueryParam("code")
if len(google_drive.Code) == 0 {
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Code cannot be empty"
logger.Error("Then code is empty: ", zap.String("code", google_drive.Code), zap.Any("name", "google_drive"))
@@ -33,7 +33,7 @@ func GetRecoverStorage(ctx echo.Context) error {
err := google_drive.Init(ctx.Request().Context())
if err != nil {
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Initialization failure"
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "google_drive"))
@@ -43,7 +43,7 @@ func GetRecoverStorage(ctx echo.Context) error {
username, err := google_drive.GetUserInfo(ctx.Request().Context())
if err != nil {
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Failed to get user information"
logger.Error("Then get user info error: ", zap.Error(err), zap.Any("name", "google_drive"))
@@ -53,7 +53,7 @@ func GetRecoverStorage(ctx echo.Context) error {
dmap["username"] = username
configs, err := service.MyService.Storage().GetConfig()
if err != nil {
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Failed to get rclone config"
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "google_drive"))
@@ -66,7 +66,7 @@ func GetRecoverStorage(ctx echo.Context) error {
continue
}
if cf["type"] == "drive" && cf["username"] == dmap["username"] {
ctx.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
ctx.HTML(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
err := service.MyService.Storage().CheckAndMountByName(v)
if err != nil {
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
@@ -100,7 +100,7 @@ func GetRecoverStorage(ctx echo.Context) error {
dropbox := dropbox.GetConfig()
dropbox.Code = ctx.QueryParam("code")
if len(dropbox.Code) == 0 {
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Code cannot be empty"
logger.Error("Then code is empty error: ", zap.String("code", dropbox.Code), zap.Any("name", "dropbox"))
@@ -109,7 +109,7 @@ func GetRecoverStorage(ctx echo.Context) error {
err := dropbox.Init(ctx.Request().Context())
if err != nil {
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Initialization failure"
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "dropbox"))
@@ -117,7 +117,7 @@ func GetRecoverStorage(ctx echo.Context) error {
}
username, err := dropbox.GetUserInfo(ctx.Request().Context())
if err != nil {
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Failed to get user information"
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "dropbox"))
@@ -128,7 +128,7 @@ func GetRecoverStorage(ctx echo.Context) error {
configs, err := service.MyService.Storage().GetConfig()
if err != nil {
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Failed to get rclone config"
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "dropbox"))
@@ -141,7 +141,7 @@ func GetRecoverStorage(ctx echo.Context) error {
continue
}
if cf["type"] == "dropbox" && cf["username"] == dmap["username"] {
ctx.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
ctx.HTML(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
err := service.MyService.Storage().CheckAndMountByName(v)
if err != nil {
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
@@ -185,7 +185,7 @@ func GetRecoverStorage(ctx echo.Context) error {
onedrive := onedrive.GetConfig()
onedrive.Code = ctx.QueryParam("code")
if len(onedrive.Code) == 0 {
ctx.String(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Code cannot be empty</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Code cannot be empty"
logger.Error("Then code is empty error: ", zap.String("code", onedrive.Code), zap.Any("name", "onedrive"))
@@ -194,7 +194,7 @@ func GetRecoverStorage(ctx echo.Context) error {
err := onedrive.Init(ctx.Request().Context())
if err != nil {
ctx.String(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Initialization failure:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Initialization failure"
logger.Error("Then init error: ", zap.Error(err), zap.Any("name", "onedrive"))
@@ -202,7 +202,7 @@ func GetRecoverStorage(ctx echo.Context) error {
}
username, driveId, driveType, err := onedrive.GetInfo(ctx.Request().Context())
if err != nil {
ctx.String(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Failed to get user information:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Failed to get user information"
logger.Error("Then get user information: ", zap.Error(err), zap.Any("name", "onedrive"))
@@ -213,7 +213,7 @@ func GetRecoverStorage(ctx echo.Context) error {
configs, err := service.MyService.Storage().GetConfig()
if err != nil {
ctx.String(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
ctx.HTML(200, `<p>Failed to get rclone config:`+err.Error()+`</p><script>window.close()</script>`)
notify["status"] = "fail"
notify["message"] = "Failed to get rclone config"
logger.Error("Then get config error: ", zap.Error(err), zap.Any("name", "onedrive"))
@@ -226,7 +226,7 @@ func GetRecoverStorage(ctx echo.Context) error {
continue
}
if cf["type"] == "onedrive" && cf["username"] == dmap["username"] {
ctx.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
ctx.HTML(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
err := service.MyService.Storage().CheckAndMountByName(v)
if err != nil {
logger.Error("check and mount by name error: ", zap.Error(err), zap.Any("name", cf["username"]))
@@ -270,5 +270,5 @@ func GetRecoverStorage(ctx echo.Context) error {
service.MyService.Notify().SendNotify("casaos:file:recover", notify)
}
return ctx.String(200, `<p>Just close the page</p><script>window.close()</script>`)
return ctx.HTML(200, `<p>Just close the page</p><script>window.close()</script>`)
}