fix(bot): fallback to expanded install_methods relation when install_methods_json is empty

This commit is contained in:
CanbiZ (MickLesk)
2026-03-18 19:05:32 +01:00
parent 105dceb42e
commit 71c02e052b

12
.github/workflows/pocketbase-bot.yml generated vendored
View File

@@ -213,7 +213,7 @@ jobs:
// ── PocketBase: find record by slug (shared by all paths) ──────────
const recordsUrl = apiBase + '/collections/' + encodeURIComponent(coll) + '/records';
const filter = "(slug='" + slug.replace(/'/g, "''") + "')";
const listRes = await request(recordsUrl + '?filter=' + encodeURIComponent(filter) + '&perPage=1', {
const listRes = await request(recordsUrl + '?filter=' + encodeURIComponent(filter) + '&perPage=1&expand=install_methods%2Cinstall_methods.type', {
headers: { 'Authorization': token }
});
const list = JSON.parse(listRes.body);
@@ -395,6 +395,16 @@ jobs:
// Parse install_methods_json from the already-fetched script record
let methodsArr = [];
try { methodsArr = JSON.parse(record.install_methods_json || '[]'); } catch (e) { methodsArr = []; }
// Fallback: if JSON cache is empty, build from expanded install_methods relation
if (methodsArr.length === 0 && record.expand && record.expand.install_methods) {
methodsArr = (record.expand.install_methods || []).map(function (im) {
const typeObj = (im.expand && im.expand.type) || {};
return {
type: typeObj.type || (typeof im.type === 'string' ? im.type : '?'),
resources: { cpu: im.resources_cpu, ram: im.resources_ram, hdd: im.resources_hdd }
};
});
}
function formatMethodsList(arr) {
if (arr.length === 0) return '*None*';