@ginhotaru282/reader 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/.dockerignore +5 -0
  2. package/.gitattributes +2 -0
  3. package/Dockerfile +26 -0
  4. package/README.md +36 -0
  5. package/eslint.config.mjs +18 -0
  6. package/next.config.ts +8 -0
  7. package/package.json +31 -0
  8. package/postcss.config.mjs +7 -0
  9. package/public/file.svg +1 -0
  10. package/public/globe.svg +1 -0
  11. package/public/window.svg +1 -0
  12. package/scripts/obfuscate-build.mjs +77 -0
  13. package/src/app/(reader)/[id]/page.tsx +40 -0
  14. package/src/app/(reader)/layout.tsx +38 -0
  15. package/src/app/api/bookmark/[id]/toggle/route.ts +41 -0
  16. package/src/app/api/chapter/[id]/audio/route.ts +37 -0
  17. package/src/app/api/chapter/[id]/audio-status/route.ts +36 -0
  18. package/src/app/api/chapter/[id]/unlock/route.ts +49 -0
  19. package/src/app/api/comment/story/[id]/route.ts +48 -0
  20. package/src/app/api/reading-progress/[storyId]/route.ts +26 -0
  21. package/src/app/api/reading-progress/sync/route.ts +38 -0
  22. package/src/app/api/story/[id]/combo-unlock/route.ts +47 -0
  23. package/src/app/globals.css +26 -0
  24. package/src/app/icon.png +0 -0
  25. package/src/app/layout.tsx +35 -0
  26. package/src/app/page.tsx +3 -0
  27. package/src/assets/fonts/Lora-Variable.ttf +0 -0
  28. package/src/assets/fonts/PlusJakartaSans-Variable.ttf +0 -0
  29. package/src/components/ssr/Skeleton/index.module.css +22 -0
  30. package/src/components/ssr/Skeleton/index.tsx +38 -0
  31. package/src/modules/reader/ReaderView.tsx +48 -0
  32. package/src/modules/reader/api/backend-data.ts +231 -0
  33. package/src/modules/reader/api/client-audio-api.ts +33 -0
  34. package/src/modules/reader/api/client-bookmark-api.ts +21 -0
  35. package/src/modules/reader/api/client-comment-api.ts +31 -0
  36. package/src/modules/reader/api/client-progress-api.ts +36 -0
  37. package/src/modules/reader/api/client-purchase-api.ts +64 -0
  38. package/src/modules/reader/api/get-reader-page-data.ts +48 -0
  39. package/src/modules/reader/api/types.ts +47 -0
  40. package/src/modules/reader/components/AudioPlayerBar.tsx +299 -0
  41. package/src/modules/reader/components/AutoScrollDrawer.tsx +58 -0
  42. package/src/modules/reader/components/ChapterBottomNav.tsx +16 -0
  43. package/src/modules/reader/components/ChapterContent.tsx +43 -0
  44. package/src/modules/reader/components/ChapterListDrawer.tsx +84 -0
  45. package/src/modules/reader/components/ChapterNav.tsx +20 -0
  46. package/src/modules/reader/components/ChapterSelect.tsx +24 -0
  47. package/src/modules/reader/components/ChapterWatermark.tsx +53 -0
  48. package/src/modules/reader/components/CommentSection.tsx +156 -0
  49. package/src/modules/reader/components/LockedChapterGate.tsx +37 -0
  50. package/src/modules/reader/components/MobileDock.tsx +62 -0
  51. package/src/modules/reader/components/NavButton.tsx +22 -0
  52. package/src/modules/reader/components/ReaderBreadcrumbs.tsx +20 -0
  53. package/src/modules/reader/components/ReaderChrome.tsx +206 -0
  54. package/src/modules/reader/components/ReaderToolbar.tsx +52 -0
  55. package/src/modules/reader/components/ReaderTopbar.tsx +31 -0
  56. package/src/modules/reader/components/SettingsPanel.tsx +158 -0
  57. package/src/modules/reader/components/Toast.tsx +15 -0
  58. package/src/modules/reader/constants/index.ts +22 -0
  59. package/src/modules/reader/hooks/useAudioPlayer.ts +633 -0
  60. package/src/modules/reader/hooks/useAutoScroll.ts +31 -0
  61. package/src/modules/reader/hooks/useBookmark.ts +32 -0
  62. package/src/modules/reader/hooks/useComments.ts +86 -0
  63. package/src/modules/reader/hooks/useContentProtection.ts +81 -0
  64. package/src/modules/reader/hooks/useDrawers.ts +27 -0
  65. package/src/modules/reader/hooks/useFullscreen.ts +24 -0
  66. package/src/modules/reader/hooks/usePrefs.ts +66 -0
  67. package/src/modules/reader/hooks/useReaderView.ts +190 -0
  68. package/src/modules/reader/hooks/useReadingProgress.ts +95 -0
  69. package/src/modules/reader/hooks/useScrollVisibility.ts +44 -0
  70. package/src/modules/reader/hooks/useToast.ts +19 -0
  71. package/src/modules/reader/hooks/useUnlock.ts +59 -0
  72. package/src/modules/reader/styles/reader.module.css +1986 -0
  73. package/src/modules/reader/types.ts +145 -0
  74. package/src/modules/reader/utils/affiliate.ts +43 -0
  75. package/src/modules/reader/utils/chapter-label.ts +8 -0
  76. package/src/modules/reader/utils/format-date.ts +10 -0
  77. package/src/modules/reader/utils/obfuscate-content.ts +70 -0
  78. package/src/modules/reader/utils/silent-wav.ts +33 -0
  79. package/src/modules/reader/utils/tiktok-tts.ts +251 -0
  80. package/src/modules/reader/utils/word-svg.ts +132 -0
  81. package/tsconfig.json +34 -0
@@ -0,0 +1,59 @@
1
+ "use client";
2
+
3
+ import { useCallback, useState } from "react";
4
+ import { useRouter } from "next/navigation";
5
+ import { unlockChapter, unlockCombo } from "../api/client-purchase-api";
6
+
7
+ // Ported from frontend/src/pages/ReaderPage.jsx's handleUnlock /
8
+ // handleQuickUnlock / handleQuickUnlockCombo — same status-message handling,
9
+ // adapted to Next.js: instead of re-fetching + local setState, a successful
10
+ // unlock just refreshes the current route so the server re-runs with the
11
+ // now-unlocked chapter data.
12
+ export function useUnlock(chapterId: string, storyId: string) {
13
+ const router = useRouter();
14
+ const [unlocking, setUnlocking] = useState(false);
15
+ const [message, setMessage] = useState<string | null>(null);
16
+
17
+ const runUnlock = useCallback(
18
+ async (action: () => ReturnType<typeof unlockChapter>, successMessage: string) => {
19
+ setUnlocking(true);
20
+ setMessage(null);
21
+ try {
22
+ const res = await action();
23
+ if (res.success) {
24
+ setMessage(successMessage);
25
+ router.refresh();
26
+ return;
27
+ }
28
+ if (res.message === "unauthorized") {
29
+ setMessage("Bạn cần đăng nhập để mở khoá chương.");
30
+ // /dang-nhap is a page on the main frontend SPA, not this Next.js
31
+ // app — router.push would try (and fail) to resolve it inside the
32
+ // reader app's own basePath. Full navigation crosses the app boundary.
33
+ window.location.href = "/dang-nhap";
34
+ return;
35
+ }
36
+ setMessage(res.message || "Không đủ Vàng để mở khoá.");
37
+ if (res.message?.includes("không đủ")) {
38
+ // Same reasoning: /nap-gold lives on the main frontend SPA.
39
+ window.location.href = "/nap-gold";
40
+ }
41
+ } finally {
42
+ setUnlocking(false);
43
+ }
44
+ },
45
+ [router]
46
+ );
47
+
48
+ const unlock = useCallback(
49
+ () => runUnlock(() => unlockChapter(chapterId, storyId), "Mở khoá chương thành công!"),
50
+ [runUnlock, chapterId, storyId]
51
+ );
52
+
53
+ const unlockStoryCombo = useCallback(
54
+ () => runUnlock(() => unlockCombo(storyId), "Mua trọn bộ truyện thành công!"),
55
+ [runUnlock, storyId]
56
+ );
57
+
58
+ return { unlocking, message, unlock, unlockStoryCombo };
59
+ }