MCPcopy Index your code
hub / github.com/triggerdotdev/jsonhero-web / action

Function action

app/routes/actions/createFromFile.ts:11–42  ·  view source on GitHub ↗
({ request, context })

Source from the content-addressed store, hash-verified

9};
10
11export 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};

Callers

nothing calls this directly

Calls 2

createFromRawJsonFunction · 0.90
sendEventFunction · 0.90

Tested by

no test coverage detected