diff --git a/Demo/SanjuuniApi-Demo/demo.jpg b/Demo/SanjuuniApi-Demo/demo.jpg new file mode 100644 index 0000000..0c33799 Binary files /dev/null and b/Demo/SanjuuniApi-Demo/demo.jpg differ diff --git a/Demo/SanjuuniApi-Demo/demo1.lua b/Demo/SanjuuniApi-Demo/demo1.lua new file mode 100644 index 0000000..bdaedcd --- /dev/null +++ b/Demo/SanjuuniApi-Demo/demo1.lua @@ -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