portal-auth P2(#24 #25):portal_user 模型+認證 API(不 merge,待總管審) (#51)

This commit was merged in pull request #51.
This commit is contained in:
Leo
2026-07-14 04:19:54 +00:00
parent 7f409646e5
commit 1260d8cffb
11 changed files with 1372 additions and 14 deletions
+9 -3
View File
@@ -22,6 +22,7 @@ import type { RecipeDefinition, AuthRecipeDefinition } from './recipes';
import { installRecipeRecord, resolveRecipe } from './recipes';
import { API_RECIPE_SEEDS } from '../lib/api-recipe-seeds';
import { AUTH_RECIPE_SEEDS } from '../lib/auth-recipe-seeds';
import { ensurePortalTemplates } from './portal';
export const initSeedRouter = new Hono<{ Bindings: Bindings }>();
@@ -82,15 +83,20 @@ initSeedRouter.post('/init/seed', async (c) => {
}
}
const allOk = apiFail === 0 && authFail === 0;
// portal-auth P2#24/#25):portal_user / portal_library template 也是「裝好後預設就緒」
// 的種子(KBDB 萬用表 template,零新表),冪等 ensure(已存在跳過)。seed 是 API 行為(rule 07)。
const portalTemplates = await ensurePortalTemplates(c.env);
const allOk = apiFail === 0 && authFail === 0 && portalTemplates.errors.length === 0;
return c.json(
{
success: allOk,
api_recipes: { seeded: apiOk, failed: apiFail, errors: apiErrors },
auth_recipes: { seeded: authOk, failed: authFail, errors: authErrors },
portal_templates: portalTemplates,
message: allOk
? `seed 完成:${apiOk} 個 API recipe + ${authOk} 個 auth recipe`
: `seed 部分失敗(誠實回報,未假綠):API ${apiOk}✓/${apiFail}✗,auth ${authOk}✓/${authFail}`,
? `seed 完成:${apiOk} 個 API recipe + ${authOk} 個 auth recipe + portal templates(新建 ${portalTemplates.created.length}/已存在 ${portalTemplates.existing.length}`
: `seed 部分失敗(誠實回報,未假綠):API ${apiOk}✓/${apiFail}✗,auth ${authOk}✓/${authFail}portal templates 錯誤 ${portalTemplates.errors.length}`,
},
allOk ? 200 : 207,
);