mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Add default storage configurations (#12813)
Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
		@@ -21,27 +21,14 @@ import (
 | 
			
		||||
// LFS represents the configuration for Git LFS
 | 
			
		||||
var LFS = struct {
 | 
			
		||||
	StartServer     bool          `ini:"LFS_START_SERVER"`
 | 
			
		||||
	ContentPath     string        `ini:"LFS_CONTENT_PATH"`
 | 
			
		||||
	JWTSecretBase64 string        `ini:"LFS_JWT_SECRET"`
 | 
			
		||||
	JWTSecretBytes  []byte        `ini:"-"`
 | 
			
		||||
	HTTPAuthExpiry  time.Duration `ini:"LFS_HTTP_AUTH_EXPIRY"`
 | 
			
		||||
	MaxFileSize     int64         `ini:"LFS_MAX_FILE_SIZE"`
 | 
			
		||||
	LocksPagingNum  int           `ini:"LFS_LOCKS_PAGING_NUM"`
 | 
			
		||||
 | 
			
		||||
	StoreType   string
 | 
			
		||||
	ServeDirect bool
 | 
			
		||||
	Minio       struct {
 | 
			
		||||
		Endpoint        string
 | 
			
		||||
		AccessKeyID     string
 | 
			
		||||
		SecretAccessKey string
 | 
			
		||||
		UseSSL          bool
 | 
			
		||||
		Bucket          string
 | 
			
		||||
		Location        string
 | 
			
		||||
		BasePath        string
 | 
			
		||||
	}
 | 
			
		||||
}{
 | 
			
		||||
	StoreType: "local",
 | 
			
		||||
}
 | 
			
		||||
	Storage
 | 
			
		||||
}{}
 | 
			
		||||
 | 
			
		||||
func newLFSService() {
 | 
			
		||||
	sec := Cfg.Section("server")
 | 
			
		||||
@@ -49,10 +36,41 @@ func newLFSService() {
 | 
			
		||||
		log.Fatal("Failed to map LFS settings: %v", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	LFS.ContentPath = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join(AppDataPath, "lfs"))
 | 
			
		||||
	if !filepath.IsAbs(LFS.ContentPath) {
 | 
			
		||||
		LFS.ContentPath = filepath.Join(AppWorkPath, LFS.ContentPath)
 | 
			
		||||
	lfsSec := Cfg.Section("lfs")
 | 
			
		||||
	LFS.Storage.Type = lfsSec.Key("STORAGE_TYPE").MustString("")
 | 
			
		||||
	if LFS.Storage.Type == "" {
 | 
			
		||||
		LFS.Storage.Type = "default"
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if LFS.Storage.Type != LocalStorageType && LFS.Storage.Type != MinioStorageType {
 | 
			
		||||
		storage, ok := storages[LFS.Storage.Type]
 | 
			
		||||
		if !ok {
 | 
			
		||||
			log.Fatal("Failed to get lfs storage type: %s", LFS.Storage.Type)
 | 
			
		||||
		}
 | 
			
		||||
		LFS.Storage = storage
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Override
 | 
			
		||||
	LFS.ServeDirect = lfsSec.Key("SERVE_DIRECT").MustBool(LFS.ServeDirect)
 | 
			
		||||
	switch LFS.Storage.Type {
 | 
			
		||||
	case LocalStorageType:
 | 
			
		||||
		// keep compatible
 | 
			
		||||
		LFS.Path = sec.Key("LFS_CONTENT_PATH").MustString(filepath.Join(AppDataPath, "lfs"))
 | 
			
		||||
		LFS.Path = lfsSec.Key("PATH").MustString(LFS.Path)
 | 
			
		||||
		if !filepath.IsAbs(LFS.Path) {
 | 
			
		||||
			LFS.Path = filepath.Join(AppWorkPath, LFS.Path)
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	case MinioStorageType:
 | 
			
		||||
		LFS.Minio.Endpoint = lfsSec.Key("MINIO_ENDPOINT").MustString(LFS.Minio.Endpoint)
 | 
			
		||||
		LFS.Minio.AccessKeyID = lfsSec.Key("MINIO_ACCESS_KEY_ID").MustString(LFS.Minio.AccessKeyID)
 | 
			
		||||
		LFS.Minio.SecretAccessKey = lfsSec.Key("MINIO_SECRET_ACCESS_KEY").MustString(LFS.Minio.SecretAccessKey)
 | 
			
		||||
		LFS.Minio.Bucket = lfsSec.Key("MINIO_BUCKET").MustString(LFS.Minio.Bucket)
 | 
			
		||||
		LFS.Minio.Location = lfsSec.Key("MINIO_LOCATION").MustString(LFS.Minio.Location)
 | 
			
		||||
		LFS.Minio.UseSSL = lfsSec.Key("MINIO_USE_SSL").MustBool(LFS.Minio.UseSSL)
 | 
			
		||||
		LFS.Minio.BasePath = lfsSec.Key("MINIO_BASE_PATH").MustString("lfs/")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if LFS.LocksPagingNum == 0 {
 | 
			
		||||
		LFS.LocksPagingNum = 50
 | 
			
		||||
	}
 | 
			
		||||
@@ -92,14 +110,6 @@ func newLFSService() {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func ensureLFSDirectory() {
 | 
			
		||||
	if LFS.StartServer {
 | 
			
		||||
		if err := os.MkdirAll(LFS.ContentPath, 0700); err != nil {
 | 
			
		||||
			log.Fatal("Failed to create '%s': %v", LFS.ContentPath, err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CheckLFSVersion will check lfs version, if not satisfied, then disable it.
 | 
			
		||||
func CheckLFSVersion() {
 | 
			
		||||
	if LFS.StartServer {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user