Merge branch 'master' into tadah

This commit is contained in:
I-Have-An-Issue 2023-02-17 22:55:03 -05:00
commit 60cb8ccd18
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
3 changed files with 90 additions and 66 deletions

View File

@ -32,6 +32,7 @@ class RCCService extends EventEmitter {
return resolve(false) return resolve(false)
} }
this.started = true
return resolve(true) return resolve(true)
}) })

View File

@ -1,19 +1,26 @@
const { readFile } = require("fs/promises"); const { readFile } = require("fs/promises")
const Job = require("./Job.js"); const Job = require("./Job.js")
const logger = require("../logger.js"); const logger = require("../logger.js")
const { randomUUID } = require("crypto")
class RenderJob extends Job { class RenderJob extends Job {
constructor() { constructor() {
super(); super()
} }
async RenderHeadshot(id) { async RenderHeadshot(id) {
const started = await this.Start(); this.id = randomUUID()
if (!started) throw new Error("RCCService failed to start");
if (!this.client) await this.CreateClient();
logger.info(`[${this.id}] Headshot RenderJob started for ${id}`); const running = this.started
if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
logger.info(`[${this.id}] Headshot RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -32,21 +39,27 @@ class RenderJob extends Job {
{ type: "LUA_TNUMBER", value: id }, { type: "LUA_TNUMBER", value: id },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`); logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
async RenderBodyshot(id, three_d = false) { async RenderBodyshot(id, three_d = false) {
const started = await this.Start(); this.id = randomUUID()
if (!started) throw new Error("RCCService failed to start");
if (!this.client) await this.CreateClient();
if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob started for ${id}`); const running = this.started
else logger.info(`[${this.id}] Bodyshot RenderJob started for ${id}`); if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob started for ${id}`)
else logger.info(`[${this.id}] Bodyshot RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -65,22 +78,28 @@ class RenderJob extends Job {
{ type: "LUA_TNUMBER", value: id }, { type: "LUA_TNUMBER", value: id },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob finished for ${id}`); if (three_d) logger.info(`[${this.id}] 3D Bodyshot RenderJob finished for ${id}`)
else logger.info(`[${this.id}] Bodyshot RenderJob finished for ${id}`); else logger.info(`[${this.id}] Bodyshot RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
async RenderAsset(id, three_d = false) { async RenderAsset(id, three_d = false) {
const started = await this.Start(); this.id = randomUUID()
if (!started) throw new Error("RCCService failed to start");
if (!this.client) await this.CreateClient();
if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob started for ${id}`); const running = this.started
else logger.info(`[${this.id}] Asset RenderJob started for ${id}`); if (!running) {
const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
if (!this.client) await this.CreateClient()
if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob started for ${id}`)
else logger.info(`[${this.id}] Asset RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -100,26 +119,30 @@ class RenderJob extends Job {
{ type: "LUA_TBOOLEAN", value: "true" }, { type: "LUA_TBOOLEAN", value: "true" },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob finished for ${id}`); if (three_d) logger.info(`[${this.id}] 3D Asset RenderJob finished for ${id}`)
else logger.info(`[${this.id}] Asset RenderJob finished for ${id}`); else logger.info(`[${this.id}] Asset RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
async RenderPlace(id) { async RenderPlace(id) {
const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_)); const response = await axios(`${process.env.BASE_URL}/API/Game/${id}?t=${process.env.ARBITER_TOKEN}`).catch((_) => reject(_))
const { server_token, server_port, server_owner_id } = response.data; const { server_token, server_port, server_owner_id } = response.data
this.id = server_token; this.id = server_token
const started = await this.Start(); const running = this.started
if (!started) throw new Error("RCCService failed to start"); if (!running) {
if (!this.client) await this.CreateClient(); const started = await this.Start()
if (!started) throw new Error("RCCService failed to start")
}
logger.info(`[${this.id}] Place RenderJob started for ${id}`); if (!this.client) await this.CreateClient()
logger.info(`[${this.id}] Place RenderJob started for ${id}`)
const result = await this.OpenJobEx({ const result = await this.OpenJobEx({
name: this.id, name: this.id,
@ -138,13 +161,13 @@ class RenderJob extends Job {
{ type: "LUA_TNUMBER", value: id }, { type: "LUA_TNUMBER", value: id },
], ],
}, },
}).catch((e) => false); }).catch((e) => false)
logger.info(`[${this.id}] Place RenderJob finished for ${id}`); logger.info(`[${this.id}] Place RenderJob finished for ${id}`)
if (!result) return false; if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value; return result[0]?.OpenJobExResult?.LuaValue[0]?.value
} }
} }
module.exports = RenderJob; module.exports = RenderJob

View File

@ -1,39 +1,39 @@
const express = require("express"); const express = require("express")
const app = express.Router(); const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js"); const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => { app.get("/:id", async (request, response) => {
const { params, query } = request; const { params, query } = request
const job = new RenderJob(); const job = new RenderJob()
let body = {}; let body = {}
const headshot = await job.RenderHeadshot(params.id).catch((_) => _); const headshot = await job.RenderHeadshot(params.id).catch((_) => _)
if (headshot?.message) { if (headshot?.message) {
job.Stop(); job.Stop()
return response.status(500).json({ error: headshot.message }); return response.status(500).json({ error: headshot.message })
} }
body.headshot = headshot; body.headshot = headshot
const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _); const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _)
if (bodyshot?.message) { if (bodyshot?.message) {
job.Stop(); job.Stop()
return response.status(500).json({ error: bodyshot.message }); return response.status(500).json({ error: bodyshot.message })
} }
body.bodyshot = bodyshot; body.bodyshot = bodyshot
if (query.three_d) { if (query.three_d) {
const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _); const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _)
if (three_d?.message) { if (three_d?.message) {
job.Stop(); job.Stop()
return response.status(500).json({ error: three_d.message }); return response.status(500).json({ error: three_d.message })
} }
body.three_d = three_d; body.three_d = three_d
} }
job.Stop(); job.Stop()
return response.json(body); return response.json(body)
}); })
module.exports = app; module.exports = app