const express = require("express");
const jimp = require("jimp");
const path = require("path");
const url = require("url");
const fs = require("fs-extra");
app.use(express.static("public"));
app.post("/publish/resources/find", async (request, response) => {
const dirPath = path.join(__dirname, "public");
await fs.ensureDir(dirPath);
const files = await fs.readdir(dirPath, {
.filter((dirent) => dirent.isDirectory())
id: path.join(dirPath, folder.name),
app.post("/publish/resources/get", async (request, response) => {
const dirPathExists = await fs.pathExists(request.body.id);
name: path.basename(request.body.id),
app.post("/publish/resources/upload", async (request, response) => {
const [asset] = request.body.assets;
const image = await jimp.read(asset.url);
const filePath = path.join(request.body.parent, asset.name);
await image.writeAsync(filePath);
protocol: request.protocol,
host: request.get("host"),
pathname: path.join(request.body.parent, asset.name),
app.listen(process.env.PORT || 3000);