Skip to content

Commit f867716

Browse files
authored
More small fixes (#765)
1 parent 455ef2e commit f867716

File tree

12 files changed

+40
-55
lines changed

12 files changed

+40
-55
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. For commit
99
- oidc groups header updates admin permission of existing user (either add/remove if role exists)'
1010
- builds amd64 binary with musl for compatibility (glic error) https://github.com/gtsteffaniak/filebrowser/issues/755
1111
- renamed `server.sources.config.disabled` to `server.sources.config.disableIndexing`
12+
- better support for running with disabled index.
1213
- small indexing behavior tweaks.
1314
- markdown viewer hides sidebar https://github.com/gtsteffaniak/filebrowser/issues/744
1415

@@ -17,6 +18,8 @@ All notable changes to this project will be documented in this file. For commit
1718
- search result links not working with custom baseUrl https://github.com/gtsteffaniak/filebrowser/issues/746
1819
- preview error for office native preview https://github.com/gtsteffaniak/filebrowser/issues/744
1920
- more source name safety for special characters.
21+
- shares with special character errors https://github.com/gtsteffaniak/filebrowser/issues/753
22+
- backspace navigates back a page when typing https://github.com/gtsteffaniak/filebrowser/issues/663
2023

2124
## v0.7.8-beta
2225

backend/http/raw.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ func setContentDisposition(w http.ResponseWriter, r *http.Request, fileName stri
4444
// @Failure 500 {object} map[string]string "Internal server error"
4545
// @Router /api/raw [get]
4646
func rawHandler(w http.ResponseWriter, r *http.Request, d *requestContext) (int, error) {
47-
encodedFiles := r.URL.Query().Get("files")
48-
// Decode the URL-encoded path
49-
files, err := url.QueryUnescape(encodedFiles)
50-
if err != nil {
51-
return http.StatusBadRequest, fmt.Errorf("invalid path encoding: %v", err)
52-
}
47+
files := r.URL.Query().Get("files")
5348
fileList := strings.Split(files, "||")
5449
return rawFilesHandler(w, r, d, fileList)
5550
}
@@ -188,8 +183,9 @@ func rawFilesHandler(w http.ResponseWriter, r *http.Request, d *requestContext,
188183

189184
firstFileSource := splitFile[0]
190185
firstFilePath := splitFile[1]
191-
fileName := filepath.Base(firstFilePath)
186+
// decode url encoded source name
192187
var err error
188+
fileName := filepath.Base(firstFilePath)
193189
userscope := "/"
194190
if d.user.Username != "publicUser" {
195191
userscope, err = settings.GetScopeFromSourceName(d.user.Scopes, firstFileSource)
@@ -323,11 +319,11 @@ func computeArchiveSize(fileList []string, d *requestContext) (int64, error) {
323319
}
324320
source := splitFile[0]
325321
path := splitFile[1]
322+
var err error
326323
idx := indexing.GetIndex(source)
327324
if idx == nil {
328325
return 0, fmt.Errorf("source %s is not available", source)
329326
}
330-
var err error
331327
userScope := "/"
332328
if d.user.Username != "publicUser" {
333329
userScope, err = settings.GetScopeFromSourceName(d.user.Scopes, source)
@@ -342,7 +338,10 @@ func computeArchiveSize(fileList []string, d *requestContext) (int64, error) {
342338
indexPath := idx.MakeIndexPath(realPath)
343339
info, ok := idx.GetReducedMetadata(indexPath, isDir)
344340
if !ok {
345-
return 0, fmt.Errorf("failed to get metadata info for %s", path)
341+
info, err = idx.GetFsDirInfo(indexPath)
342+
if err != nil {
343+
return 0, fmt.Errorf("failed to get file info for %s : %v", path, err)
344+
}
346345
}
347346
estimatedSize += info.Size
348347
}

backend/http/resource.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ func resourceGetHandler(w http.ResponseWriter, r *http.Request, d *requestContex
4141
source := r.URL.Query().Get("source")
4242
if source == "" {
4343
source = config.Server.DefaultSource.Name
44-
} else {
45-
var err error
46-
// decode url encoded source name
47-
source, err = url.QueryUnescape(source)
48-
if err != nil {
49-
return http.StatusBadRequest, fmt.Errorf("invalid source encoding: %v", err)
50-
}
5144
}
5245
// Decode the URL-encoded path
5346
path, err := url.QueryUnescape(encodedPath)

backend/http/search.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ func searchHandler(w http.ResponseWriter, r *http.Request, d *requestContext) (i
7878
return http.StatusForbidden, err
7979
}
8080
combinedPath := index.MakeIndexPath(filepath.Join(userscope, searchScope))
81+
combinedPath = strings.TrimSuffix(combinedPath, "/") + "/" // Ensure trailing slash
8182
// Perform the search using the provided query and user scope
8283
response := index.Search(query, combinedPath, sessionId)
8384
for i := range response {
8485
// Remove the user scope from the path
85-
response[i].Path = strings.TrimPrefix(response[i].Path, userscope)
86+
response[i].Path = strings.TrimPrefix(response[i].Path, combinedPath)
8687
if response[i].Path == "" {
8788
response[i].Path = "/"
8889
}

backend/http/share.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ func shareGetHandler(w http.ResponseWriter, r *http.Request, d *requestContext)
6969
source := r.URL.Query().Get("source")
7070
if source == "" {
7171
source = settings.Config.Server.DefaultSource.Name
72-
} else {
73-
var err error
74-
// decode url encoded source name
75-
source, err = url.QueryUnescape(source)
76-
if err != nil {
77-
return http.StatusBadRequest, fmt.Errorf("invalid source encoding: %v", err)
78-
}
7972
}
8073
// Decode the URL-encoded path
8174
path, err := url.QueryUnescape(encodedPath)
@@ -199,13 +192,6 @@ func sharePostHandler(w http.ResponseWriter, r *http.Request, d *requestContext)
199192
sourceName := r.URL.Query().Get("source")
200193
if sourceName == "" {
201194
sourceName = config.Server.DefaultSource.Name
202-
} else {
203-
var err error
204-
// decode url encoded source name
205-
sourceName, err = url.QueryUnescape(sourceName)
206-
if err != nil {
207-
return http.StatusBadRequest, fmt.Errorf("invalid source encoding: %v", err)
208-
}
209195
}
210196
source := config.Server.NameToSource[sourceName]
211197

backend/indexing/indexingFiles.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ func (idx *Index) GetFsDirInfo(adjustedPath string) (*iteminfo.FileInfo, error)
179179
if err != nil {
180180
return nil, err
181181
}
182-
fmt.Println(dir.Name())
183182
combinedPath := adjustedPath + "/"
184183
if adjustedPath == "/" {
185184
combinedPath = "/"

frontend/src/api/files.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function fetchFiles(url, content = false) {
1010
const result = extractSourceFromPath(url)
1111
const apiPath = getApiPath('api/resources', {
1212
path: encodeURIComponent(result.path),
13-
source: result.source,
13+
source: encodeURIComponent(result.source),
1414
...(content && { content: 'true' })
1515
})
1616
const res = await fetchURL(apiPath)
@@ -26,7 +26,7 @@ export async function fetchFiles(url, content = false) {
2626
async function resourceAction(url, method, content) {
2727
try {
2828
const result = extractSourceFromPath(url)
29-
let source = result.source
29+
let source = encodeURIComponent(result.source)
3030
let path = result.path
3131
let opts = { method }
3232
if (content) {
@@ -69,14 +69,13 @@ export function download(format, files) {
6969
if (format !== 'zip') {
7070
format = 'tar.gz'
7171
}
72-
7372
let fileargs = ''
7473
if (files.length === 1) {
75-
const result = extractSourceFromPath(decodeURI(files[0]))
74+
const result = extractSourceFromPath(decodeURIComponent(files[0]))
7675
fileargs = result.source + '::' + result.path + '||'
7776
} else {
7877
for (let file of files) {
79-
const result = extractSourceFromPath(decodeURI(file))
78+
const result = extractSourceFromPath(decodeURIComponent(file))
8079
fileargs += result.source + '::' + result.path + '||'
8180
}
8281
}
@@ -110,7 +109,7 @@ export async function post(url, content = '', overwrite = false, onupload) {
110109

111110
const apiPath = getApiPath('api/resources', {
112111
path: result.path,
113-
source: result.source,
112+
source: encodeURIComponent(result.source),
114113
override: overwrite
115114
})
116115
return new Promise((resolve, reject) => {
@@ -164,7 +163,7 @@ export async function moveCopy(
164163
const toResult = extractSourceFromPath(item.to)
165164
let localParams = {
166165
...params,
167-
destination: toResult.source + '::' + toResult.path,
166+
destination: encodeURIComponent(toResult.source) + '::' + toResult.path,
168167
from: fromResult.source + '::' + fromResult.path
169168
}
170169
const apiPath = getApiPath('api/resources', localParams)
@@ -189,12 +188,11 @@ export async function moveCopy(
189188
}
190189
}
191190

192-
export async function checksum(url, algo) {
191+
export async function checksum(source, path, algo) {
193192
try {
194-
const result = extractSourceFromPath(url)
195193
const params = {
196-
path: encodeURIComponent(result.path),
197-
source: result.source,
194+
path: encodeURIComponent(path),
195+
source: encodeURIComponent(source),
198196
checksum: algo
199197
}
200198
const apiPath = getApiPath('api/resources', params)
@@ -210,7 +208,7 @@ export async function checksum(url, algo) {
210208
export function getDownloadURL(source, path, inline, useExternal) {
211209
try {
212210
const params = {
213-
files: source + '::' + encodeURIComponent(path),
211+
files: encodeURIComponent(source) + '::' + encodeURIComponent(path),
214212
...(inline && { inline: 'true' })
215213
}
216214
const apiPath = getApiPath('api/raw', params)
@@ -230,7 +228,7 @@ export function getPreviewURL(source, path, modified) {
230228
const params = {
231229
path: encodeURIComponent(path),
232230
key: Date.parse(modified), // Use modified date as cache key
233-
source: source,
231+
source: encodeURIComponent(source),
234232
inline: 'true'
235233
}
236234
const apiPath = getApiPath('api/preview', params)

frontend/src/api/share.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export async function list() {
1010

1111
export async function get(path, source) {
1212
try {
13-
const params = { path, source };
13+
const params = { path: encodeURIComponent(path), source: encodeURIComponent(source) };
1414
const apiPath = getApiPath("api/share",params);
1515
let data = fetchJSON(apiPath);
1616
return adjustedData(data, path);
@@ -29,7 +29,7 @@ export async function remove(hash) {
2929
}
3030

3131
export async function create(path, source, password = "", expires = "", unit = "hours") {
32-
const params = { path: encodeURIComponent(path), source: source };
32+
const params = { path: encodeURIComponent(path), source: encodeURIComponent(source) };
3333
const apiPath = getApiPath("api/share",params);
3434
let body = "{}";
3535
if (password != "" || expires !== "" || unit !== "hours") {

frontend/src/components/Search.vue

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ export default {
498498
this.ongoing = true;
499499
let source = this.selectedSource;
500500
if (source == "") {
501-
source = state.sources.current;
501+
this.selectedSource = state.sources.current;
502502
}
503-
this.results = await search(this.getContext, source, searchTypesFull + this.value);
503+
this.results = await search(this.getContext, this.selectedSource, searchTypesFull + this.value);
504504
505505
this.ongoing = false;
506506
if (this.results.length == 0) {
@@ -519,13 +519,17 @@ export default {
519519
if (this.getContext === "/") {
520520
path = s.path;
521521
}
522+
let urlPath = "/files/" + state.sources.current + path;
523+
if (!state.serverHasMultipleSources) {
524+
urlPath = "/files" + path;
525+
}
522526
const modifiedItem = {
523527
name: pathParts.pop(),
524528
path: path,
525529
size: s.size,
526530
type: s.type,
527-
source: "",
528-
url: path,
531+
source: this.selectedSource,
532+
url: urlPath,
529533
fullPath: path,
530534
};
531535
mutations.resetSelected();

frontend/src/components/prompts/Info.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export default {
165165
event.preventDefault();
166166
let link;
167167
if (state.isSearchActive) {
168-
const hash = await filesApi.checksum(state.selected[0].path, algo);
168+
const hash = await filesApi.checksum(state.selected[0].source, state.selected[0].path, algo);
169169
event.target.innerHTML = hash;
170170
return;
171171
}
@@ -175,7 +175,7 @@ export default {
175175
link = state.route.path;
176176
}
177177
178-
const hash = await filesApi.checksum(link, algo);
178+
const hash = await filesApi.checksum(state.sources.current, link, algo);
179179
event.target.innerHTML = hash;
180180
},
181181
},

frontend/src/utils/url.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,8 @@ export function extractSourceFromPath(url) {
121121
if (state.serverHasMultipleSources) {
122122
source = path.split('/')[2];
123123
path = removePrefix(path, `/files/${source}`);
124-
source = encodeURIComponent(source)
125124
} else {
126-
source = encodeURIComponent(state.sources.current);
125+
source = state.sources.current;
127126
path = removePrefix(path, '/files');
128127
}
129128

frontend/src/views/files/ListingView.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,9 @@ export default {
608608
break;
609609
610610
case "Backspace":
611+
if (getters.CurrentPromptName !== null) {
612+
return;
613+
}
611614
// go back
612615
router.push({ path: newPath });
613616
break;

0 commit comments

Comments
 (0)