novel.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package routes
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "codeberg.org/vnpower/pixivfe/v2/core"
  7. "codeberg.org/vnpower/pixivfe/v2/session"
  8. "net/http"
  9. )
  10. func NovelPage(w http.ResponseWriter, r *http.Request) error {
  11. id := GetPathVar(r, "id")
  12. if _, err := strconv.Atoi(id); err != nil {
  13. return fmt.Errorf("Invalid ID: %s", id)
  14. }
  15. novel, err := core.GetNovelByID(r, id)
  16. if err != nil {
  17. return err
  18. }
  19. related, err := core.GetNovelRelated(r, id)
  20. if err != nil {
  21. return err
  22. }
  23. user, err := core.GetUserBasicInformation(r, novel.UserID)
  24. if err != nil {
  25. return err
  26. }
  27. fontType := session.GetCookie(r, session.Cookie_NovelFontType)
  28. if fontType == "" {
  29. fontType = "gothic"
  30. }
  31. viewMode := session.GetCookie(r, session.Cookie_NovelViewMode)
  32. if viewMode == "" {
  33. viewMode = strconv.Itoa(novel.Settings.ViewMode)
  34. }
  35. // println("fontType", fontType)
  36. return Render(w, r, Data_novel{Novel: novel, NovelRelated: related, User: user, Title: novel.Title, FontType: fontType, ViewMode: viewMode, Language: strings.ToLower(novel.Language)})
  37. }