| 1 | "use server"; |
| 2 | |
| 3 | import { revalidatePath } from |
| 4 | import { redirect } |
| 5 | import { actionClient } |
| 6 | import { z } |
| 7 | |
| 8 | import { callApi } |
| 9 | |
| 10 | import { releaseSchema } |
| 11 | |
| 12 | const repository = z |
| 13 | |
| 14 | export const createRelease = |
| 15 | .inputSchema( |
| 16 | releaseSchema.extend(repository |
| 17 | ) |
| 18 | .action(async ( |
| 19 | const data = |
| 20 | client.POST("/api/repositories/{username}/{repo}/releases |
| 21 | params: { path: { |
| 22 | body: { ...body |
| 23 | }), |
| 24 | ); |
| 25 | |
| 26 | revalidatePath(`/${username |
| 27 | // the form still has assets to upload, and navigates itself once they are in |
| 28 | return { id: |
| 29 | }); |
| 30 | |
| 31 | export const updateRelease = |
| 32 | .inputSchema( |
| 33 | releaseSchema |
| 34 | .omit({ tagName: |
| 35 | .partial() |
| 36 | .extend(repository.shape |
| 37 | .extend({ id: |
| 38 | ) |
| 39 | .action(async ( |
| 40 | const data = |
| 41 | client.PATCH("/api/repositories/{username}/{repo}/releases/{id} |
| 42 | params: { path: { |
| 43 | body, |
| 44 | }), |
| 45 | ); |
| 46 | |
| 47 | revalidatePath(`/${username |
| 48 | return { id: |
| 49 | }); |
| 50 | |
| 51 | export const deleteRelease = |
| 52 | .inputSchema(repository.extend |
| 53 | .action(async ( |
| 54 | await callApi((client |
| 55 | client.DELETE("/api/repositories/{username}/{repo}/releases/{id} |
| 56 | params: { path: { |
| 57 | }), |
| 58 | ); |
| 59 | |
| 60 | revalidatePath(`/${username |
| 61 | redirect(`/${username |
| 62 | }); |
| 63 | |
| 64 | export const deleteReleaseAsset = |
| 65 | .inputSchema(repository.extend |
| 66 | .action(async ( |
| 67 | await callApi((client |
| 68 | client.DELETE( |
| 69 | "/api/repositories/{username}/{repo}/releases/assets/{assetId}", |
| 70 | { |
| 71 | params: { path: { |
| 72 | }, |
| 73 | ), |
| 74 | ); |
| 75 | |
| 76 | revalidatePath(`/${username |
| 77 | }); |