9b395f5cc3
Build Chrome Extension / build (push) Waiting to run
Trigger Website Rebuild (Docs Updated) / dispatch (push) Waiting to run
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
// server-list.js
|
|
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
import { dispatchEvaluateResult } from './errors.js';
|
|
import { SLOCK_SITE, SLOCK_DOMAIN, SLOCK_HOME_URL, SLOCK_API_BASE } from './shared.js';
|
|
|
|
cli({
|
|
site: SLOCK_SITE,
|
|
name: 'server-list',
|
|
access: 'read',
|
|
description: 'List slock servers you belong to; marks active per localStorage slug',
|
|
domain: SLOCK_DOMAIN,
|
|
strategy: Strategy.COOKIE,
|
|
browser: true,
|
|
siteSession: 'persistent',
|
|
args: [],
|
|
columns: ['id', 'slug', 'name', 'active'],
|
|
func: async (page) => {
|
|
await page.goto(SLOCK_HOME_URL);
|
|
const snippet = `
|
|
const token = localStorage.getItem('slock_access_token');
|
|
if (!token) return { kind: 'auth', detail: 'no token' };
|
|
const res = await fetch('${SLOCK_API_BASE}/servers/', { credentials:'include', headers:{authorization:'Bearer '+token,accept:'application/json'} });
|
|
if (!res.ok) return { kind: res.status===401?'auth':'http', status: res.status, where: '/servers/' };
|
|
const list = await res.json();
|
|
const activeSlug = localStorage.getItem('slock_last_server_slug') || null;
|
|
return { kind: 'ok', rows: Array.isArray(list) ? list : (list.servers || list.data || []), meta: { activeSlug } };
|
|
`;
|
|
const result = await page.evaluate(`(async () => { ${snippet} })()`);
|
|
const rows = dispatchEvaluateResult(result);
|
|
const activeSlug = result.meta?.activeSlug ?? null;
|
|
return rows.map((s) => ({
|
|
id: s.id ?? '',
|
|
slug: s.slug ?? '',
|
|
name: s.name ?? '',
|
|
active: s.slug === activeSlug,
|
|
}));
|
|
},
|
|
});
|