chore: Phase 1 code quality improvements - POSIMAI_BASE_URL explicit, no emoji in logs, model comment update

Made-with: Cursor
This commit is contained in:
Ponshu Developer 2026-04-12 13:23:52 +09:00
parent 0caf370302
commit b3e1f5d0a3
3 changed files with 53 additions and 45 deletions

View File

@ -22,6 +22,9 @@ Get-Content $envFile | ForEach-Object {
$maitaKey = $env:GEMINI_API_KEY_MAITA $maitaKey = $env:GEMINI_API_KEY_MAITA
$eijiKey = $env:GEMINI_API_KEY_EIJI $eijiKey = $env:GEMINI_API_KEY_EIJI
# POSIMAI_BASE_URL: .env.local で上書き可能。未設定時は secrets.dart のデフォルト値と一致させる
$posimaiBaseUrl = if ($env:POSIMAI_BASE_URL) { $env:POSIMAI_BASE_URL } else { 'https://api.soar-enrich.com' }
if (-not $maitaKey) { Write-Error "GEMINI_API_KEY_MAITA not set in .env.local"; exit 1 } if (-not $maitaKey) { Write-Error "GEMINI_API_KEY_MAITA not set in .env.local"; exit 1 }
if (-not $eijiKey) { Write-Error "GEMINI_API_KEY_EIJI not set in .env.local"; exit 1 } if (-not $eijiKey) { Write-Error "GEMINI_API_KEY_EIJI not set in .env.local"; exit 1 }
@ -34,13 +37,15 @@ Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Ponshu Room - Consumer APK Build" -ForegroundColor Cyan Write-Host " Ponshu Room - Consumer APK Build" -ForegroundColor Cyan
Write-Host "============================================" -ForegroundColor Cyan Write-Host "============================================" -ForegroundColor Cyan
Write-Host " Output: $outputDir" -ForegroundColor Gray Write-Host " Output: $outputDir" -ForegroundColor Gray
Write-Host " POSIMAI_BASE_URL: $posimaiBaseUrl" -ForegroundColor Gray
Write-Host "" Write-Host ""
# --- 1. Maita --- # --- 1. Maita ---
Write-Host "[1/2] Building Maita..." -ForegroundColor Yellow Write-Host "[1/2] Building Maita..." -ForegroundColor Yellow
flutter build apk --release ` flutter build apk --release `
--dart-define=GEMINI_API_KEY=$maitaKey ` --dart-define=GEMINI_API_KEY=$maitaKey `
--dart-define=IS_BUSINESS_APP=false --dart-define=IS_BUSINESS_APP=false `
--dart-define=POSIMAI_BASE_URL=$posimaiBaseUrl
if ($LASTEXITCODE -ne 0) { Write-Error "Maita build failed"; exit 1 } if ($LASTEXITCODE -ne 0) { Write-Error "Maita build failed"; exit 1 }
@ -53,7 +58,8 @@ Write-Host " OK: ponshu_room_consumer_maita.apk ($sz MB)" -ForegroundColor Gree
Write-Host "[2/2] Building Eiji..." -ForegroundColor Yellow Write-Host "[2/2] Building Eiji..." -ForegroundColor Yellow
flutter build apk --release ` flutter build apk --release `
--dart-define=GEMINI_API_KEY=$eijiKey ` --dart-define=GEMINI_API_KEY=$eijiKey `
--dart-define=IS_BUSINESS_APP=false --dart-define=IS_BUSINESS_APP=false `
--dart-define=POSIMAI_BASE_URL=$posimaiBaseUrl
if ($LASTEXITCODE -ne 0) { Write-Error "Eiji build failed"; exit 1 } if ($LASTEXITCODE -ne 0) { Write-Error "Eiji build failed"; exit 1 }

View File

@ -37,7 +37,7 @@ class BackupService {
try { try {
await _googleSignIn.signInSilently(); await _googleSignIn.signInSilently();
} catch (e) { } catch (e) {
debugPrint('⚠️ サイレントサインインエラー: $e'); debugPrint('[BACKUP] Silent sign-in error: $e');
} }
} }
@ -62,7 +62,7 @@ class BackupService {
final account = await _googleSignIn.signIn(); final account = await _googleSignIn.signIn();
return account; return account;
} catch (error) { } catch (error) {
debugPrint('❌ Google Sign In エラー: $error'); debugPrint('[BACKUP] Google Sign In error: $error');
return null; return null;
} }
} }
@ -89,14 +89,14 @@ class BackupService {
// 1. // 1.
final account = _googleSignIn.currentUser; final account = _googleSignIn.currentUser;
if (account == null) { if (account == null) {
debugPrint('❌ サインインが必要です'); debugPrint('[BACKUP] Sign-in required');
return false; return false;
} }
// 2. Drive APIクライアントを作成 // 2. Drive APIクライアントを作成
final authClient = await _googleSignIn.authenticatedClient(); final authClient = await _googleSignIn.authenticatedClient();
if (authClient == null) { if (authClient == null) {
debugPrint('❌ 認証クライアントの取得に失敗しました'); debugPrint('[BACKUP] Failed to get authenticated client');
return false; return false;
} }
@ -105,7 +105,7 @@ class BackupService {
// 3. ZIPファイルを作成 // 3. ZIPファイルを作成
final zipFile = await _createBackupZip(); final zipFile = await _createBackupZip();
if (zipFile == null) { if (zipFile == null) {
debugPrint('❌ バックアップファイルの作成に失敗しました'); debugPrint('[BACKUP] Failed to create backup ZIP');
return false; return false;
} }
@ -117,7 +117,7 @@ class BackupService {
return success; return success;
} catch (error) { } catch (error) {
debugPrint('❌ バックアップ作成エラー: $error'); debugPrint('[BACKUP] Backup creation error: $error');
return false; return false;
} }
} }
@ -188,7 +188,7 @@ class BackupService {
}).toList(); }).toList();
final sakeItemsFile = File(path.join(backupDir.path, 'sake_items.json')); final sakeItemsFile = File(path.join(backupDir.path, 'sake_items.json'));
await sakeItemsFile.writeAsString(json.encode(sakeItems)); await sakeItemsFile.writeAsString(json.encode(sakeItems));
debugPrint('📄 sake_items.json 作成: ${await sakeItemsFile.length()} bytes'); debugPrint('[BACKUP] sake_items.json created: ${await sakeItemsFile.length()} bytes');
// 3. settings.jsonを作成 // 3. settings.jsonを作成
final settings = Map<String, dynamic>.from(settingsBox.toMap()); final settings = Map<String, dynamic>.from(settingsBox.toMap());
@ -221,10 +221,10 @@ class BackupService {
// 6. // 6.
await backupDir.delete(recursive: true); await backupDir.delete(recursive: true);
debugPrint('✅ バックアップZIPファイル作成完了: $zipPath'); debugPrint('[BACKUP] ZIP created: $zipPath');
return File(zipPath); return File(zipPath);
} catch (error) { } catch (error) {
debugPrint('❌ ZIP作成エラー: $error'); debugPrint('[BACKUP] ZIP creation error: $error');
return null; return null;
} }
} }
@ -232,7 +232,7 @@ class BackupService {
/// Google DriveにZIPファイルをアップロード /// Google DriveにZIPファイルをアップロード
Future<bool> _uploadToDrive(drive.DriveApi driveApi, File zipFile) async { Future<bool> _uploadToDrive(drive.DriveApi driveApi, File zipFile) async {
try { try {
debugPrint('[BACKUP] 📤 アップロード開始: ${zipFile.lengthSync()} bytes'); debugPrint('[BACKUP] Upload start: ${zipFile.lengthSync()} bytes');
// 1. // 1.
final fileList = await driveApi.files.list( final fileList = await driveApi.files.list(
q: "name = '$backupFileName' and trashed = false", q: "name = '$backupFileName' and trashed = false",
@ -244,9 +244,9 @@ class BackupService {
for (var file in fileList.files!) { for (var file in fileList.files!) {
try { try {
await driveApi.files.delete(file.id!); await driveApi.files.delete(file.id!);
debugPrint('🗑️ [BACKUP] 既存ファイルを削除: ${file.id}'); debugPrint('[BACKUP] Deleted existing file: ${file.id}');
} catch (e) { } catch (e) {
debugPrint('⚠️ [BACKUP] 既存ファイル削除失敗 (無視): $e'); debugPrint('[BACKUP] Failed to delete existing file (ignored): $e');
} }
} }
} }
@ -257,7 +257,7 @@ class BackupService {
final media = drive.Media(zipFile.openRead(), zipFile.lengthSync()); final media = drive.Media(zipFile.openRead(), zipFile.lengthSync());
debugPrint('[BACKUP] 🚀 Driveへ送信中...'); debugPrint('[BACKUP] Uploading to Drive...');
final uploadedFile = await driveApi.files.create( final uploadedFile = await driveApi.files.create(
driveFile, driveFile,
uploadMedia: media, uploadMedia: media,
@ -266,11 +266,11 @@ class BackupService {
}); });
if (uploadedFile.id == null) { if (uploadedFile.id == null) {
debugPrint('❌ [BACKUP] ID取得失敗'); debugPrint('[BACKUP] Upload failed: no file ID returned');
return false; return false;
} }
debugPrint('✅ [BACKUP] アップロード完了 ID: ${uploadedFile.id}'); debugPrint('[BACKUP] Upload complete. ID: ${uploadedFile.id}');
// 4. // 4.
int retryCount = 0; int retryCount = 0;
@ -281,16 +281,16 @@ class BackupService {
try { try {
await driveApi.files.get(uploadedFile.id!); await driveApi.files.get(uploadedFile.id!);
verified = true; verified = true;
debugPrint('✅ [BACKUP] 検証成功'); debugPrint('[BACKUP] Verification succeeded');
} catch (e) { } catch (e) {
debugPrint('⚠️ [BACKUP] 検証試行 ${retryCount + 1} 失敗: $e'); debugPrint('[BACKUP] Verification attempt ${retryCount + 1} failed: $e');
} }
retryCount++; retryCount++;
} }
return verified; return verified;
} catch (error) { } catch (error) {
debugPrint('❌ [BACKUP] アップロードエラー: $error'); debugPrint('[BACKUP] Upload error: $error');
return false; return false;
} }
} }
@ -312,14 +312,14 @@ class BackupService {
// 1. // 1.
final account = _googleSignIn.currentUser; final account = _googleSignIn.currentUser;
if (account == null) { if (account == null) {
debugPrint('❌ サインインが必要です'); debugPrint('[RESTORE] Sign-in required');
return false; return false;
} }
// 2. Drive APIクライアントを作成 // 2. Drive APIクライアントを作成
final authClient = await _googleSignIn.authenticatedClient(); final authClient = await _googleSignIn.authenticatedClient();
if (authClient == null) { if (authClient == null) {
debugPrint('❌ 認証クライアントの取得に失敗しました'); debugPrint('[RESTORE] Failed to get authenticated client');
return false; return false;
} }
@ -331,7 +331,7 @@ class BackupService {
// 4. Google Driveからダウンロード // 4. Google Driveからダウンロード
final zipFile = await _downloadFromDrive(driveApi); final zipFile = await _downloadFromDrive(driveApi);
if (zipFile == null) { if (zipFile == null) {
debugPrint('❌ ダウンロードに失敗しました'); debugPrint('[RESTORE] Download failed');
return false; return false;
} }
@ -343,7 +343,7 @@ class BackupService {
return success; return success;
} catch (error) { } catch (error) {
debugPrint('❌ 復元エラー: $error'); debugPrint('[RESTORE] Restore error: $error');
return false; return false;
} }
} }
@ -358,10 +358,10 @@ class BackupService {
if (zipFile != null) { if (zipFile != null) {
await zipFile.copy(backupPath); await zipFile.copy(backupPath);
await zipFile.delete(); await zipFile.delete();
debugPrint('✅ 復元前のデータを退避しました: $backupPath'); debugPrint('[RESTORE] Pre-restore backup saved: $backupPath');
} }
} catch (error) { } catch (error) {
debugPrint('⚠️ データ退避エラー: $error'); debugPrint('[RESTORE] Pre-restore backup error: $error');
} }
} }
@ -375,7 +375,7 @@ class BackupService {
); );
if (fileList.files == null || fileList.files!.isEmpty) { if (fileList.files == null || fileList.files!.isEmpty) {
debugPrint('❌ バックアップファイルが見つかりません'); debugPrint('[RESTORE] No backup file found on Drive');
return null; return null;
} }
@ -395,10 +395,10 @@ class BackupService {
final sink = downloadFile.openWrite(); final sink = downloadFile.openWrite();
await media.stream.pipe(sink); await media.stream.pipe(sink);
debugPrint('✅ ダウンロード完了: $downloadPath'); debugPrint('[RESTORE] Download complete: $downloadPath');
return downloadFile; return downloadFile;
} catch (error) { } catch (error) {
debugPrint('❌ ダウンロードエラー: $error'); debugPrint('[RESTORE] Download error: $error');
return null; return null;
} }
} }
@ -430,12 +430,12 @@ class BackupService {
final outFile = File(extractPath); final outFile = File(extractPath);
await outFile.create(recursive: true); await outFile.create(recursive: true);
await outFile.writeAsBytes(data); await outFile.writeAsBytes(data);
debugPrint('📦 展開: $filename (${data.length} bytes)'); debugPrint('[RESTORE] Extracted: $filename (${data.length} bytes)');
} }
} }
// : // :
debugPrint('📂 展開ディレクトリの中身:'); debugPrint('[RESTORE] Extracted directory contents:');
extractDir.listSync(recursive: true).forEach((f) => debugPrint(' - ${path.basename(f.path)}')); extractDir.listSync(recursive: true).forEach((f) => debugPrint(' - ${path.basename(f.path)}'));
// 2. sake_items.jsonを検索 () // 2. sake_items.jsonを検索 ()
@ -446,12 +446,12 @@ class BackupService {
sakeItemsFile = potentialFiles.firstWhere((f) => path.basename(f.path) == 'sake_items.json'); sakeItemsFile = potentialFiles.firstWhere((f) => path.basename(f.path) == 'sake_items.json');
} catch (e) { } catch (e) {
// //
debugPrint('❌ sake_items.json が見つかりません'); debugPrint('[RESTORE] sake_items.json not found');
} }
if (sakeItemsFile != null && await sakeItemsFile.exists()) { if (sakeItemsFile != null && await sakeItemsFile.exists()) {
final sakeItemsJson = json.decode(await sakeItemsFile.readAsString()) as List; final sakeItemsJson = json.decode(await sakeItemsFile.readAsString()) as List;
debugPrint('🔍 復元対象データ数: ${sakeItemsJson.length}'); debugPrint('[RESTORE] Items to restore: ${sakeItemsJson.length}');
final sakeBox = Hive.box<SakeItem>('sake_items'); final sakeBox = Hive.box<SakeItem>('sake_items');
await sakeBox.clear(); await sakeBox.clear();
@ -499,7 +499,7 @@ class BackupService {
// IDを保持するためにput()使add() // IDを保持するためにput()使add()
await sakeBox.put(item.id, item); await sakeBox.put(item.id, item);
} }
debugPrint('✅ SakeItemsを復元しました${sakeItemsJson.length}件)'); debugPrint('[RESTORE] SakeItems restored (${sakeItemsJson.length} items)');
// UI更新のためにわずかに待機 // UI更新のためにわずかに待機
await Future.delayed(const Duration(milliseconds: 500)); await Future.delayed(const Duration(milliseconds: 500));
} }
@ -509,7 +509,7 @@ class BackupService {
try { try {
settingsFile = potentialFiles.firstWhere((f) => path.basename(f.path) == 'settings.json'); settingsFile = potentialFiles.firstWhere((f) => path.basename(f.path) == 'settings.json');
} catch (e) { } catch (e) {
debugPrint('⚠️ settings.json が見つかりません (スキップ)'); debugPrint('[RESTORE] settings.json not found (skipped)');
} }
if (settingsFile != null && await settingsFile.exists()) { if (settingsFile != null && await settingsFile.exists()) {
@ -520,7 +520,7 @@ class BackupService {
for (var entry in settingsJson.entries) { for (var entry in settingsJson.entries) {
await settingsBox.put(entry.key, entry.value); await settingsBox.put(entry.key, entry.value);
} }
debugPrint('✅ 設定を復元しました'); debugPrint('[RESTORE] Settings restored');
} }
// 4. (sake_items.jsonと同じ階層のimagesフォルダを探す) // 4. (sake_items.jsonと同じ階層のimagesフォルダを探す)
@ -538,17 +538,17 @@ class BackupService {
await imageFile.copy(path.join(appDir.path, fileName)); await imageFile.copy(path.join(appDir.path, fileName));
} }
} }
debugPrint('✅ 画像ファイルを復元しました(${imageFiles.length}ファイル)'); debugPrint('[RESTORE] Images restored (${imageFiles.length} files)');
} }
} }
// 5. // 5.
await extractDir.delete(recursive: true); await extractDir.delete(recursive: true);
debugPrint('✅ データの復元が完了しました'); debugPrint('[RESTORE] Restore complete');
return true; return true;
} catch (error) { } catch (error) {
debugPrint('❌ 復元処理エラー: $error'); debugPrint('[RESTORE] Restore process error: $error');
// //
debugPrint(error.toString()); debugPrint(error.toString());
if (error is Error) { if (error is Error) {
@ -576,7 +576,7 @@ class BackupService {
return fileList.files != null && fileList.files!.isNotEmpty; return fileList.files != null && fileList.files!.isNotEmpty;
} catch (error) { } catch (error) {
debugPrint('❌ バックアップ確認エラー: $error'); debugPrint('[BACKUP] Check error: $error');
return false; return false;
} }
} }

View File

@ -199,8 +199,10 @@ class GeminiService {
} }
// : 503/UNAVAILABLE // : 503/UNAVAILABLE
const primaryModel = 'gemini-2.5-flash'; // FIXED - confirmed 2026-01-17 // NOTE: Google
const fallbackModel = 'gemini-2.0-flash'; // 503 // Phase 2
const primaryModel = 'gemini-2.5-flash';
const fallbackModel = 'gemini-2.0-flash';
// Prepare Prompt (customPrompt null ) // Prepare Prompt (customPrompt null )
final promptText = customPrompt ?? ''' final promptText = customPrompt ?? '''