Skip to content

CasaOS - A simple, easy-to-use, elegant open-source Personal Cloud system.

Modify naming rules

link7dedbafc8a94
diff --git a/drivers/google_drive/meta.go b/drivers/google_drive/meta.go
index 0cf88b5..b3ce819 100644
--- a/drivers/google_drive/meta.go
+++ b/drivers/google_drive/meta.go
@@ -17,7 +17,7 @@ type Addition struct {
ClientID string `json:"client_id" required:"true" default:"865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com" omit:"true"`
ClientSecret string `json:"client_secret" required:"true" default:"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" omit:"true"`
ChunkSize int64 `json:"chunk_size" type:"number" help:"chunk size while uploading (unit: MB)" omit:"true"`
- AuthUrl string `json:"auth_url" type:"string" default:"https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id=865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Ftest-get.casaos.io&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&approval_prompt=force&state=${HOST}%2Fv1%2Frecover%2FGoogleDrive&service=lso&o2v=1&flowName=GeneralOAuthFlow"`
+ AuthUrl string `json:"auth_url" type:"string" default:"https://accounts.google.com/o/oauth2/auth/oauthchooseaccount?response_type=code&client_id=865173455964-4ce3gdl73ak5s15kn1vkn73htc8tant2.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Ftest-get.casaos.io&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&access_type=offline&approval_prompt=force&state=${HOST}%2Fv1%2Frecover%2FGoogleDrive&service=lso&o2v=1&flowName=GeneralOAuthFlow"`
Icon string `json:"icon" type:"string" default:"./img/driver/GoogleDrive.svg"`
Code string `json:"code" type:"string" help:"code from auth_url" omit:"true"`
}
diff --git a/drivers/google_drive/util.go b/drivers/google_drive/util.go
index 6c09608..0adbe0f 100644
--- a/drivers/google_drive/util.go
+++ b/drivers/google_drive/util.go
@@ -28,7 +28,7 @@ func (d *GoogleDrive) getRefreshToken() error {
"client_secret": d.ClientSecret,
"code": d.Code,
"grant_type": "authorization_code",
- "redirect_uri": "http://test-get.casaos.io",
+ "redirect_uri": "https://test-get.casaos.io",
}).Post(url)
if err != nil {
return err
diff --git a/pkg/utils/file/file.go b/pkg/utils/file/file.go
index 10e91f7..1ce50d1 100644
--- a/pkg/utils/file/file.go
+++ b/pkg/utils/file/file.go
@@ -577,3 +577,22 @@ func ReadLine(lineNumber int, path string) string {
defer file.Close()
return ""
}
+
+func NameAccumulation(name string, dir string) string {
+ path := filepath.Join(dir, name)
+ if _, err := os.Stat(path); os.IsNotExist(err) {
+ return path
+ }
+ base := name
+ strings.Split(base, "_")
+ index := strings.LastIndex(base, "_")
+ if index < 0 {
+ index = len(base)
+ }
+ for i := 1; ; i++ {
+ newPath := filepath.Join(dir, fmt.Sprintf("%s_%d", base[:index], i))
+ if _, err := os.Stat(newPath); os.IsNotExist(err) {
+ return fmt.Sprintf("%s_%d", base[:index], i)
+ }
+ }
+}
diff --git a/pkg/utils/file/file_test.go b/pkg/utils/file/file_test.go
new file mode 100644
index 0000000..b75e4a2
--- /dev/null
+++ b/pkg/utils/file/file_test.go
@@ -0,0 +1,12 @@
+package file
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestNameAccumulation(t *testing.T) {
+ fmt.Println("aaa")
+ a := NameAccumulation("/mnt/test_1_1", "/")
+ fmt.Println(a)
+}
diff --git a/pkg/utils/httper/drive.go b/pkg/utils/httper/drive.go
index cdf49e2..13db91b 100644
--- a/pkg/utils/httper/drive.go
+++ b/pkg/utils/httper/drive.go
@@ -109,13 +109,14 @@ func CreateConfig(data map[string]string, name, t string) error {
"parameters": string(dataStr),
"type": t,
}).Post("/config/create")
+ logger.Info("when create config then", zap.Any("res", res.Body()))
if err != nil {
return err
}
if res.StatusCode() != 200 {
return fmt.Errorf("create config failed")
}
- logger.Info("create config then", zap.Any("res", res.Body()))
+
return nil
}
diff --git a/route/v1/recover.go b/route/v1/recover.go
index 57793b6..792556e 100644
--- a/route/v1/recover.go
+++ b/route/v1/recover.go
@@ -4,9 +4,9 @@ import (
"strings"
"time"
- "github.com/IceWhaleTech/CasaOS-Common/utils/file"
"github.com/IceWhaleTech/CasaOS/drivers/dropbox"
"github.com/IceWhaleTech/CasaOS/drivers/google_drive"
+ fileutil "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin"
)
@@ -55,7 +55,7 @@ func GetRecoverStorage(c *gin.Context) {
a := strings.Split(username, "@")
username = a[0]
}
- username += file.NameAccumulation(username)
+ username = fileutil.NameAccumulation(username, "/mnt")
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
if len(dataMap) > 0 {
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)
@@ -112,7 +112,7 @@ func GetRecoverStorage(c *gin.Context) {
a := strings.Split(username, "@")
username = a[0]
}
- username += file.NameAccumulation(username)
+ username = fileutil.NameAccumulation(username, "/mnt")
dataMap, _ := service.MyService.Storage().GetConfigByName(username)
if len(dataMap) > 0 {
c.String(200, `<p>The same configuration has been added</p><script>window.close()</script>`)