11<script setup lang="ts">
2- import { checkGalgamePR } from ' ../../utils/checkGalgamePR '
2+ import { updateGalgameSchema } from ' ~/validations/galgame '
33
44const { galgamePR } = storeToRefs (useTempGalgamePRStore ())
55
66const isPublishing = ref (false )
77
88const handlePublishGalgamePR = async () => {
9- const pullRequest = {
10- gid: galgamePR .value [0 ].id ,
11- name: galgamePR .value [0 ].name ,
12- introduction: galgamePR .value [0 ].introduction ,
13- contentLimit: galgamePR .value [0 ].contentLimit ,
14- alias: galgamePR .value [0 ].alias
9+ const galgame = galgamePR .value [0 ]
10+ const data: Record <string , number | string | string []> = {
11+ vndbId: galgame .vndbId ,
12+ name_en_us: galgame .name [' en-us' ],
13+ name_ja_jp: galgame .name [' ja-jp' ],
14+ name_zh_cn: galgame .name [' zh-cn' ],
15+ name_zh_tw: galgame .name [' zh-tw' ],
16+ intro_en_us: galgame .introduction [' en-us' ],
17+ intro_ja_jp: galgame .introduction [' ja-jp' ],
18+ intro_zh_cn: galgame .introduction [' zh-cn' ],
19+ intro_zh_tw: galgame .introduction [' zh-tw' ],
20+ contentLimit: galgame .contentLimit ,
21+ aliases: String (galgame .alias )
1522 }
1623
17- if (! checkGalgamePR (pullRequest )) {
24+ const result = updateGalgameSchema .safeParse (data )
25+ if (! result .success ) {
26+ const message = JSON .parse (result .error .message )[0 ]
27+ useMessage (
28+ ` 位置: ${message .path [0 ]} - 错误提示: ${message .message } ` ,
29+ ' warn'
30+ )
1831 return
1932 }
2033 const res = await useComponentMessageStore ().alert (
@@ -30,17 +43,17 @@ const handlePublishGalgamePR = async () => {
3043 isPublishing .value = true
3144 }
3245
33- const result = await $fetch (` /api/galgame/${pullRequest . gid }/pr ` , {
46+ const response = await $fetch (` /api/galgame/${galgame . id }/pr ` , {
3447 method: ' POST' ,
35- body: pullRequest ,
48+ body: data ,
3649 watch: false ,
3750 ... kungalgameResponseHandler
3851 })
3952 isPublishing .value = false
4053
41- if (result ) {
54+ if (response ) {
4255 useKunLoliInfo (' 创建更新请求成功' , 5 )
43- await navigateTo (` /galgame/${pullRequest . gid } ` , {
56+ await navigateTo (` /galgame/${galgame . id } ` , {
4457 replace: true
4558 })
4659 }
0 commit comments