feat: add hide dotfiles param (#1148)
This commit is contained in:
parent
dcbc3286e2
commit
10e399b3c3
|
@ -32,7 +32,8 @@
|
||||||
"toggleSidebar": "Toggle sidebar",
|
"toggleSidebar": "Toggle sidebar",
|
||||||
"update": "Update",
|
"update": "Update",
|
||||||
"upload": "Upload",
|
"upload": "Upload",
|
||||||
"permalink": "Get Permanent Link"
|
"permalink": "Get Permanent Link",
|
||||||
|
"hideDotfiles": "Hide dotfiles"
|
||||||
},
|
},
|
||||||
"success": {
|
"success": {
|
||||||
"linkCopied": "Link copied!"
|
"linkCopied": "Link copied!"
|
||||||
|
@ -188,7 +189,8 @@
|
||||||
"execute": "Execute commands",
|
"execute": "Execute commands",
|
||||||
"rename": "Rename or move files and directories",
|
"rename": "Rename or move files and directories",
|
||||||
"share": "Share files"
|
"share": "Share files"
|
||||||
}
|
},
|
||||||
|
"hideDotfiles": "Hide dotfiles"
|
||||||
},
|
},
|
||||||
"sidebar": {
|
"sidebar": {
|
||||||
"help": "Help",
|
"help": "Help",
|
||||||
|
@ -244,4 +246,4 @@
|
||||||
"downloadFile": "Download File",
|
"downloadFile": "Download File",
|
||||||
"downloadFolder": "Download Folder"
|
"downloadFolder": "Download Folder"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
|
<p><input type="checkbox" v-model="hideDotfiles"> {{ $t('settings.hideDotfiles') }}</p>
|
||||||
<h3>{{ $t('settings.language') }}</h3>
|
<h3>{{ $t('settings.language') }}</h3>
|
||||||
<languages class="input input--block" :locale.sync="locale"></languages>
|
<languages class="input input--block" :locale.sync="locale"></languages>
|
||||||
</div>
|
</div>
|
||||||
|
@ -67,6 +68,7 @@ export default {
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.locale = this.user.locale
|
this.locale = this.user.locale
|
||||||
|
this.hideDotfiles = this.user.hideDotfiles
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations([ 'updateUser' ]),
|
...mapMutations([ 'updateUser' ]),
|
||||||
|
@ -90,8 +92,8 @@ export default {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = { id: this.user.id, locale: this.locale }
|
const data = { id: this.user.id, locale: this.locale, hideDotfiles: this.hideDotfiles }
|
||||||
await api.update(data, ['locale'])
|
await api.update(data, ['locale', 'hideDotfiles'])
|
||||||
this.updateUser(data)
|
this.updateUser(data)
|
||||||
this.$showSuccess(this.$t('settings.settingsUpdated'))
|
this.$showSuccess(this.$t('settings.settingsUpdated'))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -26,6 +26,7 @@ type userInfo struct {
|
||||||
Perm users.Permissions `json:"perm"`
|
Perm users.Permissions `json:"perm"`
|
||||||
Commands []string `json:"commands"`
|
Commands []string `json:"commands"`
|
||||||
LockPassword bool `json:"lockPassword"`
|
LockPassword bool `json:"lockPassword"`
|
||||||
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type authToken struct {
|
type authToken struct {
|
||||||
|
@ -175,6 +176,7 @@ func printToken(w http.ResponseWriter, _ *http.Request, d *data, user *users.Use
|
||||||
Perm: user.Perm,
|
Perm: user.Perm,
|
||||||
LockPassword: user.LockPassword,
|
LockPassword: user.LockPassword,
|
||||||
Commands: user.Commands,
|
Commands: user.Commands,
|
||||||
|
HideDotfiles: user.HideDotfiles,
|
||||||
},
|
},
|
||||||
StandardClaims: jwt.StandardClaims{
|
StandardClaims: jwt.StandardClaims{
|
||||||
IssuedAt: time.Now().Unix(),
|
IssuedAt: time.Now().Unix(),
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/tomasen/realip"
|
"github.com/tomasen/realip"
|
||||||
|
|
||||||
|
"github.com/filebrowser/filebrowser/v2/rules"
|
||||||
"github.com/filebrowser/filebrowser/v2/runner"
|
"github.com/filebrowser/filebrowser/v2/runner"
|
||||||
"github.com/filebrowser/filebrowser/v2/settings"
|
"github.com/filebrowser/filebrowser/v2/settings"
|
||||||
"github.com/filebrowser/filebrowser/v2/storage"
|
"github.com/filebrowser/filebrowser/v2/storage"
|
||||||
|
@ -26,6 +27,10 @@ type data struct {
|
||||||
|
|
||||||
// Check implements rules.Checker.
|
// Check implements rules.Checker.
|
||||||
func (d *data) Check(path string) bool {
|
func (d *data) Check(path string) bool {
|
||||||
|
if d.user.HideDotfiles && rules.MatchHidden(path) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
allow := true
|
allow := true
|
||||||
for _, rule := range d.settings.Rules {
|
for _, rule := range d.settings.Rules {
|
||||||
if rule.Matches(path) {
|
if rule.Matches(path) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package rules
|
package rules
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -18,6 +19,12 @@ type Rule struct {
|
||||||
Regexp *Regexp `json:"regexp"`
|
Regexp *Regexp `json:"regexp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MatchHidden matches paths with a basename
|
||||||
|
// that begins with a dot.
|
||||||
|
func MatchHidden(path string) bool {
|
||||||
|
return strings.HasPrefix(filepath.Base(path), ".")
|
||||||
|
}
|
||||||
|
|
||||||
// Matches matches a path against a rule.
|
// Matches matches a path against a rule.
|
||||||
func (r *Rule) Matches(path string) bool {
|
func (r *Rule) Matches(path string) bool {
|
||||||
if r.Regex {
|
if r.Regex {
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package rules
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestMatchHidden(t *testing.T) {
|
||||||
|
cases := map[string]bool{
|
||||||
|
"/": false,
|
||||||
|
"/src": false,
|
||||||
|
"/src/": false,
|
||||||
|
"/.circleci": true,
|
||||||
|
"/a/b/c/.docker.json": true,
|
||||||
|
".docker.json": true,
|
||||||
|
"Dockerfile": false,
|
||||||
|
"/Dockerfile": false,
|
||||||
|
}
|
||||||
|
|
||||||
|
for path, want := range cases {
|
||||||
|
got := MatchHidden(path)
|
||||||
|
if got != want {
|
||||||
|
t.Errorf("MatchHidden(%s)=%v; want %v", path, got, want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,12 +8,13 @@ import (
|
||||||
// UserDefaults is a type that holds the default values
|
// UserDefaults is a type that holds the default values
|
||||||
// for some fields on User.
|
// for some fields on User.
|
||||||
type UserDefaults struct {
|
type UserDefaults struct {
|
||||||
Scope string `json:"scope"`
|
Scope string `json:"scope"`
|
||||||
Locale string `json:"locale"`
|
Locale string `json:"locale"`
|
||||||
ViewMode users.ViewMode `json:"viewMode"`
|
ViewMode users.ViewMode `json:"viewMode"`
|
||||||
Sorting files.Sorting `json:"sorting"`
|
Sorting files.Sorting `json:"sorting"`
|
||||||
Perm users.Permissions `json:"perm"`
|
Perm users.Permissions `json:"perm"`
|
||||||
Commands []string `json:"commands"`
|
Commands []string `json:"commands"`
|
||||||
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply applies the default options to a user.
|
// Apply applies the default options to a user.
|
||||||
|
@ -24,4 +25,5 @@ func (d *UserDefaults) Apply(u *users.User) {
|
||||||
u.Perm = d.Perm
|
u.Perm = d.Perm
|
||||||
u.Sorting = d.Sorting
|
u.Sorting = d.Sorting
|
||||||
u.Commands = d.Commands
|
u.Commands = d.Commands
|
||||||
|
u.HideDotfiles = d.HideDotfiles
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ type User struct {
|
||||||
Sorting files.Sorting `json:"sorting"`
|
Sorting files.Sorting `json:"sorting"`
|
||||||
Fs afero.Fs `json:"-" yaml:"-"`
|
Fs afero.Fs `json:"-" yaml:"-"`
|
||||||
Rules []rules.Rule `json:"rules"`
|
Rules []rules.Rule `json:"rules"`
|
||||||
|
HideDotfiles bool `json:"hideDotfiles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRules implements rules.Provider.
|
// GetRules implements rules.Provider.
|
||||||
|
|
Loading…
Reference in New Issue