Skip to content

Commit

Permalink
Merge pull request #39 from javad-zobeidi/dev
Browse files Browse the repository at this point in the history
New PR
  • Loading branch information
javad-zobeidi committed Apr 23, 2024
2 parents d9a7787 + 852e5d5 commit 9085f68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
20 changes: 14 additions & 6 deletions lib/src/http/validation/rules.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,24 @@ class Rules {
/// if added supported extension in validation, check with extension
/// return true
static bool isFile(Map<String, dynamic> data, dynamic value, String args) {
if (value is! RequestFile) {
if (value is! RequestFile && value is! List<RequestFile>) {
return false;
}
if (args.toString().isEmpty) {

if (args.isEmpty) {
return true;
}
List<String> extensions = args.toString().split(',');
if (extensions.contains(value.extension)) {
return true;

List<String> validExtensions = args.split(',');

bool hasValidExtension(RequestFile file) {
return validExtensions.contains(file.extension);
}

if (value is List<RequestFile>) {
return value.every(hasValidExtension);
} else {
return hasValidExtension(value);
}
return false;
}
}
7 changes: 5 additions & 2 deletions lib/src/utils/helper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:eloquent/eloquent.dart';
import 'package:vania/vania.dart';

String storagePath(String file) => '${Directory.current.path}/storage/$file';
Expand All @@ -8,6 +9,8 @@ String publicPath(String file) => '${Directory.current.path}/public/$file';

T env<T>(String key, [dynamic defaultValue]) => Env.get<T>(key, defaultValue);

abort(int code,String message){
abort(int code, String message) {
throw HttpResponseException(message: message, code: code);
}
}

Connection get connection => Config().get('database')?.driver?.connection;

0 comments on commit 9085f68

Please sign in to comment.