添加sanjuunidemo

This commit is contained in:
HKXluo 2025-05-04 19:46:05 +08:00
parent d5122c96a5
commit 11d24510bf
No known key found for this signature in database
GPG Key ID: 498DD8DAE5261F38
2 changed files with 53 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@ -0,0 +1,53 @@
-- API 地址 / API Endpoint
local API_URL = "http://newgmapi.liulikeji.cn/api/sanjuuni"
-- 输入图片URL / Input image URL
local INPUT_URL = "https://git.liulikeji.cn/xingluo/CCTweaked-Demo/raw/branch/main/Demo/SanjuuniApi-Demo/demo.jpg"
local function Get_image_url(INPUT_URL,API_URL,width,height)
-- ===== 1. 发送HTTP请求 / Send HTTP request =====
local requestData = {
input_url = INPUT_URL,
args = { "-8","--width="..width,"--height="..height }, -- sanjuuni转换参数 / sanjuuni conversion args
output_format = "lua"
}
local response, err = http.post(
API_URL,
textutils.serializeJSON(requestData),
{ ["Content-Type"] = "application/json" }
)
-- ===== 2. 读取数据 / Send HTTP request =====
if not response then error("HTTP Request Failure: "..(err or "Unknown error"))
else
-- 读取响应 / Read response
local responseData = textutils.unserializeJSON(response.readAll())
response.close()
--返回下载链接 / Return download URL
if responseData.status ~= "success" then error("Conversion failed:"..(responseData.error or "Unknown error"))
else
return responseData.download_url
end
end
end
local width, height = term.getSize() -- 获取终端尺寸width=宽度height=高度)
local width = width * 2 -- 宽度×2
local height = height * 3 -- 高度×3
local download_url = Get_image_url(INPUT_URL,API_URL,width,height)
-- ===== 显示图片 / Display image =====
print("\nConversion successful! Download URL:")
print(download_url)
luafile = http.get(download_url)
if luafile then
peint("\nLua file downloaded successfully.")
local data = luafile.readAll()
print("\nExecuting Lua code...")
load(data)()
else
print("\nFailed to download Lua file.")
end