模块

RequestHelper:修订间差异

来自蒙纳多研究本部

Monado​(留言 | 贡献)
MWBot
ヒカリ​(留言 | 贡献)
无编辑摘要
 
(未显示2个用户的3个中间版本)
第2行: 第2行:


p.language = "cn"
p.language = "cn"
if mw.xbdb.env() == "development" then
  p.entrypoint = "http://dev.xenoblade.cn:3000"
else
  p.entrypoint = "http://172.19.82.27:3000"
end


local cache = {}
local cache = {}
第16行: 第10行:
   end
   end


   local cacheKey = tablename .. ":" .. row_id .. ":" .. language
   local cacheKey = tablename .. ":" .. (row_id or "") .. ":" .. language
   if cache[cacheKey] == nil then
   if cache[cacheKey] == nil then
     cache[cacheKey] =
     cache[cacheKey] =
       mw.xbdb.post(
       mw.xbdb.getBdatData(
      p.entrypoint,
       {
       {
         game = "xb1",
         game = "xb1",
第30行: 第23行:
   end
   end
   return cache[cacheKey]
   return cache[cacheKey]
end
function p.output(frame)
  local tablename = mw.text.trim(frame.args[1])
  local row_id = frame.args[2] and mw.text.trim(frame.args[2]) or nil
  return mw.text.jsonEncode(p.post(tablename, row_id))
end
end


return p
return p

2024年5月7日 (二) 21:09的最新版本

此模块的文档可以在模块:RequestHelper/doc创建

local p = {}

p.language = "cn"

local cache = {}

function p.post(tablename, row_id, language)
  if language == nil then
    language = p.language
  end

  local cacheKey = tablename .. ":" .. (row_id or "") .. ":" .. language
  if cache[cacheKey] == nil then
    cache[cacheKey] =
      mw.xbdb.getBdatData(
      {
        game = "xb1",
        table = tablename,
        row_id = row_id,
        language = language
      }
    )
  end
  return cache[cacheKey]
end

function p.output(frame)
  local tablename = mw.text.trim(frame.args[1])
  local row_id = frame.args[2] and mw.text.trim(frame.args[2]) or nil
  return mw.text.jsonEncode(p.post(tablename, row_id))
end

return p