/render/texture/:id
This commit is contained in:
parent
a41b15331a
commit
5d39e3055f
45
src/index.js
45
src/index.js
|
|
@ -1,37 +1,38 @@
|
|||
require("dotenv").config();
|
||||
const express = require("express");
|
||||
const app = express();
|
||||
require("dotenv").config()
|
||||
const express = require("express")
|
||||
const app = express()
|
||||
|
||||
const logger = require("./lib/logger.js");
|
||||
const logger = require("./lib/logger.js")
|
||||
|
||||
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux");
|
||||
if (process.platform == "linux") logger.warn("Game hosting might not be fully compatible with Linux")
|
||||
|
||||
global.games = new Map();
|
||||
global.games = new Map()
|
||||
|
||||
setInterval(() => {
|
||||
global.games.forEach(async (value, key) => {
|
||||
if (!(await value.Running())) value.Stop();
|
||||
});
|
||||
}, 15000);
|
||||
if (!(await value.Running())) value.Stop()
|
||||
})
|
||||
}, 15000)
|
||||
|
||||
app.use("/game/start", require("./routes/game/start.js"));
|
||||
app.use("/game/stop", require("./routes/game/stop.js"));
|
||||
app.use("/game/running", require("./routes/game/running.js"));
|
||||
app.use("/game/renew", require("./routes/game/renew.js"));
|
||||
app.use("/game/status", require("./routes/game/status.js"));
|
||||
app.use("/game/execute", require("./routes/game/execute.js"));
|
||||
app.use("/game/start", require("./routes/game/start.js"))
|
||||
app.use("/game/stop", require("./routes/game/stop.js"))
|
||||
app.use("/game/running", require("./routes/game/running.js"))
|
||||
app.use("/game/renew", require("./routes/game/renew.js"))
|
||||
app.use("/game/status", require("./routes/game/status.js"))
|
||||
app.use("/game/execute", require("./routes/game/execute.js"))
|
||||
|
||||
app.use("/render/asset", require("./routes/render/asset.js"));
|
||||
app.use("/render/asset", require("./routes/render/asset.js"))
|
||||
//app.use("/render/game", require("./routes/render/game.js"))
|
||||
//app.use("/render/texture", require("./routes/render/texture.js"))
|
||||
app.use("/render/user", require("./routes/render/user.js"));
|
||||
app.use("/render/user", require("./routes/render/user.js"))
|
||||
app.use("/render/texture", require("./routes/render/texture.js"))
|
||||
|
||||
app.use("*", require("./routes/index.js"));
|
||||
app.use("*", require("./routes/index.js"))
|
||||
|
||||
app.listen(process.env.PORT || 64989, () => {
|
||||
logger.boot(`Listening on http://127.0.0.1:${process.env.PORT || 64989}/`);
|
||||
});
|
||||
logger.boot(`Listening on http://127.0.0.1:${process.env.PORT || 64989}/`)
|
||||
})
|
||||
|
||||
process.on("uncaughtException", (err) => {
|
||||
logger.error(err.message);
|
||||
});
|
||||
logger.error(err.message)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -169,6 +169,44 @@ class RenderJob extends Job {
|
|||
if (!result) return false
|
||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||
}
|
||||
|
||||
async RenderTexture(id) {
|
||||
this.id = randomUUID()
|
||||
|
||||
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}] Texture RenderJob started for ${id}`)
|
||||
|
||||
const result = await this.OpenJobEx({
|
||||
name: this.id,
|
||||
script: await readFile(__dirname + "/../../lua/texture.lua", { encoding: "utf-8" }),
|
||||
arguments: {
|
||||
LuaValue: [
|
||||
{ type: "LUA_TSTRING", value: this.id },
|
||||
|
||||
{ type: "LUA_TSTRING", value: "Texture" },
|
||||
{ type: "LUA_TSTRING", value: process.env.RENDER_FORMAT },
|
||||
|
||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_WIDTH },
|
||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_USER_HEIGHT },
|
||||
|
||||
{ type: "LUA_TSTRING", value: process.env.BASE_URL },
|
||||
{ type: "LUA_TNUMBER", value: id },
|
||||
],
|
||||
},
|
||||
}).catch((e) => false)
|
||||
|
||||
logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`)
|
||||
|
||||
if (!result) return false
|
||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RenderJob
|
||||
|
|
|
|||
|
|
@ -8,19 +8,8 @@ game:GetService("InsertService"):SetAssetVersionUrl(baseUrl .. "/Asset/?assetver
|
|||
game:GetService("ContentProvider"):SetBaseUrl(baseUrl)
|
||||
game:GetService("ScriptContext").ScriptsDisabled = true
|
||||
|
||||
local Player = game.Players:CreateLocalPlayer(0)
|
||||
Player:LoadCharacter(false)
|
||||
|
||||
local asset = game:GetObjects(("%s/asset/?id=%d"):format(baseUrl, assetId))[1]
|
||||
asset.Parent = Player.Character
|
||||
|
||||
game:GetService("RunService"):Run()
|
||||
|
||||
Player.Character.Animate.Disabled = true
|
||||
Player.Character.Torso.Anchored = true
|
||||
|
||||
print(("[%s] Rendering ..."):format(jobId))
|
||||
local result = game:GetService("ThumbnailGenerator"):Click(format, x, y, true)
|
||||
local result = game:GetService("ThumbnailGenerator"):ClickTexture("rbxassetid://" .. assetId, format, x, y)
|
||||
print(("[%s] Done!"):format(jobId))
|
||||
|
||||
return result
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
const express = require("express")
|
||||
const app = express.Router()
|
||||
|
||||
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
|
||||
|
||||
job.Stop()
|
||||
|
||||
return response.json(body)
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
Loading…
Reference in New Issue