82 lines
4.0 KiB
JavaScript
82 lines
4.0 KiB
JavaScript
const RETIRED_PAGE_KEYS = [
|
|
'planning_upload', 'market_insight', 'agent', 'ai_skill_tags',
|
|
'store_checkup', 'review_analysis', 'customer_service_checkup',
|
|
'pricing_calculator', 'desktop_client_download', 'ai_buyer_show', 'ai_seeding_video',
|
|
'product_monitoring', 'ops_b_incentive', 'marketing_events', 'promotion_module', 'product_analysis',
|
|
];
|
|
const RETIRED_ENTRY_KEYS = new Set([
|
|
'market-insight', 'agent', 'ai-skill-tags', 'platform-switch',
|
|
'store-management', 'store-checkup', 'review-analysis', 'customer-service-checkup',
|
|
'operation-tools', 'pricing-calculator', 'desktop-client-download', 'ai-buyer-show', 'ai-seeding-video',
|
|
'desktop-client-releases',
|
|
'product-monitoring', 'ops-b-incentive',
|
|
'marketing-management', 'marketing-events', 'promotion-module',
|
|
'product-management', 'product-analysis',
|
|
]);
|
|
const RETIRED_CONFIG_KEYS = [
|
|
'openclaw_chat_config', 'openclaw_chat_skill_tags',
|
|
'selection_similar_products_config', 'alibaba_1688_image_search_config',
|
|
'cs_quality_ai_config', 'desktop_client_releases',
|
|
'ai_buyer_show_ark_api_key', 'ai_buyer_show_ark_base_url',
|
|
'ai_buyer_show_vision_model', 'ai_buyer_show_review_model',
|
|
'product_tag_excluded_categories',
|
|
];
|
|
const RETIRED_DATABASE_CONFIG_NAMES = ['ai_buyer_show_database'];
|
|
|
|
function isRetiredSystemConfigKey(key) {
|
|
return RETIRED_CONFIG_KEYS.includes(String(key || '').trim());
|
|
}
|
|
|
|
function isRetiredDatabaseConfigName(name) {
|
|
return RETIRED_DATABASE_CONFIG_NAMES.includes(String(name || '').trim());
|
|
}
|
|
|
|
function pruneRetiredSidebarConfig(value) {
|
|
try {
|
|
const config = typeof value === 'string' ? JSON.parse(value) : value;
|
|
if (!config || !Array.isArray(config.entries)) return value;
|
|
const prune = (entries) => entries
|
|
.filter((entry) => entry && !RETIRED_ENTRY_KEYS.has(entry.key) && !RETIRED_ENTRY_KEYS.has(entry.routeKey))
|
|
.map((entry) => ({ ...entry, ...(Array.isArray(entry.children) ? { children: prune(entry.children) } : {}) }));
|
|
const result = { ...config, entries: prune(config.entries) };
|
|
return typeof value === 'string' ? JSON.stringify(result) : result;
|
|
} catch {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
async function cleanupRetiredFeatureSettings(db) {
|
|
for (const table of ['permissions', 'department_page_permissions', 'user_page_permissions']) {
|
|
await db.query(`DELETE FROM ${table} WHERE page_key IN (${RETIRED_PAGE_KEYS.map(() => '?').join(',')})`, RETIRED_PAGE_KEYS);
|
|
}
|
|
await db.query(`DELETE FROM system_config WHERE config_key IN (${RETIRED_CONFIG_KEYS.map(() => '?').join(',')})`, RETIRED_CONFIG_KEYS);
|
|
await db.query(`DELETE FROM database_configs WHERE name IN (${RETIRED_DATABASE_CONFIG_NAMES.map(() => '?').join(',')})`, RETIRED_DATABASE_CONFIG_NAMES);
|
|
await db.query('DROP TABLE IF EXISTS pricing_calculator_history');
|
|
await db.query('DROP TABLE IF EXISTS pricing_calculator_user_prefs');
|
|
await db.query('DROP TABLE IF EXISTS ops_b_incentive_snapshots');
|
|
await db.query('DROP TABLE IF EXISTS ops_b_incentive_periods');
|
|
await db.query('DROP TABLE IF EXISTS product_analysis_user_prefs');
|
|
await db.query('DROP TABLE IF EXISTS pdd_goods_first_seen');
|
|
await db.query('DROP TABLE IF EXISTS department_sku_owners');
|
|
await db.query('DROP TABLE IF EXISTS product_tag_rules');
|
|
await db.query('DROP TABLE IF EXISTS product_sabc_mappings');
|
|
await db.query('DROP TABLE IF EXISTS product_profit_levels');
|
|
await db.query('DROP TABLE IF EXISTS product_scale_thresholds');
|
|
const rows = await db.query("SELECT config_value FROM system_config WHERE config_key = ?", ['sidebar_navigation']);
|
|
if (rows.length) {
|
|
const current = rows[0].config_value;
|
|
const next = pruneRetiredSidebarConfig(current);
|
|
if (current !== next) await db.query('UPDATE system_config SET config_value = ? WHERE config_key = ?', [next, 'sidebar_navigation']);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
RETIRED_PAGE_KEYS,
|
|
RETIRED_CONFIG_KEYS,
|
|
RETIRED_DATABASE_CONFIG_NAMES,
|
|
isRetiredSystemConfigKey,
|
|
isRetiredDatabaseConfigName,
|
|
pruneRetiredSidebarConfig,
|
|
cleanupRetiredFeatureSettings,
|
|
};
|