Skip to content

Commit 6185e7e

Browse files
committed
feat: complete home page migrate
1 parent fecc028 commit 6185e7e

22 files changed

Lines changed: 179 additions & 185 deletions

File tree

components/galgame/card/Card.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ defineProps<{
1616
:is-transparent="isTransparent"
1717
:is-pressable="true"
1818
v-for="galgame in galgames"
19-
:key="galgame.gid"
20-
:href="`/galgame/${galgame.gid}`"
19+
:key="galgame.id"
20+
:href="`/galgame/${galgame.id}`"
2121
class-name="p-0"
2222
>
2323
<div class="relative overflow-hidden">
@@ -69,12 +69,12 @@ defineProps<{
6969
<div class="flex gap-3">
7070
<span class="flex items-center gap-1">
7171
<KunIcon class="text-white" name="lucide:eye" />
72-
<span class="text-white">{{ galgame.views }}</span>
72+
<span class="text-white">{{ galgame.view }}</span>
7373
</span>
7474

7575
<span class="flex items-center gap-1">
7676
<KunIcon class="text-white" name="lucide:thumbs-up" />
77-
<span class="text-white">{{ galgame.likes }}</span>
77+
<span class="text-white">{{ galgame.likeCount }}</span>
7878
</span>
7979
</div>
8080

@@ -99,7 +99,9 @@ defineProps<{
9999

100100
<div class="text-default-600 flex items-center gap-1 text-sm">
101101
<KunAvatar :user="galgame.user" size="xs" />
102-
{{ `${galgame.user.name} · ${formatTimeDifference(galgame.time)}` }}
102+
{{
103+
`${galgame.user.name} · ${formatTimeDifference(galgame.resourceUpdateTime)}`
104+
}}
103105
</div>
104106
</div>
105107
</KunCard>

components/home/Recent.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ const { data } = await useFetch('/api/home/message', {
4848
<KunLink
4949
underline="none"
5050
color="default"
51-
:to="
52-
message.tid ? `/topic/${message.tid}` : `/galgame/${message.gid}`
53-
"
51+
:to="message.link"
5452
class-name="hover:text-primary line-clamp-3 break-all transition-colors"
5553
>
5654
{{ message.content }}
@@ -60,13 +58,13 @@ const { data } = await useFetch('/api/home/message', {
6058
<KunLink
6159
underline="none"
6260
color="default"
63-
:to="`/user/${message.uid}/info`"
61+
:to="`/user/${message.user.id}/info`"
6462
class-name="hover:text-foreground text-default-500 text-sm font-medium transition-colors"
6563
>
66-
{{ message.name }}
64+
{{ message.user.name }}
6765
</KunLink>
6866
<span class="text-default-500 text-sm">
69-
{{ formatTimeDifference(message.time) }}
67+
{{ formatTimeDifference(message.created) }}
7068
</span>
7169
</div>
7270
</div>

components/home/resource/Container.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const { data } = await useFetch(`/api/home/resource`, {
3030
underline="none"
3131
v-for="(link, index) in data"
3232
:key="index"
33-
:to="`/galgame/${link.gid}`"
33+
:to="`/galgame/${link.galgameId}`"
3434
class-name="group flex flex-nowrap items-start gap-3 rounded-lg transition-colors"
3535
>
3636
<div
@@ -44,10 +44,10 @@ const { data } = await useFetch(`/api/home/resource`, {
4444

4545
<div class="space-y-2">
4646
<h3 class="hover:text-primary line-clamp-3 break-all transition-colors">
47-
{{ getPreferredLanguageText(link.name) }}
47+
{{ getPreferredLanguageText(link.galgameName) }}
4848

4949
<span class="text-default-500 text-sm">
50-
{{ formatTimeDifference(link.time) }}
50+
{{ formatTimeDifference(link.created) }}
5151
</span>
5252
</h3>
5353

components/home/topic/Card.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defineProps<{
1111
<KunLink
1212
underline="none"
1313
class-name="flex-col items-start w-full"
14-
:to="`/topic/${topic.tid}`"
14+
:to="`/topic/${topic.id}`"
1515
>
1616
<div class="flex w-full items-center justify-between gap-4">
1717
<h3
@@ -21,7 +21,7 @@ defineProps<{
2121
</h3>
2222

2323
<span class="text-default-500 shrink-0 text-sm">
24-
{{ formatTimeDifference(topic.time) }}
24+
{{ formatTimeDifference(topic.statusUpdateTime) }}
2525
</span>
2626
</div>
2727

@@ -30,22 +30,22 @@ defineProps<{
3030
>
3131
<TopicTagGroup
3232
:section="topic.section"
33-
:tags="topic.tags"
33+
:tags="topic.tag"
3434
:upvote-time="topic.upvoteTime"
3535
/>
3636

3737
<div class="text-default-700 flex items-center gap-4 text-sm">
3838
<span class="flex items-center gap-1">
3939
<KunIcon name="lucide:eye" class="h-4 w-4" />
40-
{{ formatNumber(topic.views) }}
40+
{{ formatNumber(topic.view) }}
4141
</span>
4242
<span class="flex items-center gap-1">
4343
<KunIcon name="lucide:thumbs-up" class="h-4 w-4" />
44-
{{ topic.likes }}
44+
{{ topic.likeCount }}
4545
</span>
4646
<span class="flex items-center gap-1">
4747
<KunIcon name="carbon:reply" class="h-4 w-4" />
48-
{{ topic.replies + topic.comments }}
48+
{{ topic.replyCount + topic.commentCount }}
4949
</span>
5050
</div>
5151
</div>

components/topic/TagGroup.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const props = defineProps<{
33
section: string[]
44
tags: string[]
5-
upvoteTime?: number
5+
upvoteTime?: Date | string | null
66
}>()
77
88
const isRecentlyUpvoted = computed(() => hourDiff(props.upvoteTime || 0, 10))

migrate/migrateData.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import TodoModel from '~/server/models/todo'
2424
import UpdateLogModel from '~/server/models/update-log'
2525
import UserModel from '~/server/models/user'
2626

27+
import {
28+
KUN_TOPIC_CATEGORY_CONST,
29+
KUN_TOPIC_SECTION_CONST
30+
} from '~/constants/topic'
31+
2732
// 加载环境变量
2833
dotenv.config()
2934

@@ -185,7 +190,7 @@ async function precacheLookups() {
185190
// )
186191

187192
await prisma.topic_section.createMany({
188-
data: ['galgame', 'technique', 'others'].map((s) => ({ name: s }))
193+
data: KUN_TOPIC_SECTION_CONST.map((s) => ({ name: s }))
189194
})
190195

191196
// Topic tags lookup (from TagModel)
@@ -255,7 +260,7 @@ async function migrateUsers() {
255260
bio: doc.bio ?? '',
256261
daily_check_in: doc.daily_check_in ?? 0,
257262
daily_image_count: doc.daily_image_count ?? 0,
258-
created: msToDate(doc.time) ?? doc.created,
263+
created: doc.created,
259264
updated: doc.updated
260265
}
261266
})
@@ -306,7 +311,7 @@ async function migrateTodos() {
306311
content_zh_tw: doc.content?.['zh-tw'] ?? '',
307312
completed_time: msToDate(doc.completed_time),
308313
user_id: 2,
309-
created: msToDate(doc.time) ?? doc.created,
314+
created: doc.created,
310315
updated: doc.updated
311316
})
312317

@@ -341,7 +346,7 @@ async function migrateUpdateLogs() {
341346
content_ja_jp: doc.content?.['ja-jp'] ?? '',
342347
content_zh_cn: doc.content?.['zh-cn'] ?? '',
343348
content_zh_tw: doc.content?.['zh-tw'] ?? '',
344-
created: flexibleToDate(doc.time) ?? doc.created,
349+
created: doc.created,
345350
updated: doc.updated
346351
})
347352

@@ -379,12 +384,12 @@ async function migrateTopics(
379384
content: doc.content ?? '',
380385
view: doc.views ?? 0,
381386
status: doc.status ?? 0,
382-
category: doc.category?.[0] ?? 'uncategorized',
387+
category: doc.category?.[0].toLocaleLowerCase() ?? 'uncategorized',
383388
tag: cache.topicTagsByTid.get(doc.tid) ?? doc.tags ?? [],
384-
status_update_time: msToDate(doc.upvote_time) ?? doc.updated, // Use upvote_time as status_update_time
389+
status_update_time: msToDate(doc.time) ?? doc.updated, // Use upvote_time as status_update_time
385390
edited: msToDate(doc.edited),
386391
upvote_time: msToDate(doc.upvote_time),
387-
created: msToDate(doc.time) ?? doc.created,
392+
created: doc.created,
388393
updated: doc.updated,
389394

390395
// user: { connect: { id: doc.uid } },
@@ -702,8 +707,8 @@ async function migrateMessages() {
702707
type: doc.type,
703708
sender_id: doc.sender_uid,
704709
receiver_id: doc.receiver_uid,
705-
created: msToDate(doc.time) ?? doc.created, // 遵循Prisma的惯例,使用created_at
706-
updated: doc.updated // 遵循Prisma的惯例,使用updated_at
710+
created: doc.created,
711+
updated: doc.updated
707712
})
708713

709714
if (batch.length >= BATCH_SIZE) {
@@ -741,7 +746,6 @@ async function migrateSystemMessages() {
741746
for await (const doc of cursor) {
742747
batch.push({
743748
id: doc.maid,
744-
time: msToDate(doc.time) ?? doc.created,
745749
content_en_us: doc.content?.['en-us'] ?? null,
746750
content_ja_jp: doc.content?.['ja-jp'] ?? null,
747751
content_zh_cn: doc.content?.['zh-cn'] ?? null,
@@ -806,7 +810,7 @@ async function migrateUnmoes() {
806810
desc_zh_cn: doc.description?.['zh-cn'] ?? '',
807811
desc_zh_tw: doc.description?.['zh-tw'] ?? '',
808812
user_id: doc.uid,
809-
created: msToDate(doc.time) ?? doc.created,
813+
created: doc.created,
810814
updated: doc.updated
811815
})
812816

@@ -1205,7 +1209,7 @@ async function migrateChatMessages() {
12051209
content: doc.content ?? '',
12061210
is_recall: doc.is_recalled ?? false,
12071211
recall_time: msToDate(doc.recalled_time),
1208-
created: msToDate(doc.time) ?? doc.created,
1212+
created: doc.created,
12091213
updated: doc.updated,
12101214

12111215
// 使用从 Map 中查找到的 ID
@@ -1331,7 +1335,6 @@ async function migrateGalgameHistories() {
13311335
// 只有当 uid 存在于 validUserIds 中时,才处理这条数据
13321336
batch.push({
13331337
id: doc.ghid,
1334-
time: msToDate(doc.time) ?? doc.created,
13351338
action: doc.action ?? '',
13361339
type: doc.type ?? '',
13371340
content: doc.content ?? '',
@@ -1514,7 +1517,6 @@ async function migrateGalgameResources() {
15141517
code: doc.code ?? '',
15151518
password: doc.password ?? '',
15161519
note: sanitizeString(doc.note) ?? '',
1517-
update_time: msToDate(doc.time) ?? doc.created,
15181520
status: doc.status ?? 0,
15191521
created: doc.created,
15201522
updated: doc.updated,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kun-galgame-nuxt3",
3-
"version": "4.0.1",
3+
"version": "4.0.2",
44
"packageManager": "pnpm@10.4.1",
55
"private": true,
66
"scripts": {

plugins/kunFetchApi.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Cookies from 'js-cookie'
2+
3+
export default defineNuxtPlugin((nuxtApp) => {
4+
const kunApiFetch = $fetch.create({
5+
baseURL: '/api',
6+
7+
async onResponse({ request, response, options }) {
8+
if (response.status === 205) {
9+
if (import.meta.client) {
10+
const navigateCookie = Cookies.get('kungalgame-is-navigate-to-login')
11+
const userStore = usePersistUserStore()
12+
13+
if (!navigateCookie && userStore.uid) {
14+
userStore.$reset()
15+
useMessage(10250, 'error', 7777)
16+
17+
// 1min
18+
Cookies.set('kungalgame-is-navigate-to-login', 'navigated', {
19+
expires: 1 / 1440
20+
})
21+
22+
await navigateTo('/login')
23+
}
24+
}
25+
}
26+
27+
if (response.status === 233) {
28+
const errorHeader = response.headers.get('Kun-Error')
29+
if (errorHeader) {
30+
kungalgameErrorHandler(errorHeader)
31+
}
32+
}
33+
},
34+
35+
async onResponseError({ request, response, options }) {
36+
if (response.status === 401) {
37+
if (import.meta.client) {
38+
console.error('Unauthorized access, redirecting to login.')
39+
await navigateTo('/login')
40+
}
41+
}
42+
}
43+
})
44+
45+
return {
46+
provide: {
47+
kunApi: kunApiFetch
48+
}
49+
}
50+
})

prisma/schema/galgame-history.prisma

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
model galgame_history {
2-
id Int @id @default(autoincrement())
3-
time DateTime @default(now())
4-
action String @default("")
5-
type String @default("")
6-
content String @default("") @db.VarChar(1007)
2+
id Int @id @default(autoincrement())
3+
action String @default("")
4+
type String @default("")
5+
content String @default("") @db.VarChar(1007)
76
87
galgame_id Int
98
galgame galgame @relation(fields: [galgame_id], references: [id])

prisma/schema/message.prisma

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ model message {
1717
}
1818

1919
model system_message {
20-
id Int @id @default(autoincrement())
21-
time DateTime @default(now())
22-
content_en_us String? @db.Text
23-
content_ja_jp String? @db.Text
24-
content_zh_cn String? @db.Text
25-
content_zh_tw String? @db.Text
26-
status String @default("unread")
20+
id Int @id @default(autoincrement())
21+
content_en_us String @default("") @db.Text
22+
content_ja_jp String @default("") @db.Text
23+
content_zh_cn String @default("") @db.Text
24+
content_zh_tw String @default("") @db.Text
25+
status String @default("unread")
2726
2827
user_id Int
2928
user user @relation("system_message_sender", fields: [user_id], references: [id], onDelete: Cascade)

0 commit comments

Comments
 (0)