4e21ca937a
Deploy Documentation / deploy (push) Has been cancelled
Canary / Prepare Version (push) Has been cancelled
Canary / build-cli (push) Has been cancelled
Canary / Upload Install Script (push) Has been cancelled
Canary / bundle-desktop (push) Has been cancelled
Canary / bundle-desktop-intel (push) Has been cancelled
Canary / bundle-desktop-linux (push) Has been cancelled
Canary / bundle-desktop-windows (push) Has been cancelled
Canary / bundle-desktop-windows-cuda (push) Has been cancelled
Canary / Release (push) Has been cancelled
Unused Dependencies / machete (push) Has been cancelled
CI / changes (push) Has been cancelled
CI / Check Rust Code Format (push) Has been cancelled
CI / Build and Test Rust Project (push) Has been cancelled
CI / Build Rust Project on Windows (push) Has been cancelled
CI / Check MSRV (push) Has been cancelled
CI / Lint Rust Code (push) Has been cancelled
CI / Check Generated Schemas are Up-to-Date (push) Has been cancelled
CI / Test and Lint Electron Desktop App (push) Has been cancelled
CI / H5 Plaza Tests and Build (push) Has been cancelled
Live Provider Tests / check-fork (push) Has been cancelled
Live Provider Tests / changes (push) Has been cancelled
Live Provider Tests / Build Binary (push) Has been cancelled
Live Provider Tests / Smoke Tests (push) Has been cancelled
Live Provider Tests / Smoke Tests (Code Execution) (push) Has been cancelled
Live Provider Tests / Compaction Tests (push) Has been cancelled
Live Provider Tests / goose server HTTP integration tests (push) Has been cancelled
Publish Ask AI Bot Docker Image / docker (push) Has been cancelled
Publish Docker Image / docker (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
Fork goose with custom MCP widgets, platform extensions (aider, git, web, search), MindSpace H5 backend/frontend, Plaza/Ops UIs, and deploy scripts for tkmind.cn. Co-authored-by: Cursor <cursoragent@cursor.com>
140 lines
4.4 KiB
JavaScript
140 lines
4.4 KiB
JavaScript
import crypto from 'node:crypto';
|
|
import { initializeDefaultSpace } from './mindspace.mjs';
|
|
|
|
export async function createIntegrationUser(pool, label = 'plaza') {
|
|
const id = crypto.randomUUID();
|
|
const suffix = id.slice(0, 8);
|
|
const username = `${label}_${suffix}`;
|
|
const now = Date.now();
|
|
await pool.query(
|
|
`INSERT INTO h5_users
|
|
(id, username, slug, email, display_name, salt, password_hash, role, workspace_root, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, 'user', ?, ?, ?)`,
|
|
[
|
|
id,
|
|
username,
|
|
username,
|
|
`${username}@plaza.test`,
|
|
`Plaza ${label}`,
|
|
'testsalt',
|
|
'testhash',
|
|
`/tmp/${username}`,
|
|
now,
|
|
now,
|
|
],
|
|
);
|
|
await initializeDefaultSpace(pool, id);
|
|
return { id, username, slug: username };
|
|
}
|
|
|
|
export async function createOnlinePublication(pool, userId, title = 'Plaza Integration Post') {
|
|
const now = Date.now();
|
|
const publicationId = crypto.randomUUID();
|
|
const pageId = crypto.randomUUID();
|
|
const pageVersionId = crypto.randomUUID();
|
|
const contentAssetId = crypto.randomUUID();
|
|
const assetVersionId = crypto.randomUUID();
|
|
const scanId = crypto.randomUUID();
|
|
|
|
const [[space]] = await pool.query(
|
|
`SELECT id FROM h5_user_spaces WHERE user_id = ? LIMIT 1`,
|
|
[userId],
|
|
);
|
|
const [[category]] = await pool.query(
|
|
`SELECT id FROM h5_space_categories
|
|
WHERE user_id = ? AND category_code = 'draft'
|
|
LIMIT 1`,
|
|
[userId],
|
|
);
|
|
if (!space?.id || !category?.id) {
|
|
throw new Error('integration fixture: user space/category missing');
|
|
}
|
|
|
|
await pool.query(
|
|
`INSERT INTO h5_assets
|
|
(id, user_id, space_id, category_id, asset_type, mime_type, original_filename, display_name,
|
|
current_version_id, size_bytes, checksum, visibility, status, source_type, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, 'content', 'text/markdown', 'page.md', ?, ?, 128, ?, 'private', 'ready', 'upload', ?, ?)`,
|
|
[
|
|
contentAssetId,
|
|
userId,
|
|
space.id,
|
|
category.id,
|
|
title,
|
|
assetVersionId,
|
|
'abc123',
|
|
now,
|
|
now,
|
|
],
|
|
);
|
|
await pool.query(
|
|
`INSERT INTO h5_asset_versions
|
|
(id, asset_id, version_no, storage_key, size_bytes, checksum, mime_type, created_by, created_at)
|
|
VALUES (?, ?, 1, ?, 128, ?, 'text/markdown', ?, ?)`,
|
|
[assetVersionId, contentAssetId, `users/${userId}/assets/${contentAssetId}/v1`, 'abc123', userId, now],
|
|
);
|
|
|
|
await pool.query(
|
|
`INSERT INTO h5_page_records
|
|
(id, user_id, space_id, category_id, title, summary, page_type, template_id, status, visibility, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, 'article', 'editorial', 'published', 'public', ?, ?)`,
|
|
[pageId, userId, space.id, category.id, title, 'integration summary', now, now],
|
|
);
|
|
|
|
await pool.query(
|
|
`INSERT INTO h5_security_scans
|
|
(id, user_id, target_type, target_id, scanner_version, status, risk_level, findings_count, started_at, completed_at)
|
|
VALUES (?, ?, 'page_version', ?, 'test', 'passed', 'none', 0, ?, ?)`,
|
|
[scanId, userId, pageVersionId, now, now],
|
|
);
|
|
|
|
await pool.query(
|
|
`INSERT INTO h5_page_versions
|
|
(id, page_id, version_no, content_asset_id, created_by, immutable, created_at)
|
|
VALUES (?, ?, 1, ?, ?, 1, ?)`,
|
|
[pageVersionId, pageId, contentAssetId, userId, now],
|
|
);
|
|
|
|
await pool.query(
|
|
`UPDATE h5_page_records SET current_version_id = ?, updated_at = ? WHERE id = ?`,
|
|
[pageVersionId, now, pageId],
|
|
);
|
|
|
|
await pool.query(
|
|
`INSERT INTO h5_publish_records
|
|
(id, user_id, page_id, page_version_id, url_slug, public_url, access_mode, published_at, status,
|
|
view_count, security_scan_id, created_at, updated_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, 'public', ?, 'online', 0, ?, ?, ?)`,
|
|
[
|
|
publicationId,
|
|
userId,
|
|
pageId,
|
|
pageVersionId,
|
|
`plaza-${publicationId.slice(0, 8)}`,
|
|
`/u/test/pages/plaza-${publicationId.slice(0, 8)}`,
|
|
now,
|
|
scanId,
|
|
now,
|
|
now,
|
|
],
|
|
);
|
|
|
|
return { publicationId, pageId };
|
|
}
|
|
|
|
export async function getPlazaCategoryId(pool, slug = 'work-report') {
|
|
const [[row]] = await pool.query(
|
|
`SELECT id FROM plaza_categories WHERE slug = ? AND is_active = 1 LIMIT 1`,
|
|
[slug],
|
|
);
|
|
return row?.id ?? null;
|
|
}
|
|
|
|
export async function setOpsRole(pool, userId, role = 'reviewer') {
|
|
await pool.query(`UPDATE h5_users SET ops_role = ?, updated_at = ? WHERE id = ?`, [
|
|
role,
|
|
Date.now(),
|
|
userId,
|
|
]);
|
|
}
|