2025-05-04 19:46:43 +08:00

54 lines
1.8 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

-- 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
print("\nLua file downloaded successfully.")
local data = luafile.readAll()
print("\nExecuting Lua code...")
load(data)()
else
print("\nFailed to download Lua file.")
end