Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cba153cfc1 | ||
|
|
0e7897ba77 | ||
|
|
86261a1a54 | ||
|
|
0c9e5df61c | ||
|
|
aaaafd0c8f | ||
|
|
369e0b27c2 | ||
|
|
738c1a56d0 | ||
|
|
0a220c158f | ||
|
|
7c0a515368 | ||
|
|
9d03d489e0 | ||
|
|
b4af1397b7 | ||
|
|
11cea53dab | ||
|
|
35e8b60684 | ||
|
|
da7a01a1c1 | ||
|
|
dbf2d342a7 |
No files matched your search
@@ -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()
|
||||
@@ -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"
|
||||
@@ -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: …
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
@@ -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,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,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
@@ -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.
|
||||
|
||||
|
||||
@@ -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."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
@@ -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)',
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user