Skip to content

Commit 38adbf6

Browse files
authored
Clear temp dir (#506)
1 parent 94e4d59 commit 38adbf6

File tree

15 files changed

+14
-266
lines changed

15 files changed

+14
-266
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ All notable changes to this project will be documented in this file. For commit
66

77
**Notes**:
88
- added full tests for single source example.
9-
- adds descriptive error if temp dir can't be created
9+
- adds descriptive error if temp dir can't be created on fatal startup
1010
- clears temp directory on shutdown.
11+
- removed put settings api (unused)
12+
- removed more unused config properties.
1113

1214
**BugFixes**:
1315
- fix url encoding issue for search links when theres only one source https://github.com/gtsteffaniak/filebrowser/issues/501

backend/http/router.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func StartHttp(ctx context.Context, Service ImgService, storage *storage.Storage
114114

115115
// Settings routes
116116
api.HandleFunc("GET /settings", withAdmin(settingsGetHandler))
117-
api.HandleFunc("PUT /settings", withAdmin(settingsPutHandler))
118117

119118
api.HandleFunc("GET /onlyoffice/config", withUser(onlyofficeClientConfigGetHandler))
120119
api.HandleFunc("POST /onlyoffice/callback", withUser(onlyofficeCallbackHandler))

backend/http/settings.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
package http
22

33
import (
4-
"encoding/json"
54
"net/http"
6-
7-
"github.com/gtsteffaniak/filebrowser/backend/settings"
85
)
96

10-
type settingsData struct {
11-
Signup bool `json:"signup"`
12-
CreateUserDir bool `json:"createUserDir"`
13-
UserHomeBasePath string `json:"userHomeBasePath"`
14-
Defaults settings.UserDefaults `json:"defaults"`
15-
Frontend settings.Frontend `json:"frontend"`
16-
}
17-
187
// settingsGetHandler retrieves the current system settings.
198
// @Summary Get system settings
209
// @Description Returns the current configuration settings for signup, user directories, rules, frontend.
@@ -45,29 +34,3 @@ func settingsGetHandler(w http.ResponseWriter, r *http.Request, d *requestContex
4534
}
4635
return renderJSON(w, r, config)
4736
}
48-
49-
// settingsPutHandler updates the system settings.
50-
// @Summary Update system settings
51-
// @Description Updates the system configuration settings for signup, user directories, rules, frontend.
52-
// @Tags Settings
53-
// @Accept json
54-
// @Produce json
55-
// @Param body body settingsData true "Settings data to update"
56-
// @Success 200 "Settings updated successfully"
57-
// @Failure 400 {object} map[string]string "Bad request - failed to decode body"
58-
// @Failure 500 {object} map[string]string "Internal server error"
59-
// @Router /api/settings [put]
60-
func settingsPutHandler(w http.ResponseWriter, r *http.Request, d *requestContext) (int, error) {
61-
req := &settingsData{}
62-
err := json.NewDecoder(r.Body).Decode(req)
63-
if err != nil {
64-
return http.StatusBadRequest, err
65-
}
66-
67-
config.Server.UserHomeBasePath = req.UserHomeBasePath
68-
config.UserDefaults = req.Defaults
69-
config.Frontend = req.Frontend
70-
config.Auth.Signup = req.Signup
71-
err = store.Settings.Save(config)
72-
return errToStatus(err), err
73-
}

backend/http/static.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ import (
55
"fmt"
66
"io/fs"
77
"net/http"
8-
"os"
9-
"path/filepath"
108
"strings"
119
"text/template"
1210

1311
"github.com/gtsteffaniak/filebrowser/backend/auth"
14-
"github.com/gtsteffaniak/filebrowser/backend/logger"
1512
"github.com/gtsteffaniak/filebrowser/backend/settings"
1613
"github.com/gtsteffaniak/filebrowser/backend/version"
1714
)
@@ -47,7 +44,6 @@ func handleWithStaticData(w http.ResponseWriter, r *http.Request, file, contentT
4744
"DisableExternal": config.Frontend.DisableDefaultLinks,
4845
"DisableUsedPercentage": config.Frontend.DisableUsedPercentage,
4946
"darkMode": settings.Config.UserDefaults.DarkMode,
50-
"Color": config.Frontend.Color,
5147
"BaseURL": config.Server.BaseURL,
5248
"Version": version.Version,
5349
"CommitSHA": version.CommitSHA,
@@ -68,19 +64,6 @@ func handleWithStaticData(w http.ResponseWriter, r *http.Request, file, contentT
6864
"SourceCount": len(config.Server.Sources),
6965
}
7066

71-
if config.Frontend.Files != "" {
72-
fPath := filepath.Join(config.Frontend.Files, "custom.css")
73-
_, err := os.Stat(fPath) //nolint:govet
74-
75-
if err != nil && !os.IsNotExist(err) {
76-
logger.Error(fmt.Sprintf("couldn't load custom styles: %v", err))
77-
}
78-
79-
if err == nil {
80-
data["CSS"] = true
81-
}
82-
}
83-
8467
if config.Auth.Methods.PasswordAuth.Enabled {
8568
raw, err := store.Auth.Get("password") //nolint:govet
8669
if err != nil {

backend/settings/storage.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ func (s *Storage) Get() (*Settings, error) {
2828
if err != nil {
2929
return nil, err
3030
}
31-
if set.Server.UserHomeBasePath == "" {
32-
set.Server.UserHomeBasePath = DefaultUsersHomeBasePath
33-
}
3431
return set, nil
3532
}
3633

backend/settings/structs.go

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,20 @@ const (
1313
)
1414

1515
type Settings struct {
16-
Commands map[string][]string `json:"commands"`
17-
Shell []string `json:"shell"`
18-
Server Server `json:"server"`
19-
Auth Auth `json:"auth"`
20-
Frontend Frontend `json:"frontend"`
21-
Users []UserDefaults `json:"users,omitempty"`
22-
UserDefaults UserDefaults `json:"userDefaults"`
23-
Integrations Integrations `json:"integrations"`
16+
Server Server `json:"server"`
17+
Auth Auth `json:"auth"`
18+
Frontend Frontend `json:"frontend"`
19+
Users []UserDefaults `json:"users,omitempty"`
20+
UserDefaults UserDefaults `json:"userDefaults"`
21+
Integrations Integrations `json:"integrations"`
2422
}
2523

2624
type Auth struct {
2725
TokenExpirationHours int `json:"tokenExpirationHours"`
2826
Recaptcha Recaptcha `json:"recaptcha"`
2927
Methods LoginMethods `json:"methods"`
30-
Command string `json:"command"`
3128
Signup bool `json:"signup"`
3229
Method string `json:"method"`
33-
Shell string `json:"shell"`
3430
Key []byte `json:"key"`
3531
AdminUsername string `json:"adminUsername"`
3632
AdminPassword string `json:"adminPassword"`
@@ -73,17 +69,15 @@ type Server struct {
7369
BaseURL string `json:"baseURL"`
7470
Logging []LogConfig `json:"logging"`
7571
Database string `json:"database"`
76-
Root string `json:"root"` // deprecated, use sources
77-
UserHomeBasePath string `json:"userHomeBasePath"`
7872
Sources []Source `json:"sources"`
7973
ExternalUrl string `json:"externalUrl"`
8074
InternalUrl string `json:"internalUrl"` // used by integrations
8175
CacheDir string `json:"cacheDir"`
8276
MaxArchiveSizeGB int64 `json:"maxArchiveSize"`
8377
// not exposed to config
84-
SourceMap map[string]Source // uses realpath as key
85-
NameToSource map[string]Source // uses name as key
86-
DefaultSource Source
78+
SourceMap map[string]Source `json:"-"` // uses realpath as key
79+
NameToSource map[string]Source `json:"-"` // uses name as key
80+
DefaultSource Source `json:"-"`
8781
}
8882

8983
type Integrations struct {
@@ -135,8 +129,6 @@ type Frontend struct {
135129
Name string `json:"name"`
136130
DisableDefaultLinks bool `json:"disableDefaultLinks"`
137131
DisableUsedPercentage bool `json:"disableUsedPercentage"`
138-
Files string `json:"files"`
139-
Color string `json:"color"`
140132
ExternalLinks []ExternalLink `json:"externalLinks"`
141133
}
142134

backend/swagger/docs/docs.go

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -917,53 +917,6 @@ const docTemplate = `{
917917
}
918918
}
919919
}
920-
},
921-
"put": {
922-
"description": "Updates the system configuration settings for signup, user directories, rules, frontend.",
923-
"consumes": [
924-
"application/json"
925-
],
926-
"produces": [
927-
"application/json"
928-
],
929-
"tags": [
930-
"Settings"
931-
],
932-
"summary": "Update system settings",
933-
"parameters": [
934-
{
935-
"description": "Settings data to update",
936-
"name": "body",
937-
"in": "body",
938-
"required": true,
939-
"schema": {
940-
"$ref": "#/definitions/http.settingsData"
941-
}
942-
}
943-
],
944-
"responses": {
945-
"200": {
946-
"description": "Settings updated successfully"
947-
},
948-
"400": {
949-
"description": "Bad request - failed to decode body",
950-
"schema": {
951-
"type": "object",
952-
"additionalProperties": {
953-
"type": "string"
954-
}
955-
}
956-
},
957-
"500": {
958-
"description": "Internal server error",
959-
"schema": {
960-
"type": "object",
961-
"additionalProperties": {
962-
"type": "string"
963-
}
964-
}
965-
}
966-
}
967920
}
968921
},
969922
"/api/share": {
@@ -1784,9 +1737,6 @@ const docTemplate = `{
17841737
"settings.Frontend": {
17851738
"type": "object",
17861739
"properties": {
1787-
"color": {
1788-
"type": "string"
1789-
},
17901740
"disableDefaultLinks": {
17911741
"type": "boolean"
17921742
},
@@ -1799,9 +1749,6 @@ const docTemplate = `{
17991749
"$ref": "#/definitions/settings.ExternalLink"
18001750
}
18011751
},
1802-
"files": {
1803-
"type": "string"
1804-
},
18051752
"name": {
18061753
"type": "string"
18071754
}

backend/swagger/docs/swagger.json

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -906,53 +906,6 @@
906906
}
907907
}
908908
}
909-
},
910-
"put": {
911-
"description": "Updates the system configuration settings for signup, user directories, rules, frontend.",
912-
"consumes": [
913-
"application/json"
914-
],
915-
"produces": [
916-
"application/json"
917-
],
918-
"tags": [
919-
"Settings"
920-
],
921-
"summary": "Update system settings",
922-
"parameters": [
923-
{
924-
"description": "Settings data to update",
925-
"name": "body",
926-
"in": "body",
927-
"required": true,
928-
"schema": {
929-
"$ref": "#/definitions/http.settingsData"
930-
}
931-
}
932-
],
933-
"responses": {
934-
"200": {
935-
"description": "Settings updated successfully"
936-
},
937-
"400": {
938-
"description": "Bad request - failed to decode body",
939-
"schema": {
940-
"type": "object",
941-
"additionalProperties": {
942-
"type": "string"
943-
}
944-
}
945-
},
946-
"500": {
947-
"description": "Internal server error",
948-
"schema": {
949-
"type": "object",
950-
"additionalProperties": {
951-
"type": "string"
952-
}
953-
}
954-
}
955-
}
956909
}
957910
},
958911
"/api/share": {
@@ -1773,9 +1726,6 @@
17731726
"settings.Frontend": {
17741727
"type": "object",
17751728
"properties": {
1776-
"color": {
1777-
"type": "string"
1778-
},
17791729
"disableDefaultLinks": {
17801730
"type": "boolean"
17811731
},
@@ -1788,9 +1738,6 @@
17881738
"$ref": "#/definitions/settings.ExternalLink"
17891739
}
17901740
},
1791-
"files": {
1792-
"type": "string"
1793-
},
17941741
"name": {
17951742
"type": "string"
17961743
}

backend/swagger/docs/swagger.yaml

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ definitions:
117117
type: object
118118
settings.Frontend:
119119
properties:
120-
color:
121-
type: string
122120
disableDefaultLinks:
123121
type: boolean
124122
disableUsedPercentage:
@@ -127,8 +125,6 @@ definitions:
127125
items:
128126
$ref: '#/definitions/settings.ExternalLink'
129127
type: array
130-
files:
131-
type: string
132128
name:
133129
type: string
134130
type: object
@@ -900,38 +896,6 @@ paths:
900896
summary: Get system settings
901897
tags:
902898
- Settings
903-
put:
904-
consumes:
905-
- application/json
906-
description: Updates the system configuration settings for signup, user directories,
907-
rules, frontend.
908-
parameters:
909-
- description: Settings data to update
910-
in: body
911-
name: body
912-
required: true
913-
schema:
914-
$ref: '#/definitions/http.settingsData'
915-
produces:
916-
- application/json
917-
responses:
918-
"200":
919-
description: Settings updated successfully
920-
"400":
921-
description: Bad request - failed to decode body
922-
schema:
923-
additionalProperties:
924-
type: string
925-
type: object
926-
"500":
927-
description: Internal server error
928-
schema:
929-
additionalProperties:
930-
type: string
931-
type: object
932-
summary: Update system settings
933-
tags:
934-
- Settings
935899
/api/share:
936900
get:
937901
consumes:

0 commit comments

Comments
 (0)