1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00
mycorrhiza/files/files.go
handlerug b87583ef28
Drop fixed authorization
Important changes:
- UseFixedAuth is now UseAuth and toggles all kinds of authorization and
  registration
- UseRegistration is now AllowRegistration to better reflect the meaning
- LimitRegistration is now RegistrationLimit because it's not a boolean,
  it's a value (not "limit registration?", but "registration limit is
  ...")
- registered-users.json is now users.json, because all users are stored
  there
- user.AuthUsed is dropped in favor of new cfg.UseAuth which has the
  same meaning

I hope I have not forgotten anything.
2021-07-02 15:20:03 +07:00

70 lines
2.1 KiB
Go

// Package files is used to get paths to different files Mycorrhiza uses. Also see cfg.
package files
import (
"os"
"path/filepath"
"github.com/bouncepaw/mycorrhiza/cfg"
)
var paths struct {
gitRepo string
cacheDir string
staticFiles string
configPath string
tokensJSON string
userCredentialsJSON string
}
// HyphaeDir returns the path to hyphae storage.
// A separate function is needed to easily know where a general storage path is
// needed rather than a concrete Git or the whole wiki storage path, so that we
// could easily refactor things later if we'll ever support different storages.
func HyphaeDir() string { return paths.gitRepo }
// GitRepo returns the path to the Git repository of the wiki.
func GitRepo() string { return paths.gitRepo }
// StaticFiles returns the path to static files directory
func StaticFiles() string { return paths.staticFiles }
// ConfigPath returns the path to the config file.
func ConfigPath() string { return paths.configPath }
// TokensJSON returns the path to the JSON user tokens storage.
func TokensJSON() string { return paths.tokensJSON }
// UserCredentialsJSON returns the path to the JSON user credentials storage.
func UserCredentialsJSON() string { return paths.userCredentialsJSON }
// PrepareWikiRoot ensures all needed directories and files exist and have
// correct permissions.
func PrepareWikiRoot() error {
if err := os.MkdirAll(cfg.WikiDir, os.ModeDir|0777); err != nil {
return err
}
paths.cacheDir = filepath.Join(cfg.WikiDir, "cache")
if err := os.MkdirAll(paths.cacheDir, os.ModeDir|0777); err != nil {
return err
}
paths.gitRepo = filepath.Join(cfg.WikiDir, "wiki.git")
if err := os.MkdirAll(paths.gitRepo, os.ModeDir|0777); err != nil {
return err
}
paths.staticFiles = filepath.Join(cfg.WikiDir, "static")
if err := os.MkdirAll(paths.staticFiles, os.ModeDir|0777); err != nil {
return err
}
paths.configPath = filepath.Join(cfg.WikiDir, "config.ini")
paths.userCredentialsJSON = filepath.Join(cfg.WikiDir, "users.json")
paths.tokensJSON = filepath.Join(paths.cacheDir, "tokens.json")
return nil
}