fix(reader): URL-encode file paths and JSON-encode init config to fix comics/manga loading
The reader failed to load comics and manga (and any file with special characters in its path) for two reasons: 1. FileURL was built with raw fmt.Sprintf instead of ResolveMediaURL, so characters like '#' in paths (e.g. 'Annual #2') were interpreted as URL fragments, truncating the path and causing 404s. 2. The Alpine x-init expression used raw string interpolation for config values, so apostrophes in paths (e.g. "I'll Use My Appraisal Skill") broke JavaScript parsing with 'Unexpected identifier'. Fix by using utils.ResolveMediaURL for proper URL path encoding and json.Marshal for the initReader config to safely escape all special characters.
This commit is contained in:
@@ -4,10 +4,10 @@ import (
|
||||
"bookhoard/internal/database"
|
||||
"bookhoard/internal/handlers"
|
||||
"bookhoard/internal/services"
|
||||
"bookhoard/internal/utils"
|
||||
"bookhoard/templates"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
@@ -99,7 +99,7 @@ func registerReaderRoutes(cfg *Config) {
|
||||
MangaType: textToString(mediaItem.MangaType),
|
||||
ReadingDirection: textToString(mediaItem.ReadingDirection),
|
||||
LibraryID: libUUID.String(),
|
||||
FileURL: fmt.Sprintf("/uploads/library-%s/%s", libUUID.String(), mediaItem.FilePath),
|
||||
FileURL: utils.ResolveMediaURL(mediaItem.LibraryID, pgtype.Text{String: mediaItem.FilePath, Valid: true}),
|
||||
}
|
||||
// Progress conversion (inline)
|
||||
progressUUID, _ := uuid.FromBytes(progress.ID.Bytes[0:16])
|
||||
@@ -124,12 +124,14 @@ func registerReaderRoutes(cfg *Config) {
|
||||
|
||||
var pageNumber *int
|
||||
if b.PageNumber.Valid {
|
||||
pageNumber = new(int(b.PageNumber.Int32))
|
||||
val := int(b.PageNumber.Int32)
|
||||
pageNumber = &val
|
||||
}
|
||||
|
||||
var chapterNumber *int
|
||||
if b.ChapterNumber.Valid {
|
||||
chapterNumber = new(int(b.ChapterNumber.Int32))
|
||||
val := int(b.ChapterNumber.Int32)
|
||||
chapterNumber = &val
|
||||
}
|
||||
|
||||
templateBookmarks[i] = templates.Bookmark{
|
||||
|
||||
Reference in New Issue
Block a user