stuff
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions
This commit is contained in:
parent
c14a7ba87e
commit
22d5ee4bd6
1 changed files with 7 additions and 87 deletions
|
|
@ -831,66 +831,20 @@ class AdminCardsApiV2 {
|
|||
error: 'Validation error',
|
||||
message: 'Voice URL is required',
|
||||
field: 'voiceUrl',
|
||||
details: 'Please provide a valid voice URL (base64 encoded audio data) to add a voice to the card.',
|
||||
details: 'Please provide a valid object ID (UUID) to add a voice to the card.',
|
||||
).toJson(),
|
||||
statusCode: 400,
|
||||
);
|
||||
}
|
||||
|
||||
// Validate base64 format (basic check)
|
||||
try {
|
||||
// Remove data URL prefix if present (data:audio/...;base64,)
|
||||
final base64String = requestDto.voiceUrl.contains(',')
|
||||
? requestDto.voiceUrl.split(',').last
|
||||
: requestDto.voiceUrl;
|
||||
|
||||
// Basic base64 validation - check if it's valid base64
|
||||
if (base64String.isEmpty) {
|
||||
return _json(
|
||||
ErrorResponse(
|
||||
error: 'Validation error',
|
||||
message: 'Invalid base64 audio data',
|
||||
field: 'voiceUrl',
|
||||
details: 'The provided voice URL does not contain valid base64 encoded audio data.',
|
||||
).toJson(),
|
||||
statusCode: 400,
|
||||
);
|
||||
}
|
||||
|
||||
// Check base64 characters (basic validation)
|
||||
final base64Regex = RegExp(r'^[A-Za-z0-9+/]*={0,2}$');
|
||||
if (!base64Regex.hasMatch(base64String)) {
|
||||
return _json(
|
||||
ErrorResponse(
|
||||
error: 'Validation error',
|
||||
message: 'Invalid base64 format',
|
||||
field: 'voiceUrl',
|
||||
details: 'The provided voice URL does not appear to be valid base64 encoded data.',
|
||||
).toJson(),
|
||||
statusCode: 400,
|
||||
);
|
||||
}
|
||||
|
||||
// Check size (base64 is ~33% larger than original, so 10MB audio = ~13.3MB base64)
|
||||
// Limit to ~15MB base64 string (roughly 11MB audio)
|
||||
if (base64String.length > 15 * 1024 * 1024) {
|
||||
return _json(
|
||||
ErrorResponse(
|
||||
error: 'Validation error',
|
||||
message: 'Audio file too large',
|
||||
field: 'voiceUrl',
|
||||
details: 'The audio file is too large. Maximum size is approximately 10MB for the original audio file.',
|
||||
).toJson(),
|
||||
statusCode: 400,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// Validate that voiceUrl is a UUID (object ID from MinIO)
|
||||
if (!_isValidUuid(requestDto.voiceUrl)) {
|
||||
return _json(
|
||||
ErrorResponse(
|
||||
error: 'Validation error',
|
||||
message: 'Invalid voice URL format',
|
||||
message: 'Invalid object ID format',
|
||||
field: 'voiceUrl',
|
||||
details: 'Failed to validate the voice URL. Please ensure it is a valid base64 encoded audio file.',
|
||||
details: 'The provided voice URL must be a valid UUID (object ID from MinIO).',
|
||||
).toJson(),
|
||||
statusCode: 400,
|
||||
);
|
||||
|
|
@ -909,42 +863,8 @@ class AdminCardsApiV2 {
|
|||
);
|
||||
}
|
||||
|
||||
// Parse base64 audio and upload to MinIO
|
||||
final parsed = VoiceStorage.tryParseBase64Audio(requestDto.voiceUrl);
|
||||
if (parsed == null) {
|
||||
return _json(
|
||||
ErrorResponse(
|
||||
error: 'Validation error',
|
||||
message: 'Invalid base64 audio data',
|
||||
field: 'voiceUrl',
|
||||
details:
|
||||
'Failed to decode the provided base64 audio. Please upload a valid base64 encoded audio file.',
|
||||
).toJson(),
|
||||
statusCode: 400,
|
||||
);
|
||||
}
|
||||
|
||||
// Upload to MinIO
|
||||
String objectId;
|
||||
try {
|
||||
objectId = await _minioService.uploadFile(
|
||||
bucket: MinioConfig.voiceAudioBucket,
|
||||
bytes: parsed.bytes,
|
||||
contentType: parsed.contentType,
|
||||
);
|
||||
} catch (e) {
|
||||
print('Error uploading voice to MinIO: $e');
|
||||
return _json(
|
||||
ErrorResponse(
|
||||
error: 'Storage error',
|
||||
message: 'Failed to upload audio file',
|
||||
field: 'voiceUrl',
|
||||
details:
|
||||
'Failed to upload the audio file to storage. Please try again later.',
|
||||
).toJson(),
|
||||
statusCode: 500,
|
||||
);
|
||||
}
|
||||
// Use the object ID directly
|
||||
final objectId = requestDto.voiceUrl;
|
||||
|
||||
// Create voice record with object ID
|
||||
final voiceId = await _db.packDao.createVoice(
|
||||
|
|
|
|||
Loading…
Reference in a new issue