fix: update reader service and handler
- Add panel_layout to getDefaultSettings() for dockable panels - Remove template rendering from ShowReader (router handles SSR) - Fix pgtype.Int4 marshaling to JSON (no explicit int conversion) - Remove unused strings import from handlers
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
@@ -99,26 +98,6 @@ func (h *ReaderHandler) ShowReader(c echo.Context) error {
|
|||||||
UserID: userData.ID,
|
UserID: userData.ID,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Prepare metadata
|
|
||||||
metadata := ReaderMetadata{
|
|
||||||
MediaItemID: mediaItemID,
|
|
||||||
Title: mediaItem.Title,
|
|
||||||
Author: textToString(mediaItem.Author),
|
|
||||||
CoverImagePath: textToString(mediaItem.CoverImagePath),
|
|
||||||
LibraryType: mediaItem.FormatGroup,
|
|
||||||
MimeType: textToString(mediaItem.MimeType),
|
|
||||||
FilePath: mediaItem.FilePath,
|
|
||||||
TotalPages: int(mediaItem.PageCount),
|
|
||||||
ChapterCount: int(mediaItem.ChapterCount),
|
|
||||||
}
|
|
||||||
|
|
||||||
// Render template
|
|
||||||
var buf strings.Builder
|
|
||||||
err = templates.Reader(userData, metadata, progress, bookmarks).Render(c.Request().Context(), &buf)
|
|
||||||
if err != nil {
|
|
||||||
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to render reader"})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return JSON response instead of rendering template
|
// Return JSON response instead of rendering template
|
||||||
return c.JSON(http.StatusOK, map[string]interface{}{
|
return c.JSON(http.StatusOK, map[string]interface{}{
|
||||||
"media_item_id": mediaItemID,
|
"media_item_id": mediaItemID,
|
||||||
@@ -128,8 +107,8 @@ func (h *ReaderHandler) ShowReader(c echo.Context) error {
|
|||||||
"library_type": mediaItem.FormatGroup,
|
"library_type": mediaItem.FormatGroup,
|
||||||
"mime_type": textToString(mediaItem.MimeType),
|
"mime_type": textToString(mediaItem.MimeType),
|
||||||
"file_path": mediaItem.FilePath,
|
"file_path": mediaItem.FilePath,
|
||||||
"total_pages": int(mediaItem.PageCount),
|
"total_pages": mediaItem.PageCount,
|
||||||
"chapter_count": int(mediaItem.ChapterCount),
|
"chapter_count": mediaItem.ChapterCount,
|
||||||
"progress": progress,
|
"progress": progress,
|
||||||
"bookmarks": bookmarks,
|
"bookmarks": bookmarks,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -402,5 +402,14 @@ func (s *ReaderService) getDefaultSettings() map[string]interface{} {
|
|||||||
"tap_zone_size": 30,
|
"tap_zone_size": 30,
|
||||||
"auto_scroll": false,
|
"auto_scroll": false,
|
||||||
"panel_zoom_enabled": true,
|
"panel_zoom_enabled": true,
|
||||||
|
|
||||||
|
// Dockable panel defaults
|
||||||
|
"panel_layout": map[string]interface{}{
|
||||||
|
"toc": map[string]interface{}{"side": "left", "visible": true, "collapsed": false, "width_px": 320, "order": 1, "locked": false, "last_valid_side": "left"},
|
||||||
|
"settings": map[string]interface{}{"side": "left", "visible": false, "collapsed": true, "width_px": 380, "order": 2, "locked": false, "last_valid_side": "left"},
|
||||||
|
"navigator": map[string]interface{}{"side": "right", "visible": true, "collapsed": false, "width_px": 200, "order": 1, "locked": false, "last_valid_side": "right"},
|
||||||
|
"bookmarks": map[string]interface{}{"side": "right", "visible": false, "collapsed": true, "width_px": 280, "order": 2, "locked": false, "last_valid_side": "right"},
|
||||||
|
"mobile_nav_visible": false,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user