fix: configuration Firebase acceptée avec guillemets typographiques ou google-services.json
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R9CBCVP5oDu2sfoYPisNCQ
This commit is contained in:
1 parent
1d707f8785
commit
11d7ed1fa6
2 files changed
+31
-4
No files matched your search
@@ -7,7 +7,7 @@ data class FirebaseConfig(val apiKey: String, val appId: String, val projectId:
|
||||
companion object {
|
||||
/**
|
||||
* Lit ce que l'utilisateur colle : le bloc `firebaseConfig` de la console (JavaScript), un JSON,
|
||||
* ou une chaîne « fc1:… » partagée par FamilyControl. Renvoie null si apiKey, appId ou projectId manque.
|
||||
* le fichier google-services.json, ou une chaîne « fc1:… » partagée par FamilyControl. Renvoie null si apiKey, appId ou projectId manque.
|
||||
*/
|
||||
fun parse(input: String): FirebaseConfig? {
|
||||
val text = input.trim()
|
||||
@@ -17,9 +17,17 @@ data class FirebaseConfig(val apiKey: String, val appId: String, val projectId:
|
||||
build(json.optString("apiKey"), json.optString("appId"), json.optString("projectId"))
|
||||
}.getOrNull()
|
||||
}
|
||||
fun pick(name: String) =
|
||||
Regex("""["']?$name["']?\s*[:=]\s*["']([^"']+)["']""").find(text)?.groupValues?.get(1)
|
||||
return build(pick("apiKey"), pick("appId"), pick("projectId"))
|
||||
// Guillemets typographiques (souvent insérés par un copier-coller sur téléphone) → droits.
|
||||
val plain = text.replace(Regex("[“”„«»]"), "\"").replace(Regex("[‘’]"), "'")
|
||||
// Noms du bloc Web (apiKey…) ou du fichier google-services.json de l'application Android.
|
||||
fun pick(vararg names: String) = names.firstNotNullOfOrNull { name ->
|
||||
Regex("""["']?\b$name["']?\s*[:=]\s*["']\s*([^"'\s]+)\s*["']""").find(plain)?.groupValues?.get(1)
|
||||
}
|
||||
return build(
|
||||
pick("apiKey", "current_key"),
|
||||
pick("appId", "mobilesdk_app_id"),
|
||||
pick("projectId", "project_id")
|
||||
)
|
||||
}
|
||||
|
||||
private fun build(apiKey: String?, appId: String?, projectId: String?): FirebaseConfig? =
|
||||
|
||||
Reference in new issue
Block a user