Merge pull request #1 from gtsteffaniak/add-indexing

Add indexing
This commit is contained in:
Graham Steffaniak 2023-06-16 12:32:24 -05:00 committed by GitHub
commit 905b0b6d4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
74 changed files with 389 additions and 214 deletions

View File

@ -7,22 +7,16 @@ RUN npm run build
FROM golang:alpine as base FROM golang:alpine as base
WORKDIR /app WORKDIR /app
COPY ./src/backend ./ COPY ./src/backend ./
RUN go build -ldflags='-w -s' -o filebrowser . RUN go build -ldflags="-w -s" -o filebrowser .
FROM alpine:latest FROM alpine:latest
RUN apk --no-cache add \ RUN apk --no-cache add \
ca-certificates \ ca-certificates \
mailcap \ mailcap
curl
HEALTHCHECK --start-period=2s --interval=5s --timeout=3s \
CMD curl -f http://localhost/health || exit 1
VOLUME /srv VOLUME /srv
EXPOSE 80 EXPOSE 80
WORKDIR /app
COPY --from=base /app/docker_config.json /.filebrowser.json COPY --from=base /app/docker_config.json ./.filebrowser.json
COPY --from=base /app/filebrowser /filebrowser COPY --from=base /app/filebrowser ./filebrowser
COPY --from=nbuild /app/dist/ ./frontend/dist/ COPY --from=nbuild /app/dist/ ./frontend/dist/
ENTRYPOINT [ "./filebrowser" ]
ENTRYPOINT [ "/filebrowser" ]

View File

@ -1,22 +1,22 @@
## My fork of filebrowser ## Gtstef fork of filebrowser
**Note: Intended to be used in docker only.** **Note: Intended to be used in docker only.**
This fork makes the following significant changes to filebrowser for origin: This fork makes the following significant changes to filebrowser for origin:
1. Improves search to use index instead of filesystem. 1. [x] Improves search to use index instead of filesystem.
- lightning fast - [x] Lightning fast
- realtime results as you type - [x] Realtime results as you type
1. Preview enhancments - [ ] Works with file type filter
1. [ ] Preview enhancements
- preview default view is constrained to files subwindow, - preview default view is constrained to files subwindow,
which can be toggled to fullscreen. which can be toggled to fullscreen.
1. Updated node version and dependancies 1. [ ] Updated version and dependencies
- uses latest npm and node version - [ ] uses latest npm and node version
- removes deprecated npm packages - [ ] removes deprecated npm packages
1. Improved routing - [x] Updates golang dependencies
- fixed bugs in original version 1. [ ] Added authentication type
1. Added authentication type - [ ] Using bearer token with remote authentication server
- Using bearer token with remote authentication server
## About ## About
@ -26,9 +26,10 @@ filebrowser provides a file managing interface within a specified directory and
Using docker: Using docker:
1. docker run: 1. docker run:
``` ```
docker run -it -v /path/to/folder:/srv -p 8080:80 gtstef/filebrowser:0.1.0
``` ```
1. docker-compose: 1. docker-compose:
@ -56,7 +57,7 @@ services:
filebrowser: filebrowser:
volumes: volumes:
- 'nas:/srv' - 'nas:/srv'
#- './database/:/database/' #- './database/:/database/'
#- './config.json:/.filebrowser.json' #- './config.json:/.filebrowser.json'
ports: ports:
- '8080:80' - '8080:80'

View File

@ -3,8 +3,8 @@ package auth
import ( import (
"net/http" "net/http"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// Auther is the authentication interface. // Auther is the authentication interface.

View File

@ -9,10 +9,10 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// MethodHookAuth is used to identify hook auth. // MethodHookAuth is used to identify hook auth.

View File

@ -7,8 +7,8 @@ import (
"os" "os"
"strings" "strings"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// MethodJSONAuth is used to identify json auth. // MethodJSONAuth is used to identify json auth.

View File

@ -3,8 +3,8 @@ package auth
import ( import (
"net/http" "net/http"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// MethodNoAuth is used to identify no auth. // MethodNoAuth is used to identify no auth.

View File

@ -4,9 +4,9 @@ import (
"net/http" "net/http"
"os" "os"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// MethodProxyAuth is used to identify no auth. // MethodProxyAuth is used to identify no auth.

View File

@ -1,8 +1,8 @@
package auth package auth
import ( import (
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// StorageBackend is a storage backend for auth storage. // StorageBackend is a storage backend for auth storage.

View File

@ -11,9 +11,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
func init() { func init() {

View File

@ -8,8 +8,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
func init() { func init() {

View File

@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
func init() { func init() {

View File

@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -13,6 +13,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"syscall" "syscall"
"strconv"
homedir "github.com/mitchellh/go-homedir" homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/afero" "github.com/spf13/afero"
@ -21,13 +22,14 @@ import (
v "github.com/spf13/viper" v "github.com/spf13/viper"
lumberjack "gopkg.in/natefinch/lumberjack.v2" lumberjack "gopkg.in/natefinch/lumberjack.v2"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/diskcache" "github.com/gtsteffaniak/filebrowser/search"
fbhttp "github.com/filebrowser/filebrowser/v2/http" "github.com/gtsteffaniak/filebrowser/diskcache"
"github.com/filebrowser/filebrowser/v2/img" fbhttp "github.com/gtsteffaniak/filebrowser/http"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/img"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/gtsteffaniak/filebrowser/users"
) )
var ( var (
@ -45,10 +47,13 @@ func (d dirFS) Open(name string) (fs.File, error) {
func init() { func init() {
cobra.OnInitialize(initConfig) cobra.OnInitialize(initConfig)
cobra.MousetrapHelpText = "" cobra.MousetrapHelpText = ""
rootCmd.SetVersionTemplate("File Browser version {{printf \"%s\" .Version}}\n") rootCmd.SetVersionTemplate("File Browser version {{printf \"%s\" .Version}}\n")
flags := rootCmd.Flags() flags := rootCmd.Flags()
// initialize indexing and schedule indexing ever n minutes (default 5)
indexingInterval := getEnvVariableAsUint32("INDEXING_INTERVAL")
go search.InitializeIndex(indexingInterval)
persistent := rootCmd.PersistentFlags() persistent := rootCmd.PersistentFlags()
persistent.StringVarP(&cfgFile, "config", "c", "", "config file path") persistent.StringVarP(&cfgFile, "config", "c", "", "config file path")
@ -60,6 +65,15 @@ func init() {
addServerFlags(flags) addServerFlags(flags)
} }
func getEnvVariableAsUint32(key string) uint32 {
valueStr := os.Getenv(key)
value, err := strconv.ParseUint(valueStr, 10, 32)
if err != nil {
return 5 // default value every 5 minutes
}
return uint32(value)
}
func addServerFlags(flags *pflag.FlagSet) { func addServerFlags(flags *pflag.FlagSet) {
flags.StringP("address", "a", "127.0.0.1", "address to listen on") flags.StringP("address", "a", "127.0.0.1", "address to listen on")
flags.StringP("log", "l", "stdout", "log output") flags.StringP("log", "l", "stdout", "log output")
@ -408,7 +422,6 @@ func initConfig() {
v.SetEnvPrefix("FB") v.SetEnvPrefix("FB")
v.AutomaticEnv() v.AutomaticEnv()
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
if err := v.ReadInConfig(); err != nil { if err := v.ReadInConfig(); err != nil {
if _, ok := err.(v.ConfigParseError); ok { if _, ok := err.(v.ConfigParseError); ok {
panic(err) panic(err)

View File

@ -5,8 +5,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -6,10 +6,10 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -5,9 +5,9 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -3,7 +3,7 @@ package cmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/storage/bolt/importer" "github.com/gtsteffaniak/filebrowser/storage/bolt/importer"
) )
func init() { func init() {

View File

@ -10,8 +10,8 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -3,7 +3,7 @@ package cmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -3,7 +3,7 @@ package cmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -8,7 +8,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -3,8 +3,8 @@ package cmd
import ( import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func init() { func init() {

View File

@ -14,9 +14,9 @@ import (
"github.com/spf13/pflag" "github.com/spf13/pflag"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/storage/bolt" "github.com/gtsteffaniak/filebrowser/storage/bolt"
) )
func checkErr(err error) { func checkErr(err error) {

View File

@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/filebrowser/filebrowser/v2/version" "github.com/gtsteffaniak/filebrowser/version"
) )
func init() { func init() {

View File

@ -1,8 +0,0 @@
{
"port": 80,
"baseURL": "",
"address": "",
"log": "stdout",
"database": "/database/filebrowser.db",
"root": "/srv"
}

View File

@ -1,15 +0,0 @@
#!/usr/bin/with-contenv bash
# make folders
mkdir -p /database
# copy config
if [ ! -f "/config/settings.json" ]; then
cp -a /defaults/settings.json /config/settings.json
fi
# permissions
chown abc:abc \
/config/settings.json \
/database \
/srv

View File

@ -1,3 +0,0 @@
#!/usr/bin/with-contenv bash
exec s6-setuidgid abc filebrowser -c /config/settings.json -d /database/filebrowser.db;

View File

@ -1,5 +1,5 @@
{ {
"port": 80, "port": 8080,
"baseURL": "", "baseURL": "",
"address": "", "address": "",
"log": "stdout", "log": "stdout",

View File

@ -19,8 +19,8 @@ import (
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
) )
// FileInfo describes a file. // FileInfo describes a file.

View File

@ -1,4 +1,4 @@
module filebrowser module github.com/gtsteffaniak/filebrowser
go 1.20 go 1.20
@ -6,7 +6,6 @@ require (
github.com/asdine/storm/v3 v3.2.1 github.com/asdine/storm/v3 v3.2.1
github.com/disintegration/imaging v1.6.2 github.com/disintegration/imaging v1.6.2
github.com/dsoprea/go-exif/v3 v3.0.1 github.com/dsoprea/go-exif/v3 v3.0.1
github.com/filebrowser/filebrowser/v2 v2.23.0
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568
github.com/golang-jwt/jwt/v4 v4.5.0 github.com/golang-jwt/jwt/v4 v4.5.0
github.com/gorilla/mux v1.8.0 github.com/gorilla/mux v1.8.0

View File

@ -86,8 +86,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po= github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/filebrowser/filebrowser/v2 v2.23.0 h1:t/crFqwgD7WBo/1xNCdWcD+Ba/m7qJHiareCxeiomF8=
github.com/filebrowser/filebrowser/v2 v2.23.0/go.mod h1:21YATGQ81ia3RgvnvkFGXx8E7JYgDqC1pfNI5AggfKQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=

View File

@ -11,8 +11,8 @@ import (
"github.com/golang-jwt/jwt/v4" "github.com/golang-jwt/jwt/v4"
"github.com/golang-jwt/jwt/v4/request" "github.com/golang-jwt/jwt/v4/request"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
const ( const (

View File

@ -11,7 +11,7 @@ import (
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/filebrowser/filebrowser/v2/runner" "github.com/gtsteffaniak/filebrowser/runner"
) )
const ( const (

View File

@ -7,11 +7,11 @@ import (
"github.com/tomasen/realip" "github.com/tomasen/realip"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/runner" "github.com/gtsteffaniak/filebrowser/runner"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
type handleFunc func(w http.ResponseWriter, r *http.Request, d *data) (int, error) type handleFunc func(w http.ResponseWriter, r *http.Request, d *data) (int, error)

View File

@ -6,8 +6,8 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
) )
type modifyRequest struct { type modifyRequest struct {

View File

@ -10,8 +10,8 @@ import (
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/img" "github.com/gtsteffaniak/filebrowser/img"
) )
/* /*

View File

@ -11,8 +11,8 @@ import (
"github.com/spf13/afero" "github.com/spf13/afero"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/share" "github.com/gtsteffaniak/filebrowser/share"
) )
var withHashFile = func(fn handleFunc) handleFunc { var withHashFile = func(fn handleFunc) handleFunc {

View File

@ -10,10 +10,10 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/share" "github.com/gtsteffaniak/filebrowser/share"
"github.com/filebrowser/filebrowser/v2/storage/bolt" "github.com/gtsteffaniak/filebrowser/storage/bolt"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func TestPublicShareHandlerAuthentication(t *testing.T) { func TestPublicShareHandlerAuthentication(t *testing.T) {

View File

@ -11,9 +11,9 @@ import (
"github.com/mholt/archiver/v3" "github.com/mholt/archiver/v3"
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/fileutils" "github.com/gtsteffaniak/filebrowser/fileutils"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
func slashClean(name string) string { func slashClean(name string) string {

View File

@ -14,9 +14,9 @@ import (
"github.com/shirou/gopsutil/v3/disk" "github.com/shirou/gopsutil/v3/disk"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/fileutils" "github.com/gtsteffaniak/filebrowser/fileutils"
) )
var resourceGetHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var resourceGetHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {

View File

@ -2,27 +2,37 @@ package http
import ( import (
"net/http" "net/http"
"os" "github.com/gtsteffaniak/filebrowser/search"
"github.com/filebrowser/filebrowser/v2/search"
) )
var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var searchHandler = withUser(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
response := []map[string]interface{}{} response := []map[string]interface{}{}
query := r.URL.Query().Get("query") query := r.URL.Query().Get("query")
var files []string
err := search.Search(d.user.Fs, r.URL.Path, query, d, func(path string, f os.FileInfo) error { var dirs []string
files, dirs = search.IndexedSearch(query,r.URL.Path,&files,&dirs)
for _,v := range(files){
response = append(response, map[string]interface{}{ response = append(response, map[string]interface{}{
"dir": f.IsDir(), "dir": false,
"path": path, "path": v,
}) })
return nil
})
if err != nil {
return http.StatusInternalServerError, err
} }
for _,v := range(dirs){
response = append(response, map[string]interface{}{
"dir": true,
"path": v,
})
}
files = files[:0]
dirs = dirs[:0]
// err := search.Search(d.user.Fs, r.URL.Path, query, d, func(path string, f os.FileInfo) error {
// response = append(response, map[string]interface{}{
// "dir": f.IsDir(),
// "path": path,
// })
//
// return nil
// })
return renderJSON(w, r, response) return renderJSON(w, r, response)
}) })

View File

@ -4,8 +4,8 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
type settingsData struct { type settingsData struct {

View File

@ -13,8 +13,8 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/share" "github.com/gtsteffaniak/filebrowser/share"
) )
func withPermShare(fn handleFunc) handleFunc { func withPermShare(fn handleFunc) handleFunc {

View File

@ -12,10 +12,10 @@ import (
"strings" "strings"
"text/template" "text/template"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/version" "github.com/gtsteffaniak/filebrowser/version"
) )
func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys fs.FS, file, contentType string) (int, error) { func handleWithStaticData(w http.ResponseWriter, _ *http.Request, d *data, fSys fs.FS, file, contentType string) (int, error) {

View File

@ -11,8 +11,8 @@ import (
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
var ( var (

View File

@ -8,7 +8,7 @@ import (
"os" "os"
"strings" "strings"
libErrors "github.com/filebrowser/filebrowser/v2/errors" libErrors "github.com/gtsteffaniak/filebrowser/errors"
) )
func renderJSON(w http.ResponseWriter, _ *http.Request, data interface{}) (int, error) { func renderJSON(w http.ResponseWriter, _ *http.Request, data interface{}) (int, error) {

View File

@ -1,7 +1,7 @@
package main package main
import ( import (
"github.com/filebrowser/filebrowser/v2/cmd" "github.com/gtsteffaniak/filebrowser/cmd"
) )
func main() { func main() {

View File

@ -3,7 +3,7 @@ package runner
import ( import (
"os/exec" "os/exec"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
// ParseCommand parses the command taking in account if the current // ParseCommand parses the command taking in account if the current

View File

@ -7,8 +7,8 @@ import (
"os/exec" "os/exec"
"strings" "strings"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// Runner is a commands runner. // Runner is a commands runner.

View File

@ -0,0 +1,182 @@
package search
import (
"log"
"os"
"path/filepath"
"strings"
"sync"
"sort"
"time"
)
var (
rootPath = "/srv" // DO NOT include trailing slash
indexes map[string][]string
mutex sync.RWMutex
lastIndexed time.Time
)
func InitializeIndex(intervalMinutes uint32) {
// Initialize the indexes map
indexes = make(map[string][]string)
var numFiles, numDirs int
log.Println("Indexing files...")
lastIndexedStart := time.Now()
// Call the function to index files and directories
totalNumFiles, totalNumDirs, err := indexFiles(rootPath,&numFiles,&numDirs)
if err != nil {
log.Fatal(err)
}
lastIndexed = lastIndexedStart
go indexingScheduler(intervalMinutes)
log.Println("Successfully indexed files.")
log.Println("Files found :",totalNumFiles)
log.Println("Directories found :",totalNumDirs)
}
func indexingScheduler(intervalMinutes uint32) {
log.Printf("Indexing scheduler will run every %v minutes",intervalMinutes)
for {
time.Sleep(time.Duration(intervalMinutes) * time.Minute)
var numFiles, numDirs int
lastIndexedStart := time.Now()
totalNumFiles, totalNumDirs, err := indexFiles(rootPath,&numFiles,&numDirs)
if err != nil {
log.Fatal(err)
}
lastIndexed = lastIndexedStart
if totalNumFiles+totalNumDirs > 0 {
log.Println("re-indexing found changes and updated the index.")
}
}
}
// Define a function to recursively index files and directories
func indexFiles(path string, numFiles *int, numDirs *int) (int,int,error) {
// Check if the current directory has been modified since last indexing
dir, err := os.Open(path)
if err != nil {
// directory must have been deleted, remove from index
delete(indexes, path)
}
defer dir.Close()
dirInfo, err := dir.Stat()
if err != nil {
return *numFiles,*numDirs,err
}
// Compare the last modified time of the directory with the last indexed time
if dirInfo.ModTime().Before(lastIndexed) {
return *numFiles,*numDirs,nil
}
// Read the directory contents
files, err := dir.Readdir(-1)
if err != nil {
return *numFiles,*numDirs,err
}
// Iterate over the files and directories
for _, file := range files {
if file.IsDir() {
*numDirs++
indexFiles(path+"/"+file.Name(),numFiles,numDirs)
}
*numFiles++
addToIndex(path, file.Name())
}
return *numFiles,*numDirs,nil
}
func addToIndex(path string, fileName string) {
mutex.Lock()
defer mutex.Unlock()
path = strings.TrimPrefix(path,rootPath+"/")
path = strings.TrimSuffix(path,"/")
if path == rootPath {
path = "/"
}
info, exists := indexes[path]
if !exists {
info = []string{}
}
info = append(info, fileName)
indexes[path] = info
}
func SearchAllIndexes(searchTerm string, scope string, files []string, dirs []string) ([]string, []string) {
mutex.RLock()
defer mutex.RUnlock()
var matchingFiles []string
var matchingDirs []string
// Iterate over the indexes
for dirName, v := range indexes {
searchItems := v
// Iterate over the path names
for _, pathName := range searchItems {
if dirName != "/" {
pathName = dirName+"/"+pathName
}
// Check if the path name contains the search term
if !containsSearchTerm(pathName, searchTerm) {
continue
}
pathName = scopedPathNameFilter(pathName, scope)
if pathName == "" {
continue
}
matchingFiles = append(matchingFiles, pathName)
}
// Check if the path name contains the search term
if !containsSearchTerm(dirName, searchTerm) {
continue
}
pathName := scopedPathNameFilter(dirName, scope)
if pathName == "" {
continue
}
matchingDirs = append(matchingDirs, pathName)
}
// Sort the strings based on the number of elements after splitting by "/"
sort.Slice(matchingFiles, func(i, j int) bool {
parts1 := strings.Split(matchingFiles[i], "/")
parts2 := strings.Split(matchingFiles[j], "/")
return len(parts1) < len(parts2)
})
// Sort the strings based on the number of elements after splitting by "/"
sort.Slice(matchingDirs, func(i, j int) bool {
parts1 := strings.Split(matchingDirs[i], "/")
parts2 := strings.Split(matchingDirs[j], "/")
return len(parts1) < len(parts2)
})
// Copy the matching files and dirs to the final slices
files = append([]string{}, matchingFiles...)
dirs = append([]string{}, matchingDirs...)
return files, dirs
}
func scopedPathNameFilter(pathName string, scope string) string {
scope = strings.TrimPrefix(scope, "/")
if strings.HasPrefix(pathName, scope) {
pathName = strings.TrimPrefix(pathName, scope)
} else {
pathName = ""
}
return pathName
}
func containsSearchTerm(pathName string, searchTerm string) bool {
path := getLastPathComponent(pathName)
// Perform case-insensitive search
pathNameLower := strings.ToLower(path)
searchTermLower := strings.ToLower(searchTerm)
return strings.Contains(pathNameLower, searchTermLower)
}
func getLastPathComponent(path string) string {
// Use filepath.Base to extract the last component of the path
return filepath.Base(path)
}

View File

@ -7,8 +7,7 @@ import (
"strings" "strings"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/rules"
) )
type searchOptions struct { type searchOptions struct {
@ -17,6 +16,11 @@ type searchOptions struct {
Terms []string Terms []string
} }
func IndexedSearch(query string, scope string, files *[]string, dirs *[]string) ([]string, []string) {
*files, *dirs = SearchAllIndexes(query, scope, *files, *dirs)
return *files, *dirs
}
// Search searches for a query in a fs. // Search searches for a query in a fs.
func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error { func Search(fs afero.Fs, scope, query string, checker rules.Checker, found func(path string, f os.FileInfo) error) error {
search := parseSearch(query) search := parseSearch(query)

View File

@ -1,8 +1,8 @@
package settings package settings
import ( import (
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// UserDefaults is a type that holds the default values // UserDefaults is a type that holds the default values

View File

@ -4,7 +4,7 @@ import (
"crypto/rand" "crypto/rand"
"strings" "strings"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
) )
const DefaultUsersHomeBasePath = "/users" const DefaultUsersHomeBasePath = "/users"

View File

@ -1,9 +1,9 @@
package settings package settings
import ( import (
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// StorageBackend is a settings storage backend. // StorageBackend is a settings storage backend.

View File

@ -3,7 +3,7 @@ package share
import ( import (
"time" "time"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
) )
// StorageBackend is the interface to implement for a share storage. // StorageBackend is the interface to implement for a share storage.

View File

@ -3,9 +3,9 @@ package bolt
import ( import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
type authBackend struct { type authBackend struct {

View File

@ -3,11 +3,11 @@ package bolt
import ( import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/share" "github.com/gtsteffaniak/filebrowser/share"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// NewStorage creates a storage.Storage based on Bolt DB. // NewStorage creates a storage.Storage based on Bolt DB.

View File

@ -3,7 +3,7 @@ package bolt
import ( import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
) )
type settingsBackend struct { type settingsBackend struct {

View File

@ -11,10 +11,10 @@ import (
"github.com/pelletier/go-toml/v2" "github.com/pelletier/go-toml/v2"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
type oldDefs struct { type oldDefs struct {

View File

@ -3,7 +3,7 @@ package importer
import ( import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/storage/bolt" "github.com/gtsteffaniak/filebrowser/storage/bolt"
) )
// Import imports an old configuration to a newer database. // Import imports an old configuration to a newer database.

View File

@ -7,9 +7,9 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
bolt "go.etcd.io/bbolt" bolt "go.etcd.io/bbolt"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
"github.com/filebrowser/filebrowser/v2/storage" "github.com/gtsteffaniak/filebrowser/storage"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
type oldUser struct { type oldUser struct {

View File

@ -4,8 +4,8 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/asdine/storm/v3/q" "github.com/asdine/storm/v3/q"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/share" "github.com/gtsteffaniak/filebrowser/share"
) )
type shareBackend struct { type shareBackend struct {

View File

@ -6,8 +6,8 @@ import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
type usersBackend struct { type usersBackend struct {

View File

@ -3,7 +3,7 @@ package bolt
import ( import (
"github.com/asdine/storm/v3" "github.com/asdine/storm/v3"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
) )
func get(db *storm.DB, name string, to interface{}) error { func get(db *storm.DB, name string, to interface{}) error {

View File

@ -1,10 +1,10 @@
package storage package storage
import ( import (
"github.com/filebrowser/filebrowser/v2/auth" "github.com/gtsteffaniak/filebrowser/auth"
"github.com/filebrowser/filebrowser/v2/settings" "github.com/gtsteffaniak/filebrowser/settings"
"github.com/filebrowser/filebrowser/v2/share" "github.com/gtsteffaniak/filebrowser/share"
"github.com/filebrowser/filebrowser/v2/users" "github.com/gtsteffaniak/filebrowser/users"
) )
// Storage is a storage powered by a Backend which makes the necessary // Storage is a storage powered by a Backend which makes the necessary

View File

@ -1,4 +1,4 @@
module github.com/filebrowser/filebrowser/v2/tools module github.com/gtsteffaniak/filebrowser/tools
go 1.18 go 1.18

View File

@ -4,7 +4,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
) )
// StorageBackend is the interface to implement for a users storage. // StorageBackend is the interface to implement for a users storage.

View File

@ -6,9 +6,9 @@ import (
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/filebrowser/filebrowser/v2/errors" "github.com/gtsteffaniak/filebrowser/errors"
"github.com/filebrowser/filebrowser/v2/files" "github.com/gtsteffaniak/filebrowser/files"
"github.com/filebrowser/filebrowser/v2/rules" "github.com/gtsteffaniak/filebrowser/rules"
) )
// ViewMode describes a view mode. // ViewMode describes a view mode.

View File

@ -2,7 +2,7 @@ package version
var ( var (
// Version is the current File Browser version. // Version is the current File Browser version.
Version = "(untracked)" Version = "(0.1.0)"
// CommitSHA is the commmit sha. // CommitSHA is the commmit sha.
CommitSHA = "(unknown)" CommitSHA = "(unknown)"
) )

View File

@ -14,7 +14,7 @@
<input <input
type="text" type="text"
@keyup.exact="keyup" @keyup.exact="keyup"
@keyup.enter="submit" @input="submit"
ref="input" ref="input"
:autofocus="active" :autofocus="active"
v-model.trim="value" v-model.trim="value"
@ -47,7 +47,7 @@
</div> </div>
</template> </template>
</template> </template>
<ul v-show="results.length > 0"> <ul v-show="filteredResults.length > 0">
<li v-for="(s, k) in filteredResults" :key="k"> <li v-for="(s, k) in filteredResults" :key="k">
<router-link @click.native="close" :to="s.url"> <router-link @click.native="close" :to="s.url">
<i v-if="s.dir" class="material-icons">folder</i> <i v-if="s.dir" class="material-icons">folder</i>
@ -163,7 +163,7 @@ export default {
return; return;
} }
this.results.length = 0; this.results.length === 0;
}, },
init(string) { init(string) {
this.value = `${string} `; this.value = `${string} `;
@ -177,7 +177,7 @@ export default {
async submit(event) { async submit(event) {
event.preventDefault(); event.preventDefault();
if (this.value === "") { if (this.value === "" || this.value.length < 3) {
return; return;
} }

View File

@ -99,7 +99,7 @@
v-else v-else
rel="noopener noreferrer" rel="noopener noreferrer"
target="_blank" target="_blank"
href="https://github.com/filebrowser/filebrowser" href="https://github.com/gtsteffaniak/filebrowser"
>File Browser</a >File Browser</a
> >
<span> {{ version }}</span> <span> {{ version }}</span>
@ -156,8 +156,8 @@ export default {
try { try {
let usage = await api.usage(path); let usage = await api.usage(path);
usageStats = { usageStats = {
used: prettyBytes(usage.used, { binary: true }), used: prettyBytes(usage.used/1024, { binary: true }),
total: prettyBytes(usage.total, { binary: true }), total: prettyBytes(usage.total/1024, { binary: true }),
usedPercentage: Math.round((usage.used / usage.total) * 100), usedPercentage: Math.round((usage.used / usage.total) * 100),
}; };
} catch (error) { } catch (error) {

View File

@ -152,7 +152,7 @@
"images": "الصور", "images": "الصور",
"music": "الموسيقى", "music": "الموسيقى",
"pdf": "PDF", "pdf": "PDF",
"pressToSearch": "Press enter to search...", "pressToSearch": "No results found in indexed search.",
"search": "البحث...", "search": "البحث...",
"typeToSearch": "Type to search...", "typeToSearch": "Type to search...",
"types": "الأنواع", "types": "الأنواع",

View File

@ -162,7 +162,7 @@
"images": "Images", "images": "Images",
"music": "Music", "music": "Music",
"pdf": "PDF", "pdf": "PDF",
"pressToSearch": "Press enter to search...", "pressToSearch": "No results found in indexed search.",
"search": "Search...", "search": "Search...",
"typeToSearch": "Type to search...", "typeToSearch": "Type to search...",
"types": "Types", "types": "Types",

View File

@ -152,7 +152,7 @@
"images": "画像", "images": "画像",
"music": "音楽", "music": "音楽",
"pdf": "PDF", "pdf": "PDF",
"pressToSearch": "Press enter to search...", "pressToSearch": "No results found in indexed search.",
"search": "検索...", "search": "検索...",
"typeToSearch": "Type to search...", "typeToSearch": "Type to search...",
"types": "種類", "types": "種類",