@softr/sdk
Version:
The SDK for building Softr apps on TanStack Start. It lets an app interact with Softr: auth, datasources, workflows and integrations.
16 lines (14 loc) • 702 B
JavaScript
import { assert } from "../assertions.js";
import { upload } from "./file-upload.js";
import { createServerFn } from "@tanstack/react-start";
//#region src/core/upload-fn.ts
const uploadServerFn = createServerFn({ method: "POST" }).validator((data) => data).handler(async ({ data }) => {
const actionJson = data.get("action");
const file = data.get("file");
assert(typeof actionJson === "string", "upload: action is required");
assert(file instanceof File, "upload: file is required");
const attachment = await upload(JSON.parse(actionJson), file);
return new Response(JSON.stringify(attachment), { headers: { "Content-Type": "application/json" } });
});
//#endregion
export { uploadServerFn };