Compare commits

..
Author SHA1 Message Date
José Alves cba153cfc1 fix(docs): update CT222 IP from 10.10.50.140 to 10.10.50.204 — BIT-24053
Tests / bridge tests (push) Successful in 29s
Tests / writer-pipeline tests (push) Successful in 30s
Tests / frontend lib tests (push) Successful in 31s
Tests / writer-pipeline tests (pull_request) Successful in 28s
Tests / bridge tests (pull_request) Successful in 28s
Tests / frontend lib tests (pull_request) Successful in 26s
CT222 news-project-test changed IP following DHCP re-lease (BIT-24050
emergency fix). IP is now static at 10.10.50.204 via systemd-networkd.
Update all doc references, deploy script post-install notes, and
wordpress/README direct-access URLs.

Paperclip-Agent: Tiago Neves (devops; id 5d084b36-f38f-42a5-a92a-520005afda4f)
Paperclip-Issue: BIT-24053
Paperclip-Run: 9c69919d-4c21-48b0-8eb7-2b9745bed65c
2026-06-01 13:12:36 +00:00
spark 0e7897ba77 Merge pull request 'fix(nginx): add wp_andebol_content volume to nginx-andebol (BIT-23734)' (#14) from fix/BIT-23734-nginx-andebol-wp-content-volume into main
Tests / writer-pipeline tests (push) Successful in 39s
Tests / bridge tests (push) Successful in 38s
Tests / frontend lib tests (push) Successful in 37s
2026-05-26 00:32:35 +01:00
Tiago Neves 86261a1a54 fix(nginx): add wp_andebol_content volume to nginx-andebol (BIT-23734)
Tests / writer-pipeline tests (push) Successful in 50s
Tests / bridge tests (push) Successful in 1m3s
Tests / frontend lib tests (push) Successful in 1m3s
Tests / bridge tests (pull_request) Successful in 1m11s
Tests / writer-pipeline tests (pull_request) Successful in 1m14s
Tests / frontend lib tests (pull_request) Successful in 1m9s
nginx-andebol was missing the wp_andebol_content volume mount, causing
uploaded files to return 404 even though they were written correctly to
the wp_andebol_content Docker volume by the WordPress PHP-FPM container.

Paperclip-Task: BIT-23734
Paperclip-Agent: devops
2026-05-25 23:25:52 +00:00
spark 0c9e5df61c Merge pull request 'feat(writer-pipeline): newsproject.bitreport.pt writer cycle and WP env split' (#12) from feat/BIT-22288-newsproject-writer into main
Tests / writer-pipeline tests (push) Successful in 13s
Tests / bridge tests (push) Successful in 13s
Tests / frontend lib tests (push) Successful in 14s
Reviewed-on: #12
2026-05-14 19:10:00 +01:00
José Alves aaaafd0c8f ci: re-trigger push checks after runner cache fix
Tests / writer-pipeline tests (push) Successful in 11s
Tests / bridge tests (push) Successful in 15s
Tests / frontend lib tests (push) Successful in 16s
Tests / writer-pipeline tests (pull_request) Successful in 15s
Tests / bridge tests (pull_request) Successful in 15s
Tests / frontend lib tests (pull_request) Successful in 15s
Empty commit to re-run push-event CI (previous failure was runner
infrastructure — missing act cache entry for actions/setup-node@v4).

Paperclip-Issue: BIT-22306
Paperclip-Run: 9c297293-f7c3-491c-9f8e-a4488578d556
2026-05-14 18:09:29 +00:00
spark 369e0b27c2 Merge pull request 'fix(writer-pipeline): handle ns0: XML namespace prefix in WebDAV PROPFIND parser (BIT-22306)' (#13) from fix/BIT-22306-webdav-ns-prefix into main
Tests / writer-pipeline tests (push) Successful in 12s
Tests / bridge tests (push) Successful in 12s
Tests / frontend lib tests (push) Successful in 13s
Merge fix(writer-pipeline): handle ns0: XML namespace prefix in WebDAV PROPFIND parser (BIT-22306)
2026-05-14 17:46:59 +01:00
Artur Moreira 738c1a56d0 fix(writer-pipeline): handle ns0: XML namespace prefix in WebDAV PROPFIND parser (BIT-22306)
Tests / writer-pipeline tests (push) Successful in 14s
Tests / bridge tests (push) Successful in 14s
Tests / frontend lib tests (push) Successful in 15s
Tests / writer-pipeline tests (pull_request) Successful in 11s
Tests / bridge tests (pull_request) Successful in 12s
Tests / frontend lib tests (pull_request) Successful in 13s
Python's xml.etree.ElementTree auto-assigns numeric prefixes like ns0: for
the first namespace it encounters. The PROPFIND regex [a-z]+: did not match
ns0: because of the digit, causing parsePropfindImageHrefs to return empty
on any WebDAV server backed by Python (WsgiDAV, some NextCloud configs).

Change [a-z]+: → [a-z][a-z0-9]*: in all three namespace-tagged element
patterns (response, href, getlastmodified). Test added with a real WsgiDAV
multistatus fixture.

Paperclip-Issue: BIT-22306
2026-05-14 16:33:49 +00:00
Artur Moreira 0a220c158f docs(writer-pipeline): clarify WebDAV disabled vs unreachable fallback
Tests / writer-pipeline tests (push) Failing after 5s
Tests / bridge tests (push) Successful in 20s
Tests / writer-pipeline tests (pull_request) Successful in 16s
Tests / bridge tests (pull_request) Successful in 16s
Tests / frontend lib tests (push) Successful in 20s
Tests / frontend lib tests (pull_request) Successful in 17s
Document that when WRITER_WEBDAV_ENABLED is off the archive is not used,
and that enabled-but-failing PROPFIND/GET surfaces an explicit error with
operational fallback (disable or restore connectivity). Aligns BIT-22292
acceptance wording with actual pipeline behaviour.
2026-05-14 16:10:14 +00:00
Artur MoreiraandCursor 7c0a515368 feat(writer-pipeline): newsproject.bitreport.pt writer cycle and WP env split
Tests / writer-pipeline tests (push) Failing after 5s
Tests / bridge tests (push) Failing after 6s
Tests / frontend lib tests (push) Successful in 14s
Tests / writer-pipeline tests (pull_request) Successful in 11s
Tests / bridge tests (pull_request) Successful in 13s
Tests / frontend lib tests (pull_request) Successful in 14s
Add site-scoped WP credentials (NEWSPROJECT_* vs ANDEBOL_*), RSS sources
config, systemd oneshot/timer offset from andebol, env template, and
deployment docs so BIT-22288 covers both stacks.

Co-authored-by: Cursor <[email protected]>
2026-05-14 14:40:09 +00:00
spark 9d03d489e0 Merge pull request 'feat(writer-pipeline): WebDAV archive fallback + handball shortlist (BIT-22292 / BIT-22288)' (#11) from feat/bit-21912-cf-cache-rules-script into main
Tests / writer-pipeline tests (push) Failing after 10s
Tests / bridge tests (push) Successful in 14s
Tests / frontend lib tests (push) Successful in 16s
2026-05-14 15:27:09 +01:00
spark b4af1397b7 Merge pull request 'fix(frontend): auth redirects use strict false-check for auth_links (BIT-22298)' (#10) from fix/BIT-22298-auth-redirect into main
Tests / writer-pipeline tests (push) Successful in 11s
Tests / bridge tests (push) Successful in 11s
Tests / frontend lib tests (push) Successful in 12s
Merge fix/BIT-22298-auth-redirect: auth redirects strict false-check (BIT-22298)
2026-05-14 14:52:54 +01:00
Artur Moreira 11cea53dab fix(frontend): auth redirects use strict false-check for auth_links (BIT-22298)
Tests / writer-pipeline tests (push) Successful in 13s
Tests / bridge tests (push) Successful in 12s
Tests / frontend lib tests (push) Successful in 12s
Tests / writer-pipeline tests (pull_request) Successful in 11s
Tests / bridge tests (pull_request) Successful in 13s
Tests / frontend lib tests (pull_request) Successful in 14s
/entrar and /registar redirected to / because !config.auth_links is
truthy when auth_links is undefined (config fallback).  Change both
pages to config.auth_links === false so only an explicit opt-out sends
the user home; missing or true both forward to wp-login.php.

Also add Cache-Control: no-store to the redirect response so edge
proxies never cache auth flows, and extend smoke-andebol.sh to assert
/entrar and /registar resolve to a wp-login URL.

Paperclip-Issue: BIT-22298
Paperclip-Agent: d706f4e6-5d05-4cec-b6e8-f8fb1f203aae
2026-05-14 13:48:27 +00:00
spark 35e8b60684 Merge pull request 'feat: add Node.js CI workflow' (#9) from feature/add-ci-workflow into main
Tests / writer-pipeline tests (push) Successful in 13s
Tests / bridge tests (push) Successful in 13s
Tests / frontend lib tests (push) Successful in 14s
Merge feature/add-ci-workflow (branch cleanup BIT-22162)
2026-05-13 22:57:30 +01:00
spark da7a01a1c1 Merge pull request 'feat(deploy): cf-cache-rules-apply.sh for BIT-21912 / BIT-21847' (#8) from feat/bit-21912-cf-cache-rules-script into main
Tests / writer-pipeline tests (push) Successful in 12s
Tests / bridge tests (push) Successful in 14s
Tests / frontend lib tests (push) Successful in 15s
2026-05-12 12:33:47 +01:00
Artur Moreira dbf2d342a7 feat: add Node.js CI workflow for bridge
Node.js CI / build-and-test (18) (pull_request) Failing after 11s
Node.js CI / build-and-test (20) (pull_request) Failing after 13s
2026-04-27 22:45:43 +00:00
21 changed files with 301 additions and 25 deletions

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
# Node.js CI for news-platform bridge
# Runs on: PR and push to main/develop
# Checks: TypeScript build and type checking
name: Node.js CI
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
CI: "true"
jobs:
build-and-test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- name: Install dependencies
run: npm ci
working-directory: bridge
- name: TypeScript build
run: npm run build
working-directory: bridge
if: always()
- name: TypeScript type checking
run: npm run typecheck
working-directory: bridge
if: always()
+2 -2
View File
@@ -129,7 +129,7 @@ log "WordPress: http://localhost:8080/wp-json/wp/v2/"
log "Nginx: http://localhost/"
log ""
log "Remaining manual steps:"
log " 1. Add DHCP reservation for 10.10.50.140 on the router"
log " 2. Configure NPM proxy host: newsproject.bitreport.pt → http://10.10.50.140"
log " 1. IP 10.10.50.204 is static (BIT-24053: systemd-networkd + PVE config; MAC BC:24:11:77:5B:E6) — no DHCP reservation needed"
log " 2. Configure NPM proxy host: newsproject.bitreport.pt → http://10.10.50.204 (NPM proxy #20)"
log " 3. Enable HTTPS in NPM (Let's Encrypt)"
log " 4. Review $ENV_DIR/frontend.env and $ENV_DIR/bridge.env"
+9
View File
@@ -53,4 +53,13 @@ _c="$(code_for "$BASE_URL/wp-json/wp/v2/")"
[[ "$_c" == "200" ]] || fail "GET $BASE_URL/wp-json/wp/v2/ expected 200, got $_c (WP andebol :8081)"
ok "GET /wp-json/wp/v2/ → $_c"
# Auth redirects — /entrar and /registar must NOT land on / (BIT-22298)
_final_entrar="$(curl -fsS -o /dev/null -w '%{url_effective}' --max-time 25 -L -H "Host: $HOST_HEADER" "$BASE_URL/entrar" 2>/dev/null || true)"
[[ "$_final_entrar" == *"wp-login"* ]] || fail "/entrar final URL must contain wp-login; got: $_final_entrar"
ok "GET /entrar → $_final_entrar"
_final_registar="$(curl -fsS -o /dev/null -w '%{url_effective}' --max-time 25 -L -H "Host: $HOST_HEADER" "$BASE_URL/registar" 2>/dev/null || true)"
[[ "$_final_registar" == *"wp-login"* ]] || fail "/registar final URL must contain wp-login; got: $_final_registar"
ok "GET /registar → $_final_registar"
echo "All smokes passed for BASE_URL=$BASE_URL (host: $HOST_HEADER)"
@@ -0,0 +1,17 @@
[Unit]
Description=News Platform — Writer Pipeline (newsproject.bitreport.pt) single cycle
After=network.target
[Service]
Type=oneshot
User=www-data
Group=www-data
WorkingDirectory=/opt/news-platform/writer-pipeline
EnvironmentFile=/etc/news-platform/writer-newsproject.env
ExecStart=/usr/bin/node dist/run-cycle.js --site newsproject.bitreport.pt --publish-max 2 --shortlist 8
StandardOutput=journal
StandardError=journal
SyslogIdentifier=news-writer-newsproject
NoNewPrivileges=true
PrivateTmp=true
@@ -0,0 +1,10 @@
[Unit]
Description=News Platform — Writer Pipeline (newsproject.bitreport.pt) daily timer
[Timer]
OnCalendar=*-*-* 06:45:00
RandomizedDelaySec=300
Persistent=true
[Install]
WantedBy=timers.target
@@ -0,0 +1,22 @@
# Writer Pipeline — newsproject.bitreport.pt environment
# Deploy to /etc/news-platform/writer-newsproject.env on the LXC
# Secrets (WP app password) must be kept out of version control.
NODE_ENV=production
# WordPress REST API base (Docker compose default stack — port 8080)
NEWSPROJECT_WP_BASE=http://127.0.0.1:8080/wp-json
# WordPress application credentials — generate in WP Users → Application Passwords
NEWSPROJECT_WP_USER=writer-bot
NEWSPROJECT_WP_APP_PASSWORD=xxxx xxxx xxxx xxxx xxxx xxxx
# Optional — public hostname for X-Site-Domain when the REST stack is multi-tenant
# NEWSPROJECT_WP_SITE_DOMAIN=https://newsproject.bitreport.pt
# Optional — same WebDAV federation archive as andebol when enabled on the host (BIT-22292)
# WRITER_WEBDAV_ENABLED=1
# WRITER_WEBDAV_BASE_URL=https://…/remote.php/dav/files/<user>/<folder>/
# WRITER_WEBDAV_USER=
# WRITER_WEBDAV_PASSWORD=
# WRITER_WEBDAV_DEFAULT_CREDIT=Foto: …
+1 -1
View File
@@ -29,7 +29,7 @@ See [`docs/ANDEBOL_EDITORIAL_BRIEF.md`](ANDEBOL_EDITORIAL_BRIEF.md) for detailed
- **Per feed:** a failing RSS URL is logged in `metrics.errors`; other feeds still run.
- **Per URL (legacy comparison):** failed HTML fetch does not block the cycle; aggregator metrics still apply for production reads.
- **WP publish:** if credentials are missing, the cycle completes with a clear error string and **no** draft creation.
- **Featured image (BIT-22288 / BIT-22292):** drafts require a rights-cleared image. The pipeline uses RSS enclosure / `og:image` / `twitter:image` first. If none are present, it can **list a WebDAV collection** (authenticated Basic auth) and pick the best-matching filename against the headline, then upload to WP with caption/alt. Configure with `WRITER_WEBDAV_*` env vars (see `deploy/systemd/writer-andebol.env.example`). If WebDAV is enabled but PROPFIND/GET fails, draft creation for that item fails with an explicit error (no silent fallback to a random web image).
- **Featured image (BIT-22288 / BIT-22292):** drafts require a rights-cleared image. The pipeline uses RSS enclosure / `og:image` / `twitter:image` first. If none are present, it can **list a WebDAV collection** (authenticated Basic auth) and pick the best-matching filename against the headline, then upload to WP with caption/alt. Configure with `WRITER_WEBDAV_*` env vars (see `deploy/systemd/writer-andebol.env.example`). When WebDAV is **not** enabled, the archive is never contacted (only RSS/HTML hints apply). If WebDAV is enabled but PROPFIND/GET fails, draft creation for that item fails with an explicit error (no silent fallback to a random web image) — operational fallback is to disable `WRITER_WEBDAV_ENABLED` or restore connectivity before retrying.
## Commands
+40
View File
@@ -288,6 +288,46 @@ Cycle output (metrics JSON) is also appended to `/opt/news-platform/writer-pipel
---
## Writer Pipeline — newsproject.bitreport.pt (systemd timer)
Same `run-cycle.js` binary as andebol.net, with **`--site newsproject.bitreport.pt`** and WordPress credentials from **`NEWSPROJECT_WP_*`** env vars (defaults to `http://127.0.0.1:8080/wp-json`). Source list: `writer-pipeline/config/newsproject.bitreport.pt.sources.json`.
The timer is offset from the andebol unit (**06:45** vs **06:00**) to reduce concurrent writes to the shared `var/aggregated-items.json` store.
### Files
| Repo path | CT destination |
|-----------|----------------|
| `deploy/systemd/news-writer-newsproject.service` | `/etc/systemd/system/news-writer-newsproject.service` |
| `deploy/systemd/news-writer-newsproject.timer` | `/etc/systemd/system/news-writer-newsproject.timer` |
| `deploy/systemd/writer-newsproject.env.example` | `/etc/news-platform/writer-newsproject.env` (fill secrets) |
### Install on the CT
```bash
sudo cp /opt/news-platform/deploy/systemd/writer-newsproject.env.example \
/etc/news-platform/writer-newsproject.env
sudo chmod 640 /etc/news-platform/writer-newsproject.env
sudo chown root:www-data /etc/news-platform/writer-newsproject.env
# Edit NEWSPROJECT_WP_USER and NEWSPROJECT_WP_APP_PASSWORD
sudo cp /opt/news-platform/deploy/systemd/news-writer-newsproject.service \
/etc/systemd/system/
sudo cp /opt/news-platform/deploy/systemd/news-writer-newsproject.timer \
/etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable --now news-writer-newsproject.timer
```
### Manual test run
```bash
sudo systemctl start news-writer-newsproject.service
journalctl -u news-writer-newsproject.service -n 50
```
---
## Future: Multi-Container
When the platform scales beyond a single test container, each service moves to its own LXC or VM:
+1 -1
View File
@@ -1,6 +1,6 @@
# Service Health Monitoring
Automated health monitoring and alerting for the news-platform services on **CT 222** (`news-project-test`, **10.10.50.140**).
Automated health monitoring and alerting for the news-platform services on **CT 222** (`news-project-test`, **10.10.50.204**).
**BIT-746** adds a **must-not-fail inventory**, optional **public URL** probing, optional **bridge deep** checks, and an **escalation runbook**: `docs/runbooks/NEWS_PLATFORM_MONITORING_ALERTS_BIT746.md`.
**BIT-3915** adds **pipeline incident** coverage (aggregator stall, lag signals, escalation): `docs/runbooks/NEWS_PLATFORM_INCIDENT_RUNBOOK_BIT3915.md`.
**Runbook index:** `docs/runbooks/README.md` (links deployment, smoke script, and company-wide **paperclip** runbooks).
@@ -1,6 +1,6 @@
# News platform — incident response (aggregator, lag, escalation) — BIT-3915
Operational incident guide for the **news-platform** stack (Astro SSR, Fastify bridge, headless WordPress, optional **writer-pipeline** aggregator). Default deployment context: **LXC CT 222** (`news-project-test`, **10.10.50.140**, VLAN 1050) — confirm VMID/IP against the current inventory in the **paperclip** meta-repo (`docs/environments/03-lxc.md`).
Operational incident guide for the **news-platform** stack (Astro SSR, Fastify bridge, headless WordPress, optional **writer-pipeline** aggregator). Default deployment context: **LXC CT 222** (`news-project-test`, **10.10.50.204**, VLAN 1050) — confirm VMID/IP against the current inventory in the **paperclip** meta-repo (`docs/environments/03-lxc.md`).
## How this runbook fits
@@ -1,6 +1,6 @@
# News platform — monitoring alerts and escalation (BIT-746)
Follow-up to incident **BIT-743** (public `/noticias` unavailable while internal checks looked fine). This runbook applies to **CT 222** (`news-project-test`, **10.10.50.140**) and the **news-platform** stack deployed under `/opt/news-platform`.
Follow-up to incident **BIT-743** (public `/noticias` unavailable while internal checks looked fine). This runbook applies to **CT 222** (`news-project-test`, **10.10.50.204**) and the **news-platform** stack deployed under `/opt/news-platform`.
## Must-not-fail inventory (MVP)
+2 -1
View File
@@ -2,8 +2,9 @@
import { getDomainConfig } from '../lib/domain.js';
const config = getDomainConfig(Astro.url.hostname);
if (!config.auth_links) {
if (config.auth_links === false) {
return Astro.redirect('/', 302);
}
Astro.response.headers.set('Cache-Control', 'no-store');
return Astro.redirect('/wp-login.php', 302);
---
+2 -1
View File
@@ -2,8 +2,9 @@
import { getDomainConfig } from '../lib/domain.js';
const config = getDomainConfig(Astro.url.hostname);
if (!config.auth_links) {
if (config.auth_links === false) {
return Astro.redirect('/', 302);
}
Astro.response.headers.set('Cache-Control', 'no-store');
return Astro.redirect('/wp-login.php?action=register', 302);
---
+3 -3
View File
@@ -36,8 +36,8 @@ WP_ADMIN_PASSWORD=your_password docker compose exec wordpress bash /var/www/html
After setup, the REST API is available at:
```
http://10.10.50.140:8080/wp-json/wp/v2/posts
http://10.10.50.140:8080/wp-json/wp/v2/categories
http://10.10.50.204:8080/wp-json/wp/v2/posts
http://10.10.50.204:8080/wp-json/wp/v2/categories
```
The Fastify bridge (port 3200) proxies these endpoints and adds Redis caching.
@@ -82,7 +82,7 @@ Credenciais: cofre da equipa (nunca em git). Se ainda não existir utilizador ad
Para **restringir** o `/wp-admin/` a utilizadores reais em redes privadas (ou a IPs conhecidos), é preciso outra camada ou `real_ip` bem configurado: `set_real_ip_from` **apenas** para IPs dos proxies de confiança, `real_ip_header X-Forwarded-For`, e depois ajustar `allow` ao resultado — ou controlar acesso no **NPM** / Cloudflare / VPN. Ver `docs/deployment.md` (secção homónima).
**Directo ao LXC:** `http://10.10.50.140:8080/wp-admin/` — o `docker compose` publica `8080` em todas as interfaces por omissão; se não abre, verifica **firewall do CT**, **Proxmox**, e rota VPN até `10.10.50.0/24`.
**Directo ao LXC:** `http://10.10.50.204:8080/wp-admin/` — o `docker compose` publica `8080` em todas as interfaces por omissão; se não abre, verifica **firewall do CT**, **Proxmox**, e rota VPN até `10.10.50.0/24`.
**Redirects do WordPress:** define `WORDPRESS_PUBLIC_URL` no `.env` para o URL público (HTTPS + host). Em produção atrás do Nginx do CT, se ainda estiver o default `http://localhost:8080`, o `WORDPRESS_CONFIG_EXTRA` infere o URL a partir de `Host` e `X-Forwarded-Proto` **desde que** o pedido traga pelo menos um cabeçalho típico de proxy (`X-Forwarded-Proto`, `X-Forwarded-For`, ou `X-Real-IP`). Garante que o Nginx preserva o `X-Forwarded-Proto` enviado pelo NPM (ficheiro `deploy/nginx/newsproject.bitreport.pt.conf`). Acesso directo ao contentor na porta `:8080` sem esses cabeçalhos continua a precisar de `WORDPRESS_PUBLIC_URL` correcto.
+1
View File
@@ -216,6 +216,7 @@ services:
- "8081:80"
volumes:
- wp_andebol_html:/var/www/html:ro
- wp_andebol_content:/var/www/html/wp-content:ro
- ./nginx/wordpress-andebol.conf:/etc/nginx/conf.d/default.conf:ro
healthcheck:
test: ["CMD", "wget", "-q", "-O", "/dev/null", "http://127.0.0.1/wp-json/wp/v2/"]
@@ -0,0 +1,32 @@
{
"site": "newsproject.bitreport.pt",
"sources": [
{
"id": "record_pt_main",
"kind": "rss",
"url": "https://www.record.pt/rss/",
"enabled": true,
"maxItems": 20,
"topics": ["pt", "sports", "media"],
"note": "newsproject.bitreport.pt — general PT sports demo; not the andebol-only policy (see andebol.net.sources.json)."
},
{
"id": "sapo_noticias",
"kind": "rss",
"url": "https://noticias.sapo.pt/rss",
"enabled": true,
"maxItems": 25,
"topics": ["pt", "national", "international", "media"],
"note": "SAPO highlights; editorial rewrite PT-PT when publishing."
},
{
"id": "bbc_football",
"kind": "rss",
"url": "https://feeds.bbci.co.uk/sport/football/rss.xml",
"enabled": true,
"maxItems": 15,
"topics": ["football", "international", "en"],
"note": "BBC Sport football (EN); site locale is pt-PT — translate in downstream writer."
}
]
}
+8 -11
View File
@@ -20,6 +20,7 @@ import {
} from './token-metrics.js';
import type { AggregatedItem, CycleMetrics } from './types.js';
import { createDraftFromAggregatedItem } from './wp-publish.js';
import { wpCredentialsForSite } from './wp-site-env.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const PKG_ROOT = path.resolve(__dirname, '..');
@@ -84,19 +85,17 @@ async function main(): Promise<void> {
const errors = [...ingest.errors];
let draftsCreated = 0;
const wpBase = process.env.ANDEBOL_WP_BASE ?? 'http://127.0.0.1:8081/wp-json';
const wpUser = process.env.ANDEBOL_WP_USER ?? '';
const wpPass = process.env.ANDEBOL_WP_APP_PASSWORD ?? '';
const wp = wpCredentialsForSite(site);
if (!dryRun && publishMax > 0 && wpUser && wpPass) {
if (!dryRun && publishMax > 0 && wp.wpUser && wp.wpPass) {
const toPublish = list.slice(0, publishMax);
for (const item of toPublish) {
try {
const { id } = await createDraftFromAggregatedItem(item, {
wpBase,
username: wpUser,
appPassword: wpPass,
siteDomain: process.env.ANDEBOL_WP_SITE_DOMAIN,
wpBase: wp.wpBase,
username: wp.wpUser,
appPassword: wp.wpPass,
siteDomain: wp.siteDomain,
});
draftsCreated += 1;
const updated: AggregatedItem = { ...item, wpDraftId: id };
@@ -107,9 +106,7 @@ async function main(): Promise<void> {
}
await saveStore(storePath, store);
} else if (!dryRun && publishMax > 0) {
errors.push(
'Skipping WP publish: set ANDEBOL_WP_USER and ANDEBOL_WP_APP_PASSWORD (optional ANDEBOL_WP_BASE)',
);
errors.push(`Skipping WP publish: set ${wp.envHint}`);
}
const finishedAt = new Date().toISOString();
@@ -24,6 +24,15 @@ test('parsePropfindImageHrefs skips collection root and lists image files', () =
assert.equal(rows[0].lastMod, 'Wed, 01 Jan 2025 12:00:00 GMT');
});
test('parsePropfindImageHrefs handles ns0: namespace prefix (WsgiDAV / Python ElementTree)', () => {
const xml = `<?xml version="1.0" encoding="utf-8" ?>
<ns0:multistatus xmlns:ns0="DAV:"><ns0:response><ns0:href>/</ns0:href><ns0:propstat><ns0:prop><ns0:getlastmodified>Thu, 14 May 2026 16:11:04 GMT</ns0:getlastmodified><ns0:resourcetype><ns0:collection /></ns0:resourcetype></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response><ns0:response><ns0:href>/Foto_FPA___duplo-embate-croacia-m20-euro.jpg</ns0:href><ns0:propstat><ns0:prop><ns0:getlastmodified>Thu, 14 May 2026 16:11:26 GMT</ns0:getlastmodified><ns0:resourcetype /></ns0:prop><ns0:status>HTTP/1.1 200 OK</ns0:status></ns0:propstat></ns0:response></ns0:multistatus>`;
const rows = parsePropfindImageHrefs(xml, 'http://127.0.0.1:8088/');
assert.equal(rows.length, 1);
assert.match(rows[0].href, /Foto_FPA___duplo-embate-croacia-m20-euro\.jpg$/);
assert.equal(rows[0].lastMod, 'Thu, 14 May 2026 16:11:26 GMT');
});
test('pickBestArchiveImage prefers hrefs whose path matches title tokens', () => {
const item: AggregatedItem = {
id: '1',
+3 -3
View File
@@ -29,14 +29,14 @@ function decodeXmlText(s: string): string {
export function parsePropfindImageHrefs(xml: string, collectionUrl: string): { href: string; lastMod?: string }[] {
const base = new URL(collectionUrl.endsWith('/') ? collectionUrl : `${collectionUrl}/`);
const out: { href: string; lastMod?: string }[] = [];
const reResponse = /<(?:[a-z]+:)?response[^>]*>([\s\S]*?)<\/(?:[a-z]+:)?response>/gi;
const reResponse = /<(?:[a-z][a-z0-9]*:)?response[^>]*>([\s\S]*?)<\/(?:[a-z][a-z0-9]*:)?response>/gi;
let m: RegExpExecArray | null;
while ((m = reResponse.exec(xml))) {
const block = m[1];
const hrefM = /<(?:[a-z]+:)?href>([^<]+)<\/(?:[a-z]+:)?href>/i.exec(block);
const hrefM = /<(?:[a-z][a-z0-9]*:)?href>([^<]+)<\/(?:[a-z][a-z0-9]*:)?href>/i.exec(block);
if (!hrefM) continue;
const hrefRaw = decodeXmlText(hrefM[1].trim());
const lmM = /<(?:[a-z]+:)?getlastmodified>([^<]+)<\/(?:[a-z]+:)?getlastmodified>/i.exec(block);
const lmM = /<(?:[a-z][a-z0-9]*:)?getlastmodified>([^<]+)<\/(?:[a-z][a-z0-9]*:)?getlastmodified>/i.exec(block);
const lastMod = lmM ? decodeXmlText(lmM[1].trim()) : undefined;
if (!IMAGE_EXT_RE.test(hrefRaw)) continue;
let abs: string;
+54
View File
@@ -0,0 +1,54 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { wpCredentialsForSite } from './wp-site-env.js';
const keysNews = [
'NEWSPROJECT_WP_BASE',
'NEWSPROJECT_WP_USER',
'NEWSPROJECT_WP_APP_PASSWORD',
'NEWSPROJECT_WP_SITE_DOMAIN',
] as const;
const keysAndebol = ['ANDEBOL_WP_BASE', 'ANDEBOL_WP_USER', 'ANDEBOL_WP_APP_PASSWORD'] as const;
function snapshotEnv<K extends string>(keys: readonly K[]): Record<K, string | undefined> {
const o = {} as Record<K, string | undefined>;
for (const k of keys) o[k] = process.env[k];
return o;
}
function restoreEnv<K extends string>(snap: Record<K, string | undefined>) {
for (const k of Object.keys(snap) as K[]) {
const v = snap[k];
if (v === undefined) delete process.env[k];
else process.env[k] = v;
}
}
test('wpCredentialsForSite uses NEWSPROJECT_* for newsproject.bitreport.pt', () => {
const snap = snapshotEnv(keysNews);
try {
process.env.NEWSPROJECT_WP_BASE = 'http://example/wp-json';
process.env.NEWSPROJECT_WP_USER = 'u';
process.env.NEWSPROJECT_WP_APP_PASSWORD = 'p';
process.env.NEWSPROJECT_WP_SITE_DOMAIN = 'https://newsproject.bitreport.pt';
const c = wpCredentialsForSite('newsproject.bitreport.pt');
assert.equal(c.wpBase, 'http://example/wp-json');
assert.equal(c.wpUser, 'u');
assert.equal(c.wpPass, 'p');
assert.equal(c.siteDomain, 'https://newsproject.bitreport.pt');
} finally {
restoreEnv(snap);
}
});
test('wpCredentialsForSite defaults andebol WP base to 8081', () => {
const snap = snapshotEnv(keysAndebol);
try {
delete process.env.ANDEBOL_WP_BASE;
delete process.env.ANDEBOL_WP_USER;
const c = wpCredentialsForSite('andebol.net');
assert.equal(c.wpBase, 'http://127.0.0.1:8081/wp-json');
} finally {
restoreEnv(snap);
}
});
+41
View File
@@ -0,0 +1,41 @@
/**
* WordPress REST credentials per writer `--site` (BIT-22288: andebol.net + newsproject).
*/
export interface WpSiteCredentials {
wpBase: string;
wpUser: string;
wpPass: string;
siteDomain: string | undefined;
/** Shown when publish is skipped due to missing secrets */
envHint: string;
}
export function wpCredentialsForSite(site: string): WpSiteCredentials {
if (site === 'newsproject.bitreport.pt') {
const wpBase =
(process.env.NEWSPROJECT_WP_BASE ?? '').trim() || 'http://127.0.0.1:8080/wp-json';
const wpUser = (process.env.NEWSPROJECT_WP_USER ?? '').trim();
const wpPass = (process.env.NEWSPROJECT_WP_APP_PASSWORD ?? '').trim();
const siteDomain = (process.env.NEWSPROJECT_WP_SITE_DOMAIN ?? '').trim() || undefined;
return {
wpBase,
wpUser,
wpPass,
siteDomain,
envHint: 'NEWSPROJECT_WP_USER and NEWSPROJECT_WP_APP_PASSWORD (optional NEWSPROJECT_WP_BASE, NEWSPROJECT_WP_SITE_DOMAIN)',
};
}
const wpBase = (process.env.ANDEBOL_WP_BASE ?? '').trim() || 'http://127.0.0.1:8081/wp-json';
const wpUser = (process.env.ANDEBOL_WP_USER ?? '').trim();
const wpPass = (process.env.ANDEBOL_WP_APP_PASSWORD ?? '').trim();
const siteDomain = (process.env.ANDEBOL_WP_SITE_DOMAIN ?? '').trim() || undefined;
return {
wpBase,
wpUser,
wpPass,
siteDomain,
envHint: 'ANDEBOL_WP_USER and ANDEBOL_WP_APP_PASSWORD (optional ANDEBOL_WP_BASE, ANDEBOL_WP_SITE_DOMAIN)',
};
}