github.com/gitbundle/modules@v0.0.0-20231025071548-85b91c5c3b01/setting/packages.go (about)

     1  // Copyright 2023 The GitBundle Inc. All rights reserved.
     2  // Copyright 2017 The Gitea Authors. All rights reserved.
     3  // Use of this source code is governed by a MIT-style
     4  // license that can be found in the LICENSE file.
     5  
     6  package setting
     7  
     8  import (
     9  	"net/url"
    10  	"os"
    11  	"path/filepath"
    12  
    13  	"github.com/gitbundle/modules/log"
    14  )
    15  
    16  // Package registry settings
    17  var (
    18  	Packages = struct {
    19  		Storage
    20  		EnableForAllOrgs  bool
    21  		ChunkedUploadPath string
    22  		RegistryHost      string
    23  	}{
    24  		EnableForAllOrgs: true,
    25  	}
    26  )
    27  
    28  func newPackages() {
    29  	sec := Cfg.Section("packages")
    30  	if err := sec.MapTo(&Packages); err != nil {
    31  		log.Fatal("Failed to map Packages settings: %v", err)
    32  	}
    33  
    34  	Packages.EnableForAllOrgs = sec.Key("ENABLE_FOR_ALL_ORGS").MustBool(true)
    35  	Packages.Storage = getStorage("packages", "", nil)
    36  
    37  	appURL, _ := url.Parse(AppURL)
    38  	Packages.RegistryHost = appURL.Host
    39  
    40  	Packages.ChunkedUploadPath = filepath.ToSlash(sec.Key("CHUNKED_UPLOAD_PATH").MustString("tmp/package-upload"))
    41  	if !filepath.IsAbs(Packages.ChunkedUploadPath) {
    42  		Packages.ChunkedUploadPath = filepath.ToSlash(filepath.Join(AppDataPath, Packages.ChunkedUploadPath))
    43  	}
    44  
    45  	if err := os.MkdirAll(Packages.ChunkedUploadPath, os.ModePerm); err != nil {
    46  		log.Error("Unable to create chunked upload directory: %s (%v)", Packages.ChunkedUploadPath, err)
    47  	}
    48  }