Files
GoSally/com/List.lua
2025-08-01 23:25:36 +03:00

55 lines
1.4 KiB
Lua

-- com/List.lua
local session = require("session")
if session.request and session.request.params and session.request.params.about then
session.response.result = {
description = "Returns a list of available methods",
params = {
layer = "select which layer list to display"
}
}
return
end
local function isValidName(name)
return name:match("^[%w]+$") ~= nil
end
local function scanDirectory(basePath, targetPath)
local res = {}
local fullPath = basePath.."/"..targetPath
local handle = io.popen('find "'..fullPath..'" -type f -name "*.lua" 2>/dev/null')
if handle then
for filePath in handle:lines() do
local parts = {}
for part in filePath:gsub(".lua$", ""):gmatch("[^/]+") do
table.insert(parts, part)
end
local allValid = true
for _, part in ipairs(parts) do
if not isValidName(part) then
allValid = false
break
end
end
if allValid then
local relPath = filePath:gsub("^"..basePath.."/", ""):gsub(".lua$", ""):gsub("/", ">")
table.insert(res, relPath)
end
end
handle:close()
end
return #res > 0 and res or nil
end
local basePath = "com"
local layer = session.request and session.request.params.layer and session.request.params.layer:gsub(">", "/") or nil
session.response.result = {
answer = layer and scanDirectory(basePath, layer) or scanDirectory(basePath, "")
}