Modify naming rules

This commit is contained in:
link 2023-02-07 10:32:12 +00:00
parent b7634402bd
commit 7dedbafc8a
6 changed files with 38 additions and 6 deletions

View file

@ -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"`
}

View file

@ -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

View file

@ -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)
}
}
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -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>`)