This commit is contained in:
Insality
2025-11-09 22:28:50 +02:00
parent 54bf904727
commit 788fc66113

View File

@@ -2,6 +2,7 @@
--- Downloads zip files and extracts them to the specified folder --- Downloads zip files and extracts them to the specified folder
local base64 = require("druid.editor_scripts.core.base64") local base64 = require("druid.editor_scripts.core.base64")
local path_replacer = require("druid.editor_scripts.core.path_replacer")
local M = {} local M = {}
@@ -25,7 +26,7 @@ local M = {}
---Download a file from URL ---Download a file from URL
---@param url string - The URL to download from ---@param url string - The URL to download from
---@return string|nil, string|nil - Downloaded content or nil, filename or nil ---@return string|nil, string|nil, table|nil - Downloaded content or nil, filename or nil, content list or nil
local function download_file_zip_json(url) local function download_file_zip_json(url)
local response = http.request(url, { as = "json" }) local response = http.request(url, { as = "json" })
@@ -35,8 +36,9 @@ local function download_file_zip_json(url)
end end
local data = response.body local data = response.body
local content_list = data.content -- Array of file paths from zip
return base64.decode(data.data), data.filename return base64.decode(data.data), data.filename, content_list
end end
@@ -50,11 +52,17 @@ function M.install_widget(item, install_folder)
end end
-- Download the zip file -- Download the zip file
local zip_data, filename = download_file_zip_json(item.json_zip_url) local zip_data, filename, content_list = download_file_zip_json(item.json_zip_url)
if not zip_data or not filename then if not zip_data or not filename then
return false, "Failed to download widget: " .. filename return false, "Failed to download widget: " .. filename
end end
if content_list then
print("Got file list from JSON:", #content_list, "files")
else
print("Warning: No content list in JSON data")
end
local zip_file_path = "." .. install_folder .. "/" .. filename local zip_file_path = "." .. install_folder .. "/" .. filename
local zip_file = io.open(zip_file_path, "wb") local zip_file = io.open(zip_file_path, "wb")
@@ -79,12 +87,15 @@ function M.install_widget(item, install_folder)
print("Zip file removed successfully") print("Zip file removed successfully")
-- Process paths within the extracted widget -- Process paths within the extracted widget
--local files_in_folder = path_replacer.get_all_files(folder_path) if content_list and #content_list > 0 then
--pprint(files_in_folder) local success, err = path_replacer.process_widget_paths(folder_path, install_folder, item.id, item.author, content_list)
if not success then
--if not path_replacer.process_widget_paths(install_folder .. "/" .. folder_name, new_base_path) then print("Warning: Path replacement failed:", err)
-- return false, "Failed to process widget paths" -- Don't fail installation if path replacement fails, just warn
--end end
else
print("Warning: No file list available, skipping path replacement")
end
return true, "Widget installed successfully" return true, "Widget installed successfully"
end end