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