Skip to content

Commit

Permalink
feat: add hidden files flag (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurynasgadl authored May 28, 2021
1 parent 11092ee commit 847d870
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ yarn-error.log*
*.sln
*.sw*
bin/
dist/
build/
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ bump-version: | ; $(info $(M) creating a new release…)
## help: Show this help
.PHONY: help
help:
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /' | sort
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /' | sort

.PHONY: build-release-bin
build-release-bin:
GO111MODULE=on GOOS=linux GOARCH=amd64 $(GO) build -ldflags '$(LDFLAGS)' -o bin/filebrowser-$(VERSION)
tar -C bin -czf "dist/filebrowser-$(VERSION).tar.gz" "filebrowser-$(VERSION)"
2 changes: 2 additions & 0 deletions cmd/config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ you want to change. Other options will remain unchanged.`,
ser.Port = mustGetString(flags, flag.Name)
case "log":
ser.Log = mustGetString(flags, flag.Name)
case "hidden-files":
ser.HiddenFiles = convertFileStrToFileMap(mustGetString(flags, flag.Name))
case "signup":
set.Signup = mustGetBool(flags, flag.Name)
case "auth.method":
Expand Down
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func addServerFlags(flags *pflag.FlagSet) {
flags.Bool("disable-preview-resize", false, "disable resize of image previews")
flags.Bool("disable-exec", false, "disables Command Runner feature")
flags.Bool("disable-type-detection-by-header", false, "disables type detection by reading file headers")
flags.String("hidden-files", "", "comma separated list of files that should be hidden")
}

var rootCmd = &cobra.Command{
Expand Down Expand Up @@ -260,6 +261,10 @@ func getRunParams(flags *pflag.FlagSet, st *storage.Storage) *settings.Server {
_, disableExec := getParamB(flags, "disable-exec")
server.EnableExec = !disableExec

if val, set := getParamB(flags, "hidden-files"); set {
server.HiddenFiles = convertFileStrToFileMap(val)
}

return server
}

Expand Down
14 changes: 14 additions & 0 deletions cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,17 @@ func convertCmdStrToCmdArray(cmd string) []string {
}
return cmdArray
}

// convertFileStrToFileMap parses a comma-separated file list string
// into a map where each key is a separate file
func convertFileStrToFileMap(files string) map[string]struct{} {
fileMap := make(map[string]struct{})
files = strings.TrimSpace(files)
if files != "" {
fileParts := strings.Split(files, ",")
for _, file := range fileParts {
fileMap[file] = struct{}{}
}
}
return fileMap
}
10 changes: 10 additions & 0 deletions files/listing.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,13 @@ func (l byModified) Less(i, j int) bool {
iModified, jModified := l.Items[i].ModTime, l.Items[j].ModTime
return iModified.Sub(jModified) < 0
}

func (l *Listing) FilterItems(fn func(fi *FileInfo) bool) {
var filtered []*FileInfo
for _, item := range l.Items {
if fn(item) {
filtered = append(filtered, item)
}
}
l.Items = filtered
}
5 changes: 5 additions & 0 deletions frontend/src/components/prompts/Archive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/>

<button
:disabled="loading"
v-for="(ext, format) in formats"
:key="format"
class="button button--block"
Expand All @@ -38,6 +39,7 @@ export default {
data: function () {
return {
name: "",
loading: false,
formats: {
zip: "zip",
tar: "tar",
Expand Down Expand Up @@ -74,11 +76,14 @@ export default {
uri = uri.replace("//", "/");
try {
this.loading = true
await api.archive(uri, this.name, format, ...items);
this.$store.commit("setReload", true);
} catch (e) {
this.$showError(e);
} finally {
this.loading = false
}
this.$store.commit("closeHovers");
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/prompts/Unarchive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
type="submit"
:aria-label="$t('buttons.unarchive')"
:title="$t('buttons.unarchive')"
:disabled="loading"
>
{{ $t("buttons.unarchive") }}
</button>
Expand All @@ -45,6 +46,7 @@ export default {
name: "rename",
data: function () {
return {
loading: false,
name: "",
};
},
Expand All @@ -63,11 +65,14 @@ export default {
dst = dst.replace("//", "/");
try {
this.loading = true;
await api.unarchive(item.url, dst, false);
this.$store.commit("setReload", true);
} catch (e) {
this.$showError(e);
} finally {
this.loading = true;
}
this.$store.commit("closeHovers");
Expand Down
8 changes: 0 additions & 8 deletions frontend/src/views/settings/Profile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@
</div>

<div class="card-content">
<p>
<input type="checkbox" v-model="hideDotfiles" />
{{ $t("settings.hideDotfiles") }}
</p>
<p>
<input type="checkbox" v-model="singleClick" />
{{ $t("settings.singleClick") }}
</p>
<h3>{{ $t("settings.language") }}</h3>
<languages
class="input input--block"
Expand Down
4 changes: 4 additions & 0 deletions http/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ var resourceGetHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
if file.IsDir {
file.Listing.Sorting = d.user.Sorting
file.Listing.ApplySort()
file.Listing.FilterItems(func(fi *files.FileInfo) bool {
_, exists := d.server.HiddenFiles[fi.Name]
return !exists
})
return renderJSON(w, r, file)
}

Expand Down
25 changes: 13 additions & 12 deletions settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,19 @@ func (s *Settings) GetRules() []rules.Rule {

// Server specific settings.
type Server struct {
Root string `json:"root"`
BaseURL string `json:"baseURL"`
Socket string `json:"socket"`
TLSKey string `json:"tlsKey"`
TLSCert string `json:"tlsCert"`
Port string `json:"port"`
Address string `json:"address"`
Log string `json:"log"`
EnableThumbnails bool `json:"enableThumbnails"`
ResizePreview bool `json:"resizePreview"`
EnableExec bool `json:"enableExec"`
TypeDetectionByHeader bool `json:"typeDetectionByHeader"`
Root string `json:"root"`
BaseURL string `json:"baseURL"`
Socket string `json:"socket"`
TLSKey string `json:"tlsKey"`
TLSCert string `json:"tlsCert"`
Port string `json:"port"`
Address string `json:"address"`
Log string `json:"log"`
EnableThumbnails bool `json:"enableThumbnails"`
ResizePreview bool `json:"resizePreview"`
EnableExec bool `json:"enableExec"`
TypeDetectionByHeader bool `json:"typeDetectionByHeader"`
HiddenFiles map[string]struct{} `json:"hiddenFiles"`
}

// Clean cleans any variables that might need cleaning.
Expand Down

0 comments on commit 847d870

Please sign in to comment.