|
1 | 1 | 'use server' |
2 | 2 |
|
| 3 | +import { cache } from 'react' |
3 | 4 | import { z } from 'zod' |
4 | 5 | import { verifyHeaderCookie } from '~/utils/actions/verifyHeaderCookie' |
5 | 6 | import { safeParseSchema } from '~/utils/actions/safeParseSchema' |
6 | 7 | import { getPatchById } from '~/app/api/patch/get' |
7 | 8 | import { getPatchIntroduction } from '~/app/api/patch/introduction/route' |
8 | 9 | import { getPatchContributor } from '~/app/api/patch/contributor/route' |
| 10 | +import { updatePatchViews } from '~/app/api/patch/views/put' |
9 | 11 |
|
10 | 12 | const patchIdSchema = z.object({ |
11 | 13 | patchId: z.coerce.number().min(1).max(9999999) |
12 | 14 | }) |
13 | 15 |
|
14 | | -export const kunGetPatchActions = async ( |
15 | | - params: z.infer<typeof patchIdSchema> |
16 | | -) => { |
17 | | - const input = safeParseSchema(patchIdSchema, params) |
18 | | - if (typeof input === 'string') { |
19 | | - return input |
| 16 | +export const kunGetPatchActions = cache( |
| 17 | + async (params: z.infer<typeof patchIdSchema>) => { |
| 18 | + const input = safeParseSchema(patchIdSchema, params) |
| 19 | + if (typeof input === 'string') { |
| 20 | + return input |
| 21 | + } |
| 22 | + const payload = await verifyHeaderCookie() |
| 23 | + |
| 24 | + const response = await getPatchById(input, payload?.uid ?? 0) |
| 25 | + return response |
20 | 26 | } |
21 | | - const payload = await verifyHeaderCookie() |
| 27 | +) |
22 | 28 |
|
23 | | - const response = await getPatchById(input, payload?.uid ?? 0) |
24 | | - return response |
25 | | -} |
| 29 | +export const kunGetPatchIntroductionActions = cache( |
| 30 | + async (params: z.infer<typeof patchIdSchema>) => { |
| 31 | + const input = safeParseSchema(patchIdSchema, params) |
| 32 | + if (typeof input === 'string') { |
| 33 | + return input |
| 34 | + } |
26 | 35 |
|
27 | | -export const kunGetPatchIntroductionActions = async ( |
28 | | - params: z.infer<typeof patchIdSchema> |
29 | | -) => { |
30 | | - const input = safeParseSchema(patchIdSchema, params) |
31 | | - if (typeof input === 'string') { |
32 | | - return input |
| 36 | + const response = await getPatchIntroduction(input) |
| 37 | + return response |
33 | 38 | } |
| 39 | +) |
34 | 40 |
|
35 | | - const response = await getPatchIntroduction(input) |
36 | | - return response |
37 | | -} |
| 41 | +export const kunGetContributorActions = cache( |
| 42 | + async (params: z.infer<typeof patchIdSchema>) => { |
| 43 | + const input = safeParseSchema(patchIdSchema, params) |
| 44 | + if (typeof input === 'string') { |
| 45 | + return input |
| 46 | + } |
| 47 | + |
| 48 | + const response = await getPatchContributor(input) |
| 49 | + return response |
| 50 | + } |
| 51 | +) |
38 | 52 |
|
39 | | -export const kunGetContributorActions = async ( |
| 53 | +export const kunUpdatePatchViewsActions = async ( |
40 | 54 | params: z.infer<typeof patchIdSchema> |
41 | 55 | ) => { |
42 | 56 | const input = safeParseSchema(patchIdSchema, params) |
43 | 57 | if (typeof input === 'string') { |
44 | 58 | return input |
45 | 59 | } |
46 | 60 |
|
47 | | - const response = await getPatchContributor(input) |
48 | | - return response |
| 61 | + await updatePatchViews(input.patchId) |
49 | 62 | } |
0 commit comments