Skip to content

Commit

Permalink
feat: add support for google drive and dropbox (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovehunter9 authored Feb 24, 2025
1 parent 54a7a95 commit 579eb2b
Show file tree
Hide file tree
Showing 17 changed files with 3,722 additions and 706 deletions.
1 change: 0 additions & 1 deletion .github/workflows/update-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ jobs:
# tags: beclab/files-server:${{ github.event.inputs.tags }}
tags: beclab/files-server:${{ steps.get-latest-tag.outputs.tag }}
platforms: linux/amd64,linux/arm64

15 changes: 9 additions & 6 deletions packages/backend/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,20 @@ user created with the credentials from options "username" and "password".`,
imgSvc := img.New(workersCount)

var fileCache diskcache.Interface = diskcache.NewNoOp()
cacheDir, err := cmd.Flags().GetString("cache-dir")
checkErr(err)
if cacheDir != "" {
if err := os.MkdirAll(cacheDir, 0700); err != nil { //nolint:govet,gomnd
log.Fatalf("can't make directory %s: %s", cacheDir, err)
// cacheDir, err := cmd.Flags().GetString("cache-dir")
//cacheDir := "/data/file_cache"
//checkErr(err)
if diskcache.CacheDir != "" {
if err := os.MkdirAll(diskcache.CacheDir, 0700); err != nil { //nolint:govet,gomnd
log.Fatalf("can't make directory %s: %s", diskcache.CacheDir, err)
}
fileCache = diskcache.New(afero.NewOsFs(), cacheDir)
fileCache = diskcache.New(afero.NewOsFs(), diskcache.CacheDir)
}

// my_redis for watcher
my_redis.InitRedis()
my_redis.InitFolderAndRedis()
go my_redis.StartDailyCleanup()

// rpcServer for zinc
var wg sync.WaitGroup
Expand Down
9 changes: 6 additions & 3 deletions packages/backend/diskcache/file_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import (
"encoding/hex"
"errors"
"fmt"
"github.com/spf13/afero"
"io"
"os"
"path/filepath"
"sync"

"github.com/spf13/afero"
)

var CacheDir = "/data/file_cache"

type FileCache struct {
fs afero.Fs

Expand All @@ -37,6 +38,7 @@ func (f *FileCache) Store(ctx context.Context, key string, value []byte) error {
defer mu.Unlock()

fileName := f.getFileName(key)
fmt.Println("key: ", key, " fileName: ", fileName, " filePath: ", filepath.Dir(fileName))
if err := f.fs.MkdirAll(filepath.Dir(fileName), 0700); err != nil { //nolint:gomnd
return err
}
Expand Down Expand Up @@ -106,5 +108,6 @@ func (f *FileCache) getFileName(key string) string {
hasher := sha1.New() //nolint:gosec
_, _ = hasher.Write([]byte(key))
hash := hex.EncodeToString(hasher.Sum(nil))
return fmt.Sprintf("%s/%s/%s", hash[:1], hash[1:3], hash)
//return fmt.Sprintf("%s/%s/%s", hash[:1], hash[1:3], hash)
return hash
}
1 change: 1 addition & 0 deletions packages/backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/mholt/archiver/v3 v3.5.1
github.com/mitchellh/go-homedir v1.1.0
github.com/nats-io/nats.go v1.38.0
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/pelletier/go-toml/v2 v2.2.3
github.com/rs/zerolog v1.33.0
github.com/shirou/gopsutil/v3 v3.24.5
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ github.com/nats-io/nkeys v0.4.9 h1:qe9Faq2Gxwi6RZnZMXfmGMZkg3afLLOtrU+gDZJ35b0=
github.com/nats-io/nkeys v0.4.9/go.mod h1:jcMqs+FLG+W5YO36OX6wFIFcmpdAns+w1Wm6D3I/evE=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/nwaples/rardecode v1.1.0/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9lEc=
github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0=
Expand Down
401 changes: 0 additions & 401 deletions packages/backend/go.work.sum

Large diffs are not rendered by default.

Loading

0 comments on commit 579eb2b

Please sign in to comment.