Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ The test script will always output coverage information when run. To check code
make cover
```

# Generated code

**NEVER edit generated files directly.** The TypeScript API SDK in `api/ts/generated/` and `api/ts/dist/` is auto-generated from Go swagger annotations. To update it:

1. Make changes to the Go source code (structs, swagger annotations, etc.)
2. Run `make swag` to regenerate the TypeScript API SDK

# Code style and linting

Weblens follows standard Go code style conventions. To ensure your code adheres to these conventions, please run the following commands after making changes to go code:
Expand Down
3 changes: 3 additions & 0 deletions api/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2264,11 +2264,14 @@ components:
example:
auth.allow_registrations: true
media.hdir_processing_enabled: true
webdav.enabled: true
properties:
auth.allow_registrations:
type: boolean
media.hdir_processing_enabled:
type: boolean
webdav.enabled:
type: boolean
type: object
CreateFolderBody:
example:
Expand Down
26 changes: 26 additions & 0 deletions api/docs/Bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**AuthAllowRegistrations** | Pointer to **bool** | | [optional]
**MediaHdirProcessingEnabled** | Pointer to **bool** | | [optional]
**WebdavEnabled** | Pointer to **bool** | | [optional]

## Methods

Expand Down Expand Up @@ -76,6 +77,31 @@ SetMediaHdirProcessingEnabled sets MediaHdirProcessingEnabled field to given val

HasMediaHdirProcessingEnabled returns a boolean if a field has been set.

### GetWebdavEnabled

`func (o *Bundle) GetWebdavEnabled() bool`

GetWebdavEnabled returns the WebdavEnabled field if non-nil, zero value otherwise.

### GetWebdavEnabledOk

`func (o *Bundle) GetWebdavEnabledOk() (*bool, bool)`

GetWebdavEnabledOk returns a tuple with the WebdavEnabled field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetWebdavEnabled

`func (o *Bundle) SetWebdavEnabled(v bool)`

SetWebdavEnabled sets WebdavEnabled field to given value.

### HasWebdavEnabled

`func (o *Bundle) HasWebdavEnabled() bool`

HasWebdavEnabled returns a boolean if a field has been set.


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
36 changes: 36 additions & 0 deletions api/model_bundle.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/ts/dist/AllApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ interface BackupInfo {
interface Bundle {
'auth.allow_registrations'?: boolean;
'media.hdir_processing_enabled'?: boolean;
'webdav.enabled'?: boolean;
}
interface CreateFolderBody {
'children'?: Array<string>;
Expand Down
1 change: 1 addition & 0 deletions api/ts/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export interface BackupInfo {
export interface Bundle {
'auth.allow_registrations'?: boolean;
'media.hdir_processing_enabled'?: boolean;
'webdav.enabled'?: boolean;
}
export interface CreateFolderBody {
'children'?: Array<string>;
Expand Down
2 changes: 2 additions & 0 deletions api/ts/generated/docs/Bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**auth_allow_registrations** | **boolean** | | [optional] [default to undefined]
**media_hdir_processing_enabled** | **boolean** | | [optional] [default to undefined]
**webdav_enabled** | **boolean** | | [optional] [default to undefined]

## Example

Expand All @@ -16,6 +17,7 @@ import { Bundle } from './api';
const instance: Bundle = {
auth_allow_registrations,
media_hdir_processing_enabled,
webdav_enabled,
};
```

Expand Down
2 changes: 1 addition & 1 deletion cmd/weblens/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func main() {
cnf.DoFileDiscovery = true

// Initialize logger
logger := log.NewZeroLogger()
logger := log.NewZeroLogger(log.CreateOpts{Level: cnf.LogLevel})

// Capture interrupt signals to allow for graceful shutdown.
// The returned context will be canceled on interrupt.
Expand Down
3 changes: 3 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3081,6 +3081,9 @@ const docTemplate = `{
},
"media.hdir_processing_enabled": {
"type": "boolean"
},
"webdav.enabled": {
"type": "boolean"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3079,6 +3079,9 @@
},
"media.hdir_processing_enabled": {
"type": "boolean"
},
"webdav.enabled": {
"type": "boolean"
}
}
},
Expand Down
2 changes: 2 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ definitions:
type: boolean
media.hdir_processing_enabled:
type: boolean
webdav.enabled:
type: boolean
type: object
CreateFolderBody:
properties:
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/gorilla/websocket v1.5.3
github.com/joho/godotenv v1.5.1
github.com/lithammer/fuzzysearch v1.1.8
github.com/pkg/errors v0.9.1
github.com/posener/wstest v1.2.0
github.com/rs/zerolog v1.33.0
github.com/saracen/fastzip v0.1.11
Expand All @@ -20,7 +19,8 @@ require (
github.com/u2takey/ffmpeg-go v0.5.0
github.com/viccon/sturdyc v1.1.5
go.mongodb.org/mongo-driver v1.17.2
golang.org/x/crypto v0.32.0
golang.org/x/crypto v0.48.0
golang.org/x/net v0.50.0
)

replace github.com/ethanrous/weblens/api v0.0.0 => ./api/
Expand Down Expand Up @@ -51,9 +51,9 @@ require (
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/tools v0.41.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 14 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8
github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
github.com/panjf2000/ants/v2 v2.4.2/go.mod h1:f6F0NZVFsGCp5A7QW/Zj/m92atWwOkY0OIhFxRNFr4A=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -123,26 +122,26 @@ gocv.io/x/gocv v0.25.0/go.mod h1:Rar2PS6DV+T4FL+PM535EImD/h13hGVaHhnCu1xarBs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
golang.org/x/net v0.50.0/go.mod h1:UgoSli3F/pBgdJBHCTc+tp3gmrU4XswgGRgtnwWTfyM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -155,8 +154,8 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
Expand All @@ -167,16 +166,16 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk=
golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand Down
3 changes: 3 additions & 0 deletions models/featureflags/feature_flag_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ const (
AllowRegistrations FlagKey = "auth.allow_registrations"
// EnableHDIR controls whether HDIR (high-dynamic-range image rendering) is enabled.
EnableHDIR FlagKey = "media.hdir_processing_enabled"
// EnableWebDAV controls whether WebDAV file access is enabled.
EnableWebDAV FlagKey = "webdav.enabled"
)

// Bundle represents the application feature flag document.
type Bundle struct {
AllowRegistrations bool `bson:"auth.allow_registrations" json:"auth.allow_registrations"`
EnableHDIR bool `bson:"media.hdir_processing_enabled" json:"media.hdir_processing_enabled"`
EnableWebDAV bool `bson:"webdav.enabled" json:"webdav.enabled"`
} // @name Bundle

// Default returns the default flags
Expand Down
19 changes: 18 additions & 1 deletion models/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ type WeblensFileImpl struct {
// size in bytes of the file on the disk
size atomic.Int64

// writeHead is the current offset for read/write operations on the file. This is used to keep track of where the next read/write should occur.
writeHead int64

// writeHeadLock is a RWMutex to protect concurrent access to the writeHead field.
writeHeadLock sync.RWMutex

// If this file is a directory, these are the files that are housed by this directory.
childLock sync.RWMutex

Expand Down Expand Up @@ -333,7 +337,17 @@ func (f *WeblensFileImpl) Read(p []byte) (n int, err error) {

fp, err := os.Open(f.portablePath.ToAbsolute())
if err != nil {
return 0, err
return -1, err
}

defer fp.Close() //nolint:errcheck

f.writeHeadLock.RLock()
defer f.writeHeadLock.RUnlock()

_, err = fp.Seek(f.writeHead, io.SeekStart)
if err != nil {
return -1, err
}

return fp.Read(p)
Expand Down Expand Up @@ -363,6 +377,9 @@ func (f *WeblensFileImpl) Readdir(count int) ([]fs.FileInfo, error) {

// Seek sets the offset for the next read or write operation.
func (f *WeblensFileImpl) Seek(offset int64, whence int) (int64, error) {
f.writeHeadLock.Lock()
defer f.writeHeadLock.Unlock()

switch whence {
case io.SeekStart:
f.writeHead = offset
Expand Down
12 changes: 11 additions & 1 deletion modules/cryptography/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import (
const BcryptDifficultyCtxKey = "bcryptDifficulty"
const bcryptDefaultDifficulty = 11

// HashUserPasswordDifficulty hashes a user password using bcrypt with the specified difficulty level.
func HashUserPasswordDifficulty(password string, difficulty int) ([]byte, error) {
difficulty = max(difficulty, bcrypt.MinCost)

return bcrypt.GenerateFromPassword([]byte(password), difficulty)
}

// HashUserPassword hashes a user password using bcrypt.
func HashUserPassword(ctx context.Context, password string) (string, error) {
// For testing, we can set the bcrypt difficulty in the context
Expand All @@ -23,7 +30,10 @@ func HashUserPassword(ctx context.Context, password string) (string, error) {
bcryptDifficulty = bcryptDefaultDifficulty
}

passHashBytes, err := bcrypt.GenerateFromPassword([]byte(password), bcryptDifficulty)
passHashBytes, err := HashUserPasswordDifficulty(password, bcryptDifficulty)
if err != nil {
return "", err
}

return string(passHashBytes), err
}
Expand Down
Loading
Loading