update readme
Former-commit-id: 526e9c3b22e35bdf4e1a20133be9677a84c855b3 [formerly c32f0e71e758cda14ad3e7174cac5c61e18683ac] [formerly 31e8a1808321a0fc95e9c1ce382d6267987c797f [formerly 465b10a02aef310ad05d1484a860db78f998625d]] Former-commit-id: 577ddb9013d6f993b24eb3ee2f9650f82a22be90 [formerly 8c4e05b2f3f2e46020c507744a3424e93512102f] Former-commit-id: d4df957be2535cf8bdbc891ebf52d68450f03b18
This commit is contained in:
@@ -4,8 +4,9 @@
|
||||
package filemanager
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -97,22 +98,31 @@ func parse(c *caddy.Controller) ([]*config, error) {
|
||||
|
||||
caddyConf := httpserver.GetConfig(c)
|
||||
|
||||
path := filepath.Join(caddy.AssetsPath(), "filemanager")
|
||||
err := os.MkdirAll(path, 0700)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// if there is a database path and it is not absolute,
|
||||
// it will be relative to Caddy folder.
|
||||
if !filepath.IsAbs(database) && database != "" {
|
||||
database = filepath.Join(path, database)
|
||||
}
|
||||
|
||||
// If there is no database path on the settings,
|
||||
// store one in .caddy/filemanager/name.db.
|
||||
if database == "" {
|
||||
path := filepath.Join(caddy.AssetsPath(), "filemanager")
|
||||
err := os.MkdirAll(path, 0700)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// The name of the database is the hashed value of a string composed
|
||||
// by the host, address path and the baseurl of this File Manager
|
||||
// instance.
|
||||
hasher := sha256.New()
|
||||
hasher := md5.New()
|
||||
hasher.Write([]byte(caddyConf.Addr.Host + caddyConf.Addr.Path + baseURL))
|
||||
sha := hex.EncodeToString(hasher.Sum(nil))
|
||||
database = filepath.Join(path, sha+".db")
|
||||
|
||||
fmt.Println("[WARNING] A database is going to be created for your File Manager instace at " + database +
|
||||
". It is highly recommended that you set the 'database' option to '" + sha + ".db'\n")
|
||||
}
|
||||
|
||||
fm, err := New(database, User{
|
||||
|
||||
Reference in New Issue
Block a user