UNPKG

smp-serverless-utils

Version:

Utilities for working with GCP Storage, file handling, and PDF/SVG conversions

47 lines (46 loc) 1.94 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleExportStory = void 0; const constants_1 = require("./constants"); const httpStatuses_1 = require("./httpStatuses"); const storyExporter_1 = __importDefault(require("./storyExporter")); const handleExportStory = (pageUrl) => { return async (req, res) => { const { title, format, quality = 1, multiplier = 1, artboardId, transparentBackground = false, save_to_asset = false, organization, storyId, } = req.body; // Validate inputs if (!format || !constants_1.ALLOWED_FILE_FORMATS.includes(format)) { return res.status(httpStatuses_1.HTTP_STATUS_400_BAD_REQUEST).json({ message: `Invalid or missing format. Allowed formats are: ${constants_1.ALLOWED_FILE_FORMATS.join(", ")}`, }); } if (!title || !artboardId || !storyId) { return res.status(httpStatuses_1.HTTP_STATUS_400_BAD_REQUEST).json({ message: "Invalid or missing required parameters.", }); } try { const result = await (0, storyExporter_1.default)({ title, format, quality, multiplier, artboardId, transparentBackground, save_to_asset, organization: organization || null, storyId, pageUrl, }); res.status(httpStatuses_1.HTTP_STATUS_200_OK).json(result); } catch (error) { res.status(httpStatuses_1.HTTP_STATUS_400_BAD_REQUEST).json({ message: error.message || "Failed to export story", }); } }; }; exports.handleExportStory = handleExportStory;