({ request, context })
| 9 | }; |
| 10 | |
| 11 | export const action: ActionFunction = async ({ request, context }) => { |
| 12 | const formData = await request.formData(); |
| 13 | const filename = formData.get("filename"); |
| 14 | const rawJson = formData.get("rawJson"); |
| 15 | |
| 16 | const errors: CreateFromFileError = {}; |
| 17 | |
| 18 | if (!filename) errors.filename = true; |
| 19 | if (!rawJson) errors.rawJson = true; |
| 20 | |
| 21 | if (Object.keys(errors).length) { |
| 22 | return errors; |
| 23 | } |
| 24 | |
| 25 | invariant(typeof filename === "string", "filename must be a string"); |
| 26 | invariant(typeof rawJson === "string", "rawJson must be a string"); |
| 27 | |
| 28 | const doc = await createFromRawJson(filename, rawJson); |
| 29 | |
| 30 | const url = new URL(request.url); |
| 31 | |
| 32 | context.waitUntil( |
| 33 | sendEvent({ |
| 34 | type: "create", |
| 35 | from: "file", |
| 36 | id: doc.id, |
| 37 | source: url.searchParams.get("utm_source") ?? url.hostname, |
| 38 | }) |
| 39 | ); |
| 40 | |
| 41 | return redirect(`/j/${doc.id}`); |
| 42 | }; |
nothing calls this directly
no test coverage detected