✨ (engine): 在本机直接执行 Legado 书源规则(CSS/XPath/JSONPath/正则/URL 构造)
This commit is contained in:
1 parent
485d0160a1
commit
f73f9c4f39
13 files changed
+4503
No files matched your search
@@ -0,0 +1,50 @@
|
||||
--[[--
|
||||
JS / WebView 规则一律拒绝:抛出带固定提示的错误表,由 parser 转成用户可见的错误。
|
||||
|
||||
@module moonsource_legadorule.unsupported
|
||||
--]]
|
||||
|
||||
local Regex = require("moonsource_legadorule.regex")
|
||||
|
||||
local Unsupported = {}
|
||||
|
||||
Unsupported.MESSAGE = "该书源需要 JS/WebView,暂不支持"
|
||||
|
||||
local ErrMeta = { __tostring = function(e) return e.message end }
|
||||
|
||||
function Unsupported.fail()
|
||||
error(setmetatable({ message = Unsupported.MESSAGE, unsupported = true }, ErrMeta), 0)
|
||||
end
|
||||
|
||||
--- pcall 抛出的错误转成文字。
|
||||
function Unsupported.message(err)
|
||||
if type(err) == "table" and err.message then return err.message end
|
||||
return tostring(err)
|
||||
end
|
||||
|
||||
function Unsupported.isJsSnippet(text)
|
||||
return Regex.test("(?i)<js\\b|@js:", text)
|
||||
end
|
||||
|
||||
function Unsupported.throwIfJsSnippet(text)
|
||||
if Unsupported.isJsSnippet(text) then Unsupported.fail() end
|
||||
end
|
||||
|
||||
function Unsupported.isSelectorRule(rule)
|
||||
rule = rule:gsub("^%s+", "")
|
||||
return rule:sub(1, 1) == "@" or rule:sub(1, 2) == "$." or rule:sub(1, 2) == "$[" or rule:sub(1, 2) == "//"
|
||||
end
|
||||
|
||||
function Unsupported.isJsExpression(expr)
|
||||
expr = expr:gsub("^%s+", ""):gsub("%s+$", "")
|
||||
if expr == "" then return false end
|
||||
local compact = expr:gsub("%s+", "")
|
||||
if Regex.test("(?i)^(key|keyword|page)([+\\-*/%]\\d+)?$", compact) then return false end
|
||||
return not Unsupported.isSelectorRule(expr)
|
||||
end
|
||||
|
||||
function Unsupported.throwIfJsExpression(expr)
|
||||
if Unsupported.isJsExpression(expr) then Unsupported.fail() end
|
||||
end
|
||||
|
||||
return Unsupported
|
||||
Reference in new issue
Block a user