feat: add French localization support for character attributes and improve character display logic
All checks were successful
Build Docker Image / build (push) Successful in 1m18s
All checks were successful
Build Docker Image / build (push) Successful in 1m18s
- Added optional French names, affiliations, origins, and epithets to character records. - Updated character import logic to handle new French fields. - Enhanced character search and display components to show French names and epithets based on selected language. - Modified database schema to include French fields for characters. - Improved error handling in daily character setup to check for existing characters. - Refactored components to utilize helper functions for displaying names and attributes based on language.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { createClient } from '@libsql/client';
|
||||
import { drizzle } from 'drizzle-orm/libsql';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { eq, inArray } from 'drizzle-orm';
|
||||
import fs from 'fs';
|
||||
import { character, characterHistory } from '../src/lib/server/db/schema';
|
||||
|
||||
@@ -24,13 +24,14 @@ function getErrorMessage(error: unknown): string {
|
||||
|
||||
async function setDailyCharacters(): Promise<void> {
|
||||
try {
|
||||
const dailyCharacterIds = readJsonFile('./scripts/daily-characters.json');
|
||||
const dailyCharacterIdsRaw = readJsonFile('./scripts/daily-characters.json');
|
||||
|
||||
if (!dailyCharacterIds || dailyCharacterIds.length === 0) {
|
||||
console.error('❌ No daily characters found in daily-characters.json');
|
||||
process.exit(1);
|
||||
if (!dailyCharacterIdsRaw || dailyCharacterIdsRaw.length === 0) {
|
||||
throw new Error('No daily characters found in daily-characters.json');
|
||||
}
|
||||
|
||||
const dailyCharacterIds = dailyCharacterIdsRaw;
|
||||
|
||||
console.log(`\n=== Setting Daily Mode Characters ===\n`);
|
||||
console.log(`Found ${dailyCharacterIds.length} characters to set as daily\n`);
|
||||
|
||||
@@ -45,16 +46,36 @@ async function setDailyCharacters(): Promise<void> {
|
||||
let successCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
const existingCharacters = await db
|
||||
.select({ id: character.id })
|
||||
.from(character)
|
||||
.where(inArray(character.id, dailyCharacterIds));
|
||||
|
||||
const existingIdSet = new Set(existingCharacters.map((c) => c.id));
|
||||
const missingIds = dailyCharacterIds.filter((id) => !existingIdSet.has(id));
|
||||
|
||||
if (missingIds.length > 0) {
|
||||
errorCount += missingIds.length;
|
||||
console.error(`✗ ${missingIds.length} character ID(s) were not found in database:`);
|
||||
for (const missingId of missingIds) {
|
||||
console.error(` - ${missingId}`);
|
||||
}
|
||||
console.error('');
|
||||
}
|
||||
|
||||
for (let i = 0; i < dailyCharacterIds.length; i++) {
|
||||
const charId = dailyCharacterIds[i];
|
||||
if (!existingIdSet.has(charId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await db
|
||||
await db
|
||||
.update(character)
|
||||
.set({ isInDailyMode: true })
|
||||
.where(eq(character.id, charId));
|
||||
|
||||
successCount++;
|
||||
process.stdout.write(`\rUpdated: ${successCount}/${dailyCharacterIds.length}`);
|
||||
} catch (error) {
|
||||
errorCount++;
|
||||
console.error(`\n✗ Error updating character ${i + 1}:`);
|
||||
|
||||
Reference in New Issue
Block a user