diff --git a/README.md b/README.md index 1a74536..632247f 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,99 @@ It comes preloaded with some Lua scripts made by kinery and jackd900. You **will** have to replace/modify these scripts when implementing for your own projects. Set your desired settings in `.env.example`, then rename it to `.env`. + +## Routes + +### GET /render/asset/:id + +
+200 OK + +``` +iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC... +``` + +
+ +### GET /render/asset/3d/:id + +
+200 OK + +```json +{ + "camera": { + "position": { "x": 0, "y": 0, "z": 0 }, + "direction": { "x": 0, "y": 0, "z": 0 } + }, + "AABB": { + "min": { "x": 0, "y": 0, "z": 0 }, + "max": { "x": 0, "y": 0, "z": 0 } + }, + "files": { + "scene.obj": { "content": "..." }, + "scene.mtl": { "content": "..." }, + "Handle1Tex.png": { "content": "..." } + } +} +``` + +
+ +### GET /render/texture/:id + +
+200 OK + +``` +iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC... +``` + +
+ +### GET /render/user/headshot/:id + +
+200 OK + +``` +iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC... +``` + +
+ +### GET /render/user/bodyshot/:id + +
+200 OK + +``` +iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC... +``` + +
+ +### GET /render/user/3d/:id + +
+200 OK + +```json +{ + "camera": { + "position": { "x": 0, "y": 0, "z": 0 }, + "direction": { "x": 0, "y": 0, "z": 0 } + }, + "AABB": { + "min": { "x": 0, "y": 0, "z": 0 }, + "max": { "x": 0, "y": 0, "z": 0 } + }, + "files": { + "scene.obj": { "content": "..." }, + "scene.mtl": { "content": "..." }, + "Handle1Tex.png": { "content": "..." } + } +} +``` + +
diff --git a/src/lib/classes/RenderJob.js b/src/lib/classes/RenderJob.js index 0439098..78f0139 100644 --- a/src/lib/classes/RenderJob.js +++ b/src/lib/classes/RenderJob.js @@ -44,6 +44,8 @@ class RenderJob extends Job { logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Headshot RenderJob finished for ${id}`) + this.Stop() + if (!result) return false return result[0]?.OpenJobExResult?.LuaValue[0]?.value } @@ -84,6 +86,8 @@ class RenderJob extends Job { if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Bodyshot RenderJob finished for ${id}`) else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Bodyshot RenderJob finished for ${id}`) + this.Stop() + if (!result) return false return result[0]?.OpenJobExResult?.LuaValue[0]?.value } @@ -125,6 +129,8 @@ class RenderJob extends Job { if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Asset RenderJob finished for ${id}`) else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Asset RenderJob finished for ${id}`) + this.Stop() + if (!result) return false return result[0]?.OpenJobExResult?.LuaValue[0]?.value } @@ -166,6 +172,8 @@ class RenderJob extends Job { logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Place RenderJob finished for ${id}`) + this.Stop() + if (!result) return false return result[0]?.OpenJobExResult?.LuaValue[0]?.value } @@ -204,6 +212,8 @@ class RenderJob extends Job { logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`) + this.Stop() + if (!result) return false return result[0]?.OpenJobExResult?.LuaValue[0]?.value } diff --git a/src/routes/render/asset.js b/src/routes/render/asset.js index 9fc500e..24aea09 100644 --- a/src/routes/render/asset.js +++ b/src/routes/render/asset.js @@ -6,27 +6,21 @@ const RenderJob = require("../../lib/classes/RenderJob.js") app.get("/:id", async (request, response) => { const { params, query } = request const job = new RenderJob() - let body = {} const asset = await job.RenderAsset(params.id).catch((_) => _) - if (asset?.message) { - job.Stop() - return response.status(500).json({ error: asset.message }) - } - body.asset = asset + if (asset?.message) return response.status(500).json({ error: asset.message }) - if (query.three_d) { - const three_d = await job.RenderAsset(params.id, true).catch((_) => _) - if (three_d?.message) { - job.Stop() - return response.status(500).json({ error: three_d.message }) - } - body.three_d = three_d - } + return response.end(asset) +}) - job.Stop() +app.get("/:id/3d", async (request, response) => { + const { params, query } = request + const job = new RenderJob() - return response.json(body) + const three_d = await job.RenderAsset(params.id, true).catch((_) => _) + if (three_d?.message) return response.status(500).json({ error: three_d.message }) + + return response.json(JSON.parse(three_d)) }) module.exports = app diff --git a/src/routes/render/game.js b/src/routes/render/game.js index 7616772..5962c24 100644 --- a/src/routes/render/game.js +++ b/src/routes/render/game.js @@ -3,12 +3,16 @@ const app = express.Router() const RenderJob = require("../../lib/classes/RenderJob.js") -app.get("/:id", async (request, response) => { - const job = new RenderJob() - const result = await job.RenderPlace(request.params.id, process.env.RENDER_BASE64).catch((_) => _) +// app.get("/:id", async (request, response) => { +// const job = new RenderJob() +// const result = await job.RenderPlace(request.params.id, process.env.RENDER_BASE64).catch((_) => _) - if (result?.message) return response.status(500).json({ error: result.message }) - else return response.end(result) +// if (result?.message) return response.status(500).json({ error: result.message }) +// else return response.end(result) +// }) + +app.get("*", (request, response) => { + response.status(501).end("Not Implemented") }) module.exports = app diff --git a/src/routes/render/texture.js b/src/routes/render/texture.js index 5d1e7ad..6bd0fc7 100644 --- a/src/routes/render/texture.js +++ b/src/routes/render/texture.js @@ -6,18 +6,11 @@ const RenderJob = require("../../lib/classes/RenderJob.js") app.get("/:id", async (request, response) => { const { params, query } = request const job = new RenderJob() - let body = {} const texture = await job.RenderTexture(params.id).catch((_) => _) - if (texture?.message) { - job.Stop() - return response.status(500).json({ error: texture.message }) - } - body.texture = texture + if (texture?.message) return response.status(500).json({ error: texture.message }) - job.Stop() - - return response.json(body) + return response.end(texture) }) module.exports = app diff --git a/src/routes/render/user.js b/src/routes/render/user.js index 76f7376..b799dc9 100644 --- a/src/routes/render/user.js +++ b/src/routes/render/user.js @@ -3,37 +3,34 @@ const app = express.Router() const RenderJob = require("../../lib/classes/RenderJob.js") -app.get("/:id", async (request, response) => { - const { params, query } = request +app.get("/:id/bodyshot", async (request, response) => { + const { params } = request const job = new RenderJob() - let body = {} - - const headshot = await job.RenderHeadshot(params.id).catch((_) => _) - if (headshot?.message) { - job.Stop() - return response.status(500).json({ error: headshot.message }) - } - body.headshot = headshot const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _) - if (bodyshot?.message) { - job.Stop() - return response.status(500).json({ error: bodyshot.message }) - } - body.bodyshot = bodyshot + if (bodyshot?.message) return response.status(500).json({ error: bodyshot.message }) - if (query.three_d) { - const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _) - if (three_d?.message) { - job.Stop() - return response.status(500).json({ error: three_d.message }) - } - body.three_d = three_d - } + return response.end(bodyshot) +}) - job.Stop() +app.get("/:id/headshot", async (request, response) => { + const { params } = request + const job = new RenderJob() - return response.json(body) + const headshot = await job.RenderHeadshot(params.id).catch((_) => _) + if (headshot?.message) return response.status(500).json({ error: headshot.message }) + + return response.end(headshot) +}) + +app.get("/:id/3d", async (request, response) => { + const { params, query } = request + const job = new RenderJob() + + const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _) + if (three_d?.message) return response.status(500).json({ error: three_d.message }) + + return response.json(JSON.parse(three_d)) }) module.exports = app