Add workflow to push json changes to pocketbase

This commit is contained in:
Michel Roegl-Brunner
2026-03-02 15:26:29 +01:00
parent e8b3b936df
commit 7d5900de18

View File

@@ -78,23 +78,20 @@ jobs:
const apiBase = /\/api$/i.test(raw) ? raw : raw + '/api'; const apiBase = /\/api$/i.test(raw) ? raw : raw + '/api';
const coll = process.env.POCKETBASE_COLLECTION; const coll = process.env.POCKETBASE_COLLECTION;
const files = fs.readFileSync('changed_app_jsons.txt', 'utf8').trim().split(/\s+/).filter(Boolean); const files = fs.readFileSync('changed_app_jsons.txt', 'utf8').trim().split(/\s+/).filter(Boolean);
const authUrl = apiBase + '/collections/users/auth-with-password';
console.log('Auth URL: ' + authUrl);
const authBody = JSON.stringify({ const authBody = JSON.stringify({
identity: process.env.POCKETBASE_ADMIN_EMAIL, identity: process.env.POCKETBASE_ADMIN_EMAIL,
password: process.env.POCKETBASE_ADMIN_PASSWORD password: process.env.POCKETBASE_ADMIN_PASSWORD
}); });
let authRes = await request(apiBase + '/admins/auth-with-password', { const authRes = await request(authUrl, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: authBody body: authBody
}); });
if (!authRes.ok && authRes.statusCode === 404) { if (!authRes.ok) {
authRes = await request(raw + '/admins/auth-with-password', { throw new Error('Auth failed. Tried: ' + authUrl + ' - Verify POST to that URL with body {"identity":"...","password":"..."} works. Response: ' + authRes.body);
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: authBody
});
} }
if (!authRes.ok) throw new Error('Auth failed (check POCKETBASE_URL): ' + authRes.body);
const token = JSON.parse(authRes.body).token; const token = JSON.parse(authRes.body).token;
const recordsUrl = apiBase + '/collections/' + encodeURIComponent(coll) + '/records'; const recordsUrl = apiBase + '/collections/' + encodeURIComponent(coll) + '/records';
for (const file of files) { for (const file of files) {