@insapp-dev/inslog 0.0.0-stage → 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 (110) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +66 -2
  3. package/config/database.example.json +5 -0
  4. package/config/locale.example.json +3 -0
  5. package/locales/en.json +476 -0
  6. package/locales/zh-CN.json +1 -0
  7. package/next-env.d.ts +7 -0
  8. package/next.config.ts +10 -0
  9. package/package.json +62 -4
  10. package/public/apple-touch-icon.png +0 -0
  11. package/public/favicon.ico +0 -0
  12. package/public/icon-color.png +0 -0
  13. package/public/icon-color.svg +5 -0
  14. package/public/icon-dark.svg +5 -0
  15. package/public/icon.svg +5 -0
  16. package/scripts/_db.mjs +67 -0
  17. package/scripts/export-backup.mjs +104 -0
  18. package/scripts/release.sh +70 -0
  19. package/scripts/seed-demo.mjs +184 -0
  20. package/scripts/test-connection.mjs +26 -0
  21. package/src/app/api/auth/logout/route.ts +9 -0
  22. package/src/app/api/auth/passkey/add-request/route.ts +35 -0
  23. package/src/app/api/auth/passkey/login/options/route.ts +40 -0
  24. package/src/app/api/auth/passkey/login/verify/route.ts +58 -0
  25. package/src/app/api/auth/passkey/register/options/route.ts +46 -0
  26. package/src/app/api/auth/passkey/register/verify/route.ts +63 -0
  27. package/src/app/api/auth/passkey/remove-request/route.ts +44 -0
  28. package/src/app/api/auth/recovery/route.ts +45 -0
  29. package/src/app/api/auth/totp/disable/route.ts +42 -0
  30. package/src/app/api/auth/totp/enable/route.ts +75 -0
  31. package/src/app/api/auth/totp/login/route.ts +47 -0
  32. package/src/app/api/auth/totp/setup/route.ts +20 -0
  33. package/src/app/api/setup/complete/route.ts +27 -0
  34. package/src/app/api/setup/email/route.ts +41 -0
  35. package/src/app/api/upload/local/route.ts +73 -0
  36. package/src/app/api/upload/route.ts +73 -0
  37. package/src/app/api/upload/s3/route.ts +73 -0
  38. package/src/app/confirm/[token]/page.tsx +181 -0
  39. package/src/app/globals.css +952 -0
  40. package/src/app/layout.tsx +107 -0
  41. package/src/app/login/login-form.tsx +325 -0
  42. package/src/app/login/page.tsx +76 -0
  43. package/src/app/not-found.tsx +26 -0
  44. package/src/app/page.tsx +179 -0
  45. package/src/app/posts/[slug]/page.tsx +100 -0
  46. package/src/app/robots.txt/route.ts +25 -0
  47. package/src/app/rss.xml/route.ts +60 -0
  48. package/src/app/search/page.tsx +94 -0
  49. package/src/app/settings/actions.ts +92 -0
  50. package/src/app/settings/image-field.tsx +143 -0
  51. package/src/app/settings/language-actions.ts +28 -0
  52. package/src/app/settings/language-select.tsx +56 -0
  53. package/src/app/settings/page.tsx +97 -0
  54. package/src/app/settings/passkey-manager.tsx +194 -0
  55. package/src/app/settings/site-form.tsx +323 -0
  56. package/src/app/settings/theme-toggle.tsx +51 -0
  57. package/src/app/settings/totp-manager.tsx +239 -0
  58. package/src/app/setup/auth-config-panel.tsx +132 -0
  59. package/src/app/setup/config-actions.ts +90 -0
  60. package/src/app/setup/page.tsx +80 -0
  61. package/src/app/setup/secrets-actions.ts +49 -0
  62. package/src/app/setup/setup-data.ts +133 -0
  63. package/src/app/setup/setup-wizard.tsx +338 -0
  64. package/src/app/sitemap.xml/route.ts +46 -0
  65. package/src/app/uploads/[...path]/route.ts +64 -0
  66. package/src/app/write/actions.ts +85 -0
  67. package/src/app/write/page.tsx +48 -0
  68. package/src/app/write/write-client.tsx +254 -0
  69. package/src/components/BlockEditor.tsx +102 -0
  70. package/src/components/PostBody.tsx +51 -0
  71. package/src/components/SiteFooter.tsx +41 -0
  72. package/src/components/WriteFab.tsx +38 -0
  73. package/src/components/i18n-provider.tsx +22 -0
  74. package/src/components/install-hint.tsx +31 -0
  75. package/src/components/service-config-fields.tsx +110 -0
  76. package/src/lib/auth.ts +41 -0
  77. package/src/lib/change-request.ts +184 -0
  78. package/src/lib/config-keys.ts +300 -0
  79. package/src/lib/credentials.ts +171 -0
  80. package/src/lib/env-config.ts +39 -0
  81. package/src/lib/env-store.ts +72 -0
  82. package/src/lib/i18n-core.ts +27 -0
  83. package/src/lib/i18n.ts +72 -0
  84. package/src/lib/image-compress.ts +59 -0
  85. package/src/lib/mail.ts +121 -0
  86. package/src/lib/mongodb.ts +236 -0
  87. package/src/lib/passkey.ts +73 -0
  88. package/src/lib/pending.ts +142 -0
  89. package/src/lib/post-utils.ts +56 -0
  90. package/src/lib/posts.ts +283 -0
  91. package/src/lib/rate-limit.ts +91 -0
  92. package/src/lib/recovery-hints.ts +16 -0
  93. package/src/lib/safe-path.ts +0 -0
  94. package/src/lib/secret-box.ts +46 -0
  95. package/src/lib/service-config.ts +25 -0
  96. package/src/lib/service-features.ts +72 -0
  97. package/src/lib/session-constants.ts +5 -0
  98. package/src/lib/session.ts +51 -0
  99. package/src/lib/settings-file.ts +120 -0
  100. package/src/lib/settings.ts +199 -0
  101. package/src/lib/site-url.ts +15 -0
  102. package/src/lib/slug.ts +53 -0
  103. package/src/lib/storage.ts +226 -0
  104. package/src/lib/time.ts +15 -0
  105. package/src/lib/totp.ts +88 -0
  106. package/src/lib/types.ts +72 -0
  107. package/src/lib/upload-client.ts +83 -0
  108. package/src/lib/xml.ts +12 -0
  109. package/src/proxy.ts +24 -0
  110. package/tsconfig.json +41 -0
@@ -0,0 +1,254 @@
1
+ "use client";
2
+
3
+ import type { ClientStorageProvider } from "@/lib/upload-client";
4
+
5
+ import { useMemo, useRef, useState } from "react";
6
+ import dynamic from "next/dynamic";
7
+ import { useRouter } from "next/navigation";
8
+ import type { Block } from "@blocknote/core";
9
+ import type { Visibility } from "@/lib/types";
10
+ import { deletePostAction, savePost } from "./actions";
11
+ import { useT } from "@/components/i18n-provider";
12
+
13
+ type Props = {
14
+ slug: string | null;
15
+ initialTitle: string;
16
+ initialTags: string[];
17
+ initialBlocks: Block[];
18
+ initialVisibility: Visibility;
19
+ initialPinned: boolean;
20
+ availableTags: string[];
21
+ storageProvider: ClientStorageProvider;
22
+ siteOrigin: string;
23
+ };
24
+
25
+ export default function WriteClient({
26
+ slug,
27
+ initialTitle,
28
+ initialTags,
29
+ initialBlocks,
30
+ initialVisibility,
31
+ initialPinned,
32
+ availableTags,
33
+ storageProvider,
34
+ siteOrigin,
35
+ }: Props) {
36
+ const t = useT();
37
+ // BlockNote 依赖浏览器 API,关闭 SSR。
38
+ // 关键:dynamic 要缓存,不能在每次渲染时重新构造,否则下面任何 input 的
39
+ // setState 重渲染都会让编辑器被当成新组件卸载重挂载,表现为「每敲一个字闪一下」。
40
+ const BlockEditor = useMemo(
41
+ () =>
42
+ dynamic(() => import("@/components/BlockEditor"), {
43
+ ssr: false,
44
+ loading: () => <div className="notice">{t("编辑器加载中…")}</div>,
45
+ }),
46
+ [t]
47
+ );
48
+ const VISIBILITY_OPTIONS: { value: Visibility; label: string }[] = [
49
+ { value: "public", label: t("公开") },
50
+ { value: "private", label: t("私有") },
51
+ { value: "draft", label: t("草稿") },
52
+ ];
53
+ const router = useRouter();
54
+ const [title, setTitle] = useState(initialTitle);
55
+ const [tags, setTags] = useState(initialTags);
56
+ const [tagOptions, setTagOptions] = useState(availableTags);
57
+ const [newTag, setNewTag] = useState("");
58
+ const [visibility, setVisibility] = useState<Visibility>(initialVisibility);
59
+ const [pinned, setPinned] = useState(initialPinned);
60
+ // 编辑时预填当前地址,留空表示让系统自动生成(新建)或保持原样(编辑)
61
+ const [slugInput, setSlugInput] = useState(slug ?? "");
62
+ const [saving, setSaving] = useState(false);
63
+ const [deleting, setDeleting] = useState(false);
64
+ const [hint, setHint] = useState("");
65
+
66
+ // 正文块只在保存时取一次,避免每次输入都触发父组件重渲染
67
+ const blocksRef = useRef<Block[]>(initialBlocks);
68
+
69
+ const toggleTag = (tag: string) => {
70
+ setTags(tags.includes(tag) ? tags.filter((t) => t !== tag) : [...tags, tag]);
71
+ };
72
+
73
+ const addTag = () => {
74
+ const name = newTag.trim();
75
+ if (!name) return;
76
+ if (!tagOptions.includes(name)) setTagOptions([...tagOptions, name]);
77
+ if (!tags.includes(name)) setTags([...tags, name]);
78
+ setNewTag("");
79
+ };
80
+
81
+ // 按钮文案跟着可见性走,一眼能看出这次保存会得到什么状态
82
+ const saveLabel =
83
+ visibility === "draft" ? t("保存草稿") : visibility === "private" ? t("保存为私有") : t("发布");
84
+
85
+ const handleSave = async () => {
86
+ if (saving) return;
87
+ setSaving(true);
88
+ setHint(t("保存中…"));
89
+ const result = await savePost({
90
+ slug,
91
+ customSlug: slugInput,
92
+ title,
93
+ blocks: blocksRef.current,
94
+ tags,
95
+ visibility,
96
+ pinned,
97
+ });
98
+ if (!result.ok) {
99
+ setSaving(false);
100
+ setHint(result.error);
101
+ return;
102
+ }
103
+ // 保存成功就离开编辑页,直接看文章的实际效果
104
+ // 这里故意不解除 saving,避免跳转前重复提交
105
+ router.push(`/posts/${result.slug}`);
106
+ };
107
+
108
+ const handleDelete = async () => {
109
+ if (!slug || deleting) return;
110
+ // 删除不可撤销,必须先明确确认
111
+ if (!window.confirm(t("确定删除这篇文章?删除后无法恢复。"))) return;
112
+ setDeleting(true);
113
+ setHint(t("删除中…"));
114
+ const result = await deletePostAction(slug);
115
+ if (!result.ok) {
116
+ setDeleting(false);
117
+ setHint(result.error);
118
+ return;
119
+ }
120
+ router.push("/");
121
+ router.refresh();
122
+ };
123
+
124
+ return (
125
+ <>
126
+ <div className="write-bar d-flex align-items-baseline">
127
+ <a href={slug ? `/posts/${slug}` : "/"}>{t("← 返回")}</a>
128
+ <span className="notice">{slug ? t("编辑文章") : t("新建文章")}</span>
129
+ </div>
130
+
131
+ <input
132
+ className="write-title"
133
+ type="text"
134
+ value={title}
135
+ onChange={(e) => setTitle(e.target.value)}
136
+ placeholder={t("文章标题")}
137
+ aria-label={t("文章标题")}
138
+ />
139
+
140
+ <div className="write-tags">
141
+ <div className="tag-list d-flex flex-wrap">
142
+ {tagOptions.map((tag) => (
143
+ <button
144
+ type="button"
145
+ key={tag}
146
+ className={`tag-chip ${tags.includes(tag) ? "selected" : ""}`}
147
+ aria-pressed={tags.includes(tag)}
148
+ onClick={() => toggleTag(tag)}
149
+ >
150
+ {tag}
151
+ </button>
152
+ ))}
153
+ </div>
154
+ <div className="write-tag-add d-flex align-items-baseline">
155
+ <input
156
+ className="write-tag-input"
157
+ type="text"
158
+ value={newTag}
159
+ onChange={(e) => setNewTag(e.target.value)}
160
+ onKeyDown={(e) => {
161
+ if (e.key === "Enter") {
162
+ e.preventDefault();
163
+ addTag();
164
+ }
165
+ }}
166
+ placeholder={t("新建标签后回车")}
167
+ aria-label={t("新建标签")}
168
+ />
169
+ <button className="write-tag-add-btn" type="button" onClick={addTag}>
170
+ {t("添加")}
171
+ </button>
172
+ </div>
173
+ </div>
174
+
175
+ <div className="write-editor">
176
+ <BlockEditor
177
+ storageProvider={storageProvider}
178
+ initialBlocks={initialBlocks}
179
+ onChange={(blocks) => {
180
+ blocksRef.current = blocks;
181
+ }}
182
+ />
183
+ </div>
184
+
185
+ {/* 先选可见性,按钮在它下面(都靠左),按钮文案跟着可见性变 */}
186
+ <div className="write-actions d-flex flex-column align-items-start">
187
+ <div className="write-meta d-flex flex-wrap align-items-baseline">
188
+ <span className="write-meta-label">{t("可见性")}</span>
189
+ {VISIBILITY_OPTIONS.map((option) => (
190
+ <button
191
+ key={option.value}
192
+ type="button"
193
+ className={`visibility-option ${
194
+ visibility === option.value ? "selected" : ""
195
+ }`}
196
+ aria-pressed={visibility === option.value}
197
+ onClick={() => setVisibility(option.value)}
198
+ >
199
+ {option.label}
200
+ </button>
201
+ ))}
202
+ </div>
203
+ <div className="write-meta d-flex flex-wrap align-items-baseline">
204
+ <label className="pin-toggle d-inline-flex align-items-center">
205
+ <input
206
+ type="checkbox"
207
+ checked={pinned}
208
+ onChange={(e) => setPinned(e.target.checked)}
209
+ />
210
+ <span>{t("置顶")}</span>
211
+ </label>
212
+ <span className="write-meta-hint">{t("置顶的文章排在列表最前面")}</span>
213
+ </div>
214
+ <div className="write-meta d-flex flex-wrap align-items-baseline">
215
+ <span className="write-meta-label">{t("文章地址")}</span>
216
+ <span className="write-slug-field d-inline-flex align-items-baseline">
217
+ <span className="write-slug-prefix">{siteOrigin}/posts/</span>
218
+ <input
219
+ id="post-slug"
220
+ className="write-slug-input"
221
+ type="text"
222
+ value={slugInput}
223
+ onChange={(e) => setSlugInput(e.target.value)}
224
+ placeholder={t("留空自动生成")}
225
+ aria-label={t("文章地址")}
226
+ />
227
+ </span>
228
+ <span className="write-meta-hint">{t("只能用小写字母、数字和连字符,中文会自动转拼音")}</span>
229
+ </div>
230
+ <div className="write-action-row d-flex flex-wrap align-items-center">
231
+ <button
232
+ className="btn btn-outline-light btn-plain"
233
+ type="button"
234
+ disabled={saving}
235
+ onClick={handleSave}
236
+ >
237
+ {saveLabel}
238
+ </button>
239
+ {slug && (
240
+ <button
241
+ className="write-delete-link"
242
+ type="button"
243
+ disabled={saving || deleting}
244
+ onClick={handleDelete}
245
+ >
246
+ {t("删除这篇文章")}
247
+ </button>
248
+ )}
249
+ </div>
250
+ {hint && <div className="write-save-hint">{hint}</div>}
251
+ </div>
252
+ </>
253
+ );
254
+ }
@@ -0,0 +1,102 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { useCreateBlockNote } from "@blocknote/react";
5
+ import { BlockNoteView } from "@blocknote/mantine";
6
+ import { BlockNoteSchema, defaultBlockSpecs } from "@blocknote/core";
7
+ import type { Block, PartialBlock } from "@blocknote/core";
8
+ import { prepareImage } from "@/lib/image-compress";
9
+ import { uploadFile, type ClientStorageProvider } from "@/lib/upload-client";
10
+ import "@blocknote/core/fonts/inter.css";
11
+ import "@blocknote/mantine/style.css";
12
+ import { useT } from "@/components/i18n-provider";
13
+
14
+ type Props = {
15
+ initialBlocks: Block[];
16
+ onChange: (blocks: Block[]) => void;
17
+ /** 图片存储方案,由服务端读配置后传下来 */
18
+ storageProvider: ClientStorageProvider;
19
+ };
20
+
21
+ // 只去掉待办和折叠块:个人博客用不到这两种交互块。
22
+ // 文件、音频、视频保留——附件就靠这些块插在正文里,不再单独做附件列表。
23
+ const blockSpecs = { ...defaultBlockSpecs };
24
+ for (const key of ["checkListItem", "toggleListItem"]) {
25
+ delete (blockSpecs as Record<string, unknown>)[key];
26
+ }
27
+ const editorSchema = BlockNoteSchema.create({ blockSpecs });
28
+
29
+ // BlockNote 编辑器:内容一变就把当前块数组交给父组件,什么时候写库由父组件决定
30
+ export default function BlockEditor({
31
+ initialBlocks,
32
+ onChange,
33
+ storageProvider,
34
+ }: Props) {
35
+ const t = useT();
36
+ const [dark, setDark] = useState(false);
37
+ // 注意:BlockNote 要求 initialContent 是非空数组,新建文章传 [] 会直接抛错。
38
+ // 传 undefined 时它自己会生成一个空段落。
39
+ const editor = useCreateBlockNote({
40
+ schema: editorSchema,
41
+ initialContent:
42
+ initialBlocks.length > 0 ? (initialBlocks as PartialBlock[]) : undefined,
43
+ // 图片/文件/音视频都按当前存储方案上传,数据库里只留 URL。
44
+ // 图片先降采样再走图片通道(10MB);其余文件不限类型,走附件通道(50MB)。
45
+ uploadFile: async (file: File) => {
46
+ const isImage = file.type.startsWith("image/");
47
+ try {
48
+ if (isImage) {
49
+ // 手机拍的大图先降采样/转 webp,再传
50
+ const prepared = await prepareImage(file);
51
+ return await uploadFile(prepared, storageProvider, "image");
52
+ }
53
+ return await uploadFile(file, storageProvider, "attachment");
54
+ } catch (err) {
55
+ const msg = err instanceof Error ? err.message : "";
56
+ if (msg === "IMAGE_TYPE_NOT_ALLOWED") throw new Error(t("只支持 jpg / png / webp / gif / avif / svg 图片"));
57
+ if (msg === "IMAGE_TOO_LARGE_CLIENT") throw new Error(t("图片超过 10MB,请先压缩"));
58
+ if (msg.includes("[UNAUTHORIZED]")) throw new Error(t("登录已过期,请重新登录后再上传"));
59
+ if (msg.includes("[BAD_TYPE]")) throw new Error(t("只支持图片文件(jpg/png/webp/gif)"));
60
+ if (msg.includes("[TOO_LARGE]")) throw new Error(t(isImage ? "图片超过 10MB,请压缩后再传" : "文件超过 50MB,请换一个再传"));
61
+ if (msg.includes("content type")) throw new Error(t("只支持图片文件(jpg/png/webp/gif)"));
62
+ if (msg.includes("too large")) throw new Error(t(isImage ? "图片超过 10MB,请压缩后再传" : "文件超过 50MB,请换一个再传"));
63
+ throw new Error(msg || t(isImage ? "图片上传失败,请重试" : "文件上传失败,请重试"));
64
+ }
65
+ },
66
+ });
67
+
68
+ // 跟随系统夜览模式,避免编辑器在深色页面里出现一整块白
69
+ useEffect(() => {
70
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
71
+ const apply = () => {
72
+ const explicit = document.documentElement.dataset.theme;
73
+ setDark(explicit === "dark" || (explicit !== "light" && mq.matches));
74
+ };
75
+ apply();
76
+ mq.addEventListener("change", apply);
77
+ // 设置页手动切换外观时也要跟着变
78
+ const observer = new MutationObserver(apply);
79
+ observer.observe(document.documentElement, {
80
+ attributes: true,
81
+ attributeFilter: ["data-theme"],
82
+ });
83
+ return () => {
84
+ mq.removeEventListener("change", apply);
85
+ observer.disconnect();
86
+ };
87
+ }, []);
88
+
89
+ return (
90
+ <div
91
+ className="bn-editor-wrap"
92
+ data-mantine-color-scheme={dark ? "dark" : "light"}
93
+ data-bs-theme={dark ? "dark" : "light"}
94
+ >
95
+ <BlockNoteView
96
+ editor={editor}
97
+ theme={dark ? "dark" : "light"}
98
+ onChange={() => onChange(editor.document)}
99
+ />
100
+ </div>
101
+ );
102
+ }
@@ -0,0 +1,51 @@
1
+ "use client";
2
+
3
+ import { useEffect, useState } from "react";
4
+ import { useCreateBlockNote } from "@blocknote/react";
5
+ import { BlockNoteView } from "@blocknote/mantine";
6
+ import type { Block, PartialBlock } from "@blocknote/core";
7
+ import "@blocknote/core/fonts/inter.css";
8
+ import "@blocknote/mantine/style.css";
9
+
10
+ // 只读正文:把库里存的块原样渲染出来,不带工具栏、不可编辑
11
+ // BlockNote 依赖浏览器 API,必须等挂载后再创建编辑器,否则服务端渲染会报 window is not defined
12
+ export default function PostBody({ blocks }: { blocks: Block[] }) {
13
+ const [mounted, setMounted] = useState(false);
14
+
15
+ useEffect(() => setMounted(true), []);
16
+
17
+ if (!mounted) return null;
18
+ return <ReadonlyEditor blocks={blocks} />;
19
+ }
20
+
21
+ function ReadonlyEditor({ blocks }: { blocks: Block[] }) {
22
+ const [dark, setDark] = useState(false);
23
+ const editor = useCreateBlockNote({
24
+ // BlockNote 的 initialContent 不能是空数组(传 [] 会抛错),
25
+ // 空文章传 undefined,让它自己生成一个空段落。
26
+ initialContent:
27
+ blocks.length > 0 ? (blocks as PartialBlock[]) : undefined,
28
+ });
29
+
30
+ useEffect(() => {
31
+ const mq = window.matchMedia("(prefers-color-scheme: dark)");
32
+ const apply = () => setDark(mq.matches);
33
+ apply();
34
+ mq.addEventListener("change", apply);
35
+ return () => mq.removeEventListener("change", apply);
36
+ }, []);
37
+
38
+ return (
39
+ <div
40
+ className="bn-readonly"
41
+ data-mantine-color-scheme={dark ? "dark" : "light"}
42
+ data-bs-theme={dark ? "dark" : "light"}
43
+ >
44
+ <BlockNoteView
45
+ editor={editor}
46
+ editable={false}
47
+ theme={dark ? "dark" : "light"}
48
+ />
49
+ </div>
50
+ );
51
+ }
@@ -0,0 +1,41 @@
1
+ // 站内统一页脚:未登录显示"登录",登录后换成"退出登录"
2
+ import { isLoggedIn } from "@/lib/auth";
3
+ import { getSettings } from "@/lib/settings";
4
+ import { getT } from "@/lib/i18n";
5
+
6
+ export default async function SiteFooter() {
7
+ const t = await getT();
8
+ const [loggedIn, settings] = await Promise.all([
9
+ isLoggedIn(),
10
+ getSettings().catch(() => null),
11
+ ]);
12
+
13
+ // 页脚文字:设置页填了就用它,没填用默认的版权年份。
14
+ // 填的是完整的一段(想带年份就自己写上),这样「用 inslog 写的」
15
+ // 这种话也能直接放进去,不会被硬套一个格式。
16
+ const footerText = settings?.footerText?.trim();
17
+
18
+ return (
19
+ <footer className="site-foot">
20
+ <a href="/">{t("首页")}</a> · {footerText || "© 2026"}{" "}
21
+ <a href="https://github.com/daveswong/inslog">inslog on GitHub</a>
22
+ {loggedIn ? (
23
+ <>
24
+ {" · "}
25
+ <a href="/settings">{t("设置")}</a>
26
+ {" · "}
27
+ <form className="foot-logout d-inline" action="/api/auth/logout" method="post">
28
+ <button className="foot-link" type="submit">
29
+ {t("退出登录")}
30
+ </button>
31
+ </form>
32
+ </>
33
+ ) : (
34
+ <>
35
+ {" · "}
36
+ <a href="/login">{t("登录")}</a>
37
+ </>
38
+ )}
39
+ </footer>
40
+ );
41
+ }
@@ -0,0 +1,38 @@
1
+ "use client";
2
+
3
+ // 写文章悬浮按钮:右下角固定,圆形黑色,仅有笔图标(高频操作,单功能)
4
+ // 仅登录后显示;在 /write 页隐藏,避免误触
5
+ import Link from "next/link";
6
+ import { usePathname } from "next/navigation";
7
+ import { useT } from "@/components/i18n-provider";
8
+
9
+ export default function WriteFab({ visible }: { visible: boolean }) {
10
+ const t = useT();
11
+ const pathname = usePathname();
12
+
13
+ if (!visible) return null;
14
+
15
+ // 正在写文章时不需要这个按钮
16
+ if (pathname === "/write" || pathname.startsWith("/write/")) {
17
+ return null;
18
+ }
19
+
20
+ return (
21
+ <Link href="/write" className="write-fab" aria-label={t("写文章")} title={t("写文章")}>
22
+ <svg
23
+ width="20"
24
+ height="20"
25
+ viewBox="0 0 24 24"
26
+ fill="none"
27
+ stroke="currentColor"
28
+ strokeWidth="2"
29
+ strokeLinecap="round"
30
+ strokeLinejoin="round"
31
+ aria-hidden="true"
32
+ >
33
+ <path d="M12 20h9" />
34
+ <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z" />
35
+ </svg>
36
+ </Link>
37
+ );
38
+ }
@@ -0,0 +1,22 @@
1
+ "use client";
2
+
3
+ // 把服务端读到的语言包交给客户端组件。client 组件用 useT() 拿翻译函数。
4
+ import { createContext, useContext } from "react";
5
+ import { render, type Dictionary, type Translate } from "@/lib/i18n-core";
6
+
7
+ const I18nContext = createContext<Translate>((key) => key);
8
+
9
+ export function I18nProvider({
10
+ dict,
11
+ children,
12
+ }: {
13
+ dict: Dictionary;
14
+ children: React.ReactNode;
15
+ }) {
16
+ const t: Translate = (key, vars) => render(dict, key, vars);
17
+ return <I18nContext.Provider value={t}>{children}</I18nContext.Provider>;
18
+ }
19
+
20
+ export function useT(): Translate {
21
+ return useContext(I18nContext);
22
+ }
@@ -0,0 +1,31 @@
1
+ // 数据库还没配好时的提示页。
2
+ //
3
+ // 全新部署的第一件事就是填数据库地址,那之前首页、文章页都得能打开,
4
+ // 给出「去安装向导」的入口,而不是甩一个 500 错误页。
5
+ import SiteFooter from "@/components/SiteFooter";
6
+ import { getT } from "@/lib/i18n";
7
+
8
+ export default async function InstallHint() {
9
+ const t = await getT();
10
+ return (
11
+ <main className="site mx-auto">
12
+ <header className="site-head">
13
+ <h1 className="site-title">{t("站点还没配置好")}</h1>
14
+ <p className="site-desc">
15
+ {t("数据库连不上,所以没有内容可以显示。")}
16
+ </p>
17
+ </header>
18
+
19
+ <section className="section">
20
+ <p className="notice">
21
+ <a href="/setup">{t("去安装向导")}</a>
22
+ </p>
23
+ <p className="notice">
24
+ {t("第一步填数据库地址就行,填完刷新页面。")}
25
+ </p>
26
+ </section>
27
+
28
+ <SiteFooter />
29
+ </main>
30
+ );
31
+ }
@@ -0,0 +1,110 @@
1
+ "use client";
2
+
3
+ /**
4
+ * 服务类配置(图片存储 / 发信)的字段编辑器。
5
+ *
6
+ * 每个功能块先选方案(provider),再只显示这个方案需要的字段——
7
+ * 没选的那套不参与,也不必填。只负责收集和呈现字段,统一由父组件的
8
+ * 「生成 .env 文件」按钮写进下载的文件。
9
+ */
10
+ import { useT } from "@/components/i18n-provider";
11
+
12
+ export type ServiceField = {
13
+ key: string;
14
+ label: string;
15
+ hint: string;
16
+ secret: boolean;
17
+ configured: boolean;
18
+ /** 属于哪个方案;没有这个值表示所有方案共用 */
19
+ provider?: string;
20
+ };
21
+
22
+ export type ServiceFeature = {
23
+ id: string;
24
+ title: string;
25
+ /** 区块标题下的补充说明,可空 */
26
+ note?: string;
27
+ /** provider 选择器对应的配置键,如 STORAGE_PROVIDER */
28
+ choiceKey: string;
29
+ /** 当前生效的方案 */
30
+ current: string;
31
+ providers: { value: string; label: string }[];
32
+ fields: ServiceField[];
33
+ };
34
+
35
+ type Props = {
36
+ features: ServiceFeature[];
37
+ /** 全部值,含 provider 选择器的键 */
38
+ values: Record<string, string>;
39
+ onChange: (values: Record<string, string>) => void;
40
+ };
41
+
42
+ export default function ServiceConfigFields({
43
+ features,
44
+ values,
45
+ onChange,
46
+ }: Props) {
47
+ const t = useT();
48
+ if (!features.length) return null;
49
+
50
+ return (
51
+ <div className="config-fields">
52
+ {features.map((feature) => {
53
+ const choice =
54
+ values[feature.choiceKey] ||
55
+ feature.current ||
56
+ feature.providers[0]?.value ||
57
+ "";
58
+ const visible = feature.fields.filter(
59
+ (field) => !field.provider || field.provider === choice
60
+ );
61
+
62
+ return (
63
+ <fieldset className="provider-block" key={feature.id}>
64
+ <legend className="provider-title">{feature.title}</legend>
65
+
66
+ {feature.note && <p className="field-hint">{feature.note}</p>}
67
+
68
+ <label className="d-block">
69
+ <select
70
+ className="search-input w-100"
71
+ value={choice}
72
+ onChange={(e) =>
73
+ onChange({ ...values, [feature.choiceKey]: e.target.value })
74
+ }
75
+ >
76
+ {feature.providers.map((provider) => (
77
+ <option key={provider.value} value={provider.value}>
78
+ {provider.label}
79
+ </option>
80
+ ))}
81
+ </select>
82
+ </label>
83
+
84
+ {visible.map((field) => (
85
+ <div className="config-item" key={field.key}>
86
+ <div className="config-item-head d-flex flex-wrap align-items-baseline">
87
+ <span className="config-item-label">{field.label}</span>
88
+ <code className="config-item-key">{field.key}</code>
89
+ {field.configured && (
90
+ <span className="config-item-state">{t("已配置")}</span>
91
+ )}
92
+ </div>
93
+ <input
94
+ className="search-input"
95
+ type={field.secret ? "password" : "text"}
96
+ value={values[field.key] ?? ""}
97
+ onChange={(e) =>
98
+ onChange({ ...values, [field.key]: e.target.value })
99
+ }
100
+ placeholder={field.secret ? t("留空表示不改") : field.hint}
101
+ autoComplete="off"
102
+ />
103
+ </div>
104
+ ))}
105
+ </fieldset>
106
+ );
107
+ })}
108
+ </div>
109
+ );
110
+ }