const express = require("express");
const fs = require("fs-extra");
const jimp = require("jimp");
const path = require("path");
const url = require("url");
app.use(express.static("public"));
app.post("/publish/resources/upload", async (request, response) => {
// Ensure the "public" directory exists
await fs.ensureDir(path.join(__dirname, "public"));
// Get the first asset from the "assets" array
const [asset] = request.body.assets;
const image = await jimp.read(asset.url);
const filePath = path.join(__dirname, "public", asset.name);
await image.writeAsync(filePath);
// Respond with the URL of the published design
protocol: request.protocol,
host: request.get("host"),
app.listen(process.env.PORT || 3000);