Move admin auth local
This commit is contained in:
+39
-8
@@ -1,7 +1,8 @@
|
||||
import path from 'node:path';
|
||||
import { createDbPool, isDatabaseConfigured } from './db.mjs';
|
||||
import { importMemind, resolveMemindLib } from './lib-path.mjs';
|
||||
import { projectRoot } from './load-env.mjs';
|
||||
import { createLocalUserAuth } from './local-auth.mjs';
|
||||
import { importMemind, resolveMemindLib } from './lib-path.mjs';
|
||||
|
||||
export async function bootstrapAdminServices() {
|
||||
if (!isDatabaseConfigured()) {
|
||||
@@ -10,19 +11,44 @@ export async function bootstrapAdminServices() {
|
||||
|
||||
const memindLib = resolveMemindLib();
|
||||
const pool = createDbPool();
|
||||
const { createUserAuth } = await importMemind('user-auth.mjs');
|
||||
const { createLlmProviderService } = await importMemind('llm-providers.mjs');
|
||||
const { createWechatAdminService } = await importMemind('wechat-admin.mjs');
|
||||
const { loadWechatMpConfig } = await importMemind('wechat-mp.mjs');
|
||||
const { createPlazaPostService, formatPostRow } = await importMemind('plaza-posts.mjs');
|
||||
const { createPlazaInteractionService } = await importMemind('plaza-interactions.mjs');
|
||||
const { createPlazaOpsService } = await importMemind('plaza-ops.mjs');
|
||||
const { createNoopPlazaRedis } = await importMemind('plaza-redis.mjs');
|
||||
const { ensureAlgorithmConfig, loadAlgorithmConfig } = await importMemind('plaza-algorithm.mjs');
|
||||
const { createOpsApi } = await importMemind('admin-routes.mjs');
|
||||
|
||||
const usersRoot =
|
||||
process.env.H5_USERS_ROOT?.trim() ?? path.join(projectRoot, 'data', 'users');
|
||||
const apiTarget = process.env.TKMIND_API_TARGET ?? 'https://127.0.0.1:18006';
|
||||
const apiSecret = process.env.TKMIND_SERVER__SECRET_KEY ?? 'local-dev-secret';
|
||||
const plazaRedis = createNoopPlazaRedis();
|
||||
|
||||
const userAuth = createUserAuth(pool, {
|
||||
usersRoot,
|
||||
h5Root: memindLib,
|
||||
defaultSignupBalanceCents: Number(process.env.H5_SIGNUP_BALANCE_CENTS ?? 500),
|
||||
await ensureAlgorithmConfig(pool);
|
||||
const algorithmConfig = await loadAlgorithmConfig(pool);
|
||||
const plazaInteractions = createPlazaInteractionService(pool, { formatPostRow, plazaRedis });
|
||||
|
||||
let plazaOps = null;
|
||||
const plazaPosts = createPlazaPostService(pool, {
|
||||
loadViewerReactions: (viewerId, postIds) =>
|
||||
plazaInteractions.loadViewerReactions(viewerId, postIds),
|
||||
plazaRedis,
|
||||
algorithmConfig,
|
||||
onPostPublished: () => {},
|
||||
loadFeaturedPosts: async (viewerId) => {
|
||||
if (!plazaOps) return { homepage_banner: [], trending: [], category_top: {} };
|
||||
return plazaOps.loadActiveFeaturedPosts(viewerId);
|
||||
},
|
||||
});
|
||||
plazaOps = createPlazaOpsService(pool, {
|
||||
formatPostRow,
|
||||
reviewPost: (...args) => plazaPosts.reviewPost(...args),
|
||||
invalidateFeedCaches: () => plazaRedis?.invalidateFeedCaches?.(),
|
||||
});
|
||||
|
||||
const userAuth = createLocalUserAuth(pool);
|
||||
|
||||
await userAuth.ensureAdminUser();
|
||||
|
||||
@@ -30,10 +56,15 @@ export async function bootstrapAdminServices() {
|
||||
apiTarget,
|
||||
apiSecret,
|
||||
});
|
||||
const wechatAdmin = createWechatAdminService(pool, {
|
||||
config: loadWechatMpConfig(),
|
||||
scheduleEnabled: process.env.H5_SCHEDULE_ENABLED === '1',
|
||||
reminderWorkerEnabled: process.env.H5_REMINDER_WORKER_ENABLED === '1',
|
||||
});
|
||||
|
||||
console.log(`Admin DB connected (${process.env.MYSQL_DATABASE ?? 'via DATABASE_URL'})`);
|
||||
console.log(`Users root: ${usersRoot}`);
|
||||
console.log(`Memind lib: ${memindLib}`);
|
||||
|
||||
return { pool, userAuth, llmProviderService };
|
||||
return { pool, userAuth, llmProviderService, plazaOps, createOpsApi, wechatAdmin };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user