feat(inscription): payload enfant/photo et limite JSON 15 Mo côté API

- Express/Nest : body parser json et urlencoded à 15 Mo pour les photos base64.
- Front : envoi d’inscription parent (authService, payload, étape 3).

Made-with: Cursor
This commit is contained in:
2026-04-11 16:36:15 +02:00
parent d7ccbfbe35
commit 4969be5809
5 changed files with 155 additions and 37 deletions
@@ -102,7 +102,7 @@ class ParentRegistrationPayload {
final tel = _normalizePhone(p1.phone);
final body = <String, dynamic>{
'email': p1.email.trim(),
'email': normalizeEmailText(p1.email),
'prenom': p1.firstName.trim(),
'nom': p1.lastName.trim(),
'telephone': tel,
@@ -188,6 +188,51 @@ class ParentRegistrationPayload {
return map;
}
/// Sous-type `image/…` pour data-URL et extension côté API (`jpeg`, `png`, `gif`, `heic`, …).
static String _imageMimeFromMagicBytes(Uint8List bytes) {
if (bytes.length >= 8) {
if (bytes[0] == 0x89 &&
bytes[1] == 0x50 &&
bytes[2] == 0x4E &&
bytes[3] == 0x47) {
return 'png';
}
if (bytes[0] == 0xFF && bytes[1] == 0xD8) {
return 'jpeg';
}
if (bytes.length >= 12 &&
bytes[0] == 0x52 &&
bytes[1] == 0x49 &&
bytes[2] == 0x46 &&
bytes[3] == 0x46) {
return 'webp';
}
if (bytes.length >= 6 &&
bytes[0] == 0x47 &&
bytes[1] == 0x49 &&
bytes[2] == 0x46 &&
bytes[3] == 0x38 &&
(bytes[4] == 0x37 || bytes[4] == 0x39) &&
bytes[5] == 0x61) {
return 'gif';
}
if (bytes.length >= 12 &&
bytes[4] == 0x66 &&
bytes[5] == 0x74 &&
bytes[6] == 0x79 &&
bytes[7] == 0x70) {
final a = bytes[8], b = bytes[9], c = bytes[10], d = bytes[11];
if ((a == 0x68 && b == 0x65 && c == 0x69 && d == 0x63) ||
(a == 0x68 && b == 0x65 && c == 0x69 && d == 0x78) ||
(a == 0x6d && b == 0x69 && c == 0x66 && d == 0x31) ||
(a == 0x6d && b == 0x73 && c == 0x66 && d == 0x31)) {
return 'heic';
}
}
}
return 'jpeg';
}
/// (`dataUrl`, `filename`) ou `null` si pas de fichier lisible.
static (String, String)? _childPhotoBase64(ChildData c, int index, String prenom) {
Uint8List? bytes = c.imageBytes;
@@ -203,23 +248,7 @@ class ParentRegistrationPayload {
}
if (bytes.isEmpty) return null;
final b64 = base64Encode(bytes);
var mime = 'jpeg';
if (bytes.length >= 8) {
if (bytes[0] == 0x89 &&
bytes[1] == 0x50 &&
bytes[2] == 0x4E &&
bytes[3] == 0x47) {
mime = 'png';
} else if (bytes[0] == 0xFF && bytes[1] == 0xD8) {
mime = 'jpeg';
} else if (bytes.length >= 12 &&
bytes[0] == 0x52 &&
bytes[1] == 0x49 &&
bytes[2] == 0x46 &&
bytes[3] == 0x46) {
mime = 'webp';
}
}
final mime = _imageMimeFromMagicBytes(bytes);
final safeName = prenom.isNotEmpty
? '${prenom.toLowerCase().replaceAll(RegExp(r'[^a-z0-9]+'), '_')}.$mime'
: 'enfant_${index + 1}.$mime';