Add asset downloaing via download_models.luau

This commit is contained in:
2025-09-22 17:27:15 -04:00
parent 749c070609
commit 50d71a004d
2 changed files with 52 additions and 6 deletions
+28 -6
View File
@@ -2,6 +2,7 @@ local process = require("@lune/process")
local fs = require("@lune/fs") local fs = require("@lune/fs")
local roblox = require("@lune/roblox") local roblox = require("@lune/roblox")
local stdio = require("@lune/stdio") local stdio = require("@lune/stdio")
local download_models = require("./download_models")
local args = process.args local args = process.args
@@ -79,6 +80,16 @@ while i <= #args do
directoryMode = true directoryMode = true
directoryPath = args[i + 1] directoryPath = args[i + 1]
i = i + 2 i = i + 2
elseif arg == "--asset" or arg == "--a" then
if i + 1 > #args and not process.env.OPEN_CLOUD_API_KEY then
stdio.write(stdio.color("red"))
stdio.write("Error: --asset (or --a) flag requires an asset ID and a valid Open Cloud API Key.\n")
stdio.write(stdio.color("reset"))
process.exit(1)
end
downloadAssetMode = true
downloadAssetId = args[i+1]
i = i+2
else else
-- regular file argument -- regular file argument
if not directoryMode then if not directoryMode then
@@ -123,6 +134,17 @@ if directoryMode then
end end
end end
if downloadAssetMode then
local assetContents = download_models.downloadModel(downloadAssetId)
if assetContents then
table.insert(filesToProcess, assetContents)
else
stdio.write(stdio.color("yellow"))
stdio.write(`Warning: Asset fetch for asset with id: {downloadAssetId} failed. Is your Open Cloud key valid and does it have assetdelivery scope?\n`)
stdio.write(stdio.color("reset"))
end
end
if #filesToProcess == 0 then if #filesToProcess == 0 then
stdio.write(stdio.color("red")) stdio.write(stdio.color("red"))
stdio.write("Error: No files to process.\n") stdio.write("Error: No files to process.\n")
@@ -176,9 +198,9 @@ if outputFile then
end end
-- print summary -- print summary
stdio.write("\nFiles containing a Workspace instance:\n") stdio.write("\nFiles containing a Workspace instance:\n")
for _, file in pairs(filesWithWorkspace) do for _, file in pairs(filesWithWorkspace) do
stdio.write(stdio.color("green")) stdio.write(stdio.color("green"))
stdio.write(` {file}\n`) stdio.write(` {file}\n`)
stdio.write(stdio.color("reset")) stdio.write(stdio.color("reset"))
end end
+24
View File
@@ -0,0 +1,24 @@
local fs = require("@lune/fs")
local net = require("@lune/net")
local process = require("@lune/process")
-- should be an open cloud api key with assetdelivery scope
local OPEN_CLOUD_API_KEY = process.env.OPEN_CLOUD_API_KEY
local BASE_API_URL = "https://apis.roblox.com/asset-delivery-api/v1/assetId/"
local download_models = {}
function download_models.downloadModel(assetId: number, fileName: string?): string?
local response = net.request({
url = BASE_API_URL .. assetId,
method = "GET",
headers = {["x-api-key"] = OPEN_CLOUD_API_KEY}
})
if response.ok then
return response.body
else
return nil
end
end
return download_models