Foundry and discord bot
All checks were successful
Build and Deploy Nuxt / build (push) Successful in 1m51s

This commit is contained in:
2026-10-11 22:26:29 +02:00
parent a2b512699a
commit 1402045001
65 changed files with 5962 additions and 144 deletions

View File

@@ -0,0 +1,34 @@
async function requestFoundry(path) {
const baseUrl = process.env.FOUNDRY_API_URL;
const token = process.env.FOUNDRY_API_TOKEN;
if (!baseUrl || !token) {
const error = new Error('Foundry API is not configured.');
error.code = 'FOUNDRY_NOT_CONFIGURED';
throw error;
}
const normalizedBase = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
const url = new URL(path.replace(/^\/+/, ''), normalizedBase);
const response = await fetch(url, {
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${token}`
},
signal: AbortSignal.timeout(10000)
});
const body = await response.text();
let data;
try {
data = JSON.parse(body);
} catch {
const error = new Error('Foundry API returned an invalid response.');
error.code = 'FOUNDRY_INVALID_RESPONSE';
throw error;
}
return { status: response.status, data };
}
module.exports = { requestFoundry };