« Module:ZoteroAPI » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 20 : | Ligne 20 : | ||
local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json' | local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json' | ||
local success, response = pcall(mw. | -- Utiliser mw.uri.fetchContent au lieu de externalData | ||
local success, response = pcall(function() | |||
return mw.uri.fetchContent(url) | |||
end) | |||
if not success or not response then | if not success or not response then | ||
| Ligne 29 : | Ligne 29 : | ||
end | end | ||
-- | -- Décoder la réponse JSON | ||
local success, data = pcall(mw.text.jsonDecode, response) | |||
if not success or not data then | |||
return nil | return nil | ||
end | end | ||
-- | -- Extraire les données de la réponse | ||
if data.data then | if data.data then | ||
cachedData = data.data | cachedData = data.data | ||
else | else | ||
cachedData = data | cachedData = data | ||
end | end | ||
| Ligne 61 : | Ligne 44 : | ||
return cachedData | return cachedData | ||
end | end | ||
-- Fonction pour déboguer la réponse brute | |||
function p.debugRawResponse(frame) | function p.debugRawResponse(frame) | ||
local itemKey = frame and frame.args[1] | local itemKey = frame and frame.args[1] | ||
| Ligne 70 : | Ligne 55 : | ||
local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json' | local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json' | ||
local success, response = pcall(mw. | -- Utiliser mw.uri.fetchContent | ||
local success, response = pcall(function() | |||
return mw.uri.fetchContent(url) | |||
end) | |||
if not success then | if not success then | ||
| Ligne 83 : | Ligne 68 : | ||
end | end | ||
-- | -- Limiter la taille de la réponse pour éviter de surcharger la page | ||
return "Type: " .. type(response) .. "\n\nContenu: " .. | if #response > 1000 then | ||
response = response:sub(1, 1000) .. "... (tronqué)" | |||
end | |||
return "Type: " .. type(response) .. "\n\nContenu: " .. response | |||
end | end | ||
-- Fonctions de débogage | -- Fonctions de débogage | ||
function p.debugResult(frame) | function p.debugResult(frame) | ||