mirror of
https://github.com/foss42/apidash.git
synced 2025-12-04 03:46:57 +08:00
Move curl import to core
This commit is contained in:
@@ -5,6 +5,7 @@ export 'extensions/extensions.dart';
|
||||
export 'models/models.dart';
|
||||
export 'utils/utils.dart';
|
||||
export 'services/services.dart';
|
||||
export 'parsers/parsers.dart';
|
||||
|
||||
// Export 3rd party packages
|
||||
export 'package:collection/collection.dart';
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import 'package:curl_parser/curl_parser.dart';
|
||||
import '../consts.dart';
|
||||
import '../models/models.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class CurlFileImport {
|
||||
List<HttpRequestModel>? getHttpRequestModel(String content) {
|
||||
content = content.trim();
|
||||
try {
|
||||
final curl = Curl.parse(content);
|
||||
final url = stripUriParams(curl.uri);
|
||||
final method = HTTPVerb.values.byName(curl.method.toLowerCase());
|
||||
final headers = mapToRows(curl.headers);
|
||||
final params = mapToRows(curl.uri.queryParameters);
|
||||
final body = curl.data;
|
||||
// TODO: formdata with file paths must be set to empty as
|
||||
// there will be permission issue while trying to access the path
|
||||
final formData = curl.formData;
|
||||
// Determine content type based on form data and headers
|
||||
final ContentType contentType = curl.form
|
||||
? ContentType.formdata
|
||||
: (getContentTypeFromHeadersMap(curl.headers) ?? ContentType.text);
|
||||
|
||||
return [
|
||||
HttpRequestModel(
|
||||
method: method,
|
||||
url: url,
|
||||
headers: headers,
|
||||
params: params,
|
||||
body: body,
|
||||
bodyContentType: contentType,
|
||||
formData: formData,
|
||||
),
|
||||
];
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
packages/apidash_core/lib/parsers/parsers.dart
Normal file
2
packages/apidash_core/lib/parsers/parsers.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
export 'curl_to_http_request_model.dart';
|
||||
export 'postman_to_http_request_model.dart';
|
||||
@@ -12,6 +12,8 @@ dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
collection: ^1.18.0
|
||||
curl_parser:
|
||||
path: ../curl_parser
|
||||
freezed_annotation: ^2.4.1
|
||||
http: ^1.2.1
|
||||
http_parser: ^4.0.2
|
||||
@@ -25,40 +27,3 @@ dev_dependencies:
|
||||
flutter_lints: ^4.0.0
|
||||
freezed: ^2.5.7
|
||||
test: ^1.25.2
|
||||
|
||||
# For information on the generic Dart part of this file, see the
|
||||
# following page: https://dart.dev/tools/pub/pubspec
|
||||
|
||||
# The following section is specific to Flutter packages.
|
||||
flutter:
|
||||
|
||||
# To add assets to your package, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
# - images/a_dot_ham.jpeg
|
||||
#
|
||||
# For details regarding assets in packages, see
|
||||
# https://flutter.dev/to/asset-from-package
|
||||
#
|
||||
# An image asset can refer to one or more resolution-specific "variants", see
|
||||
# https://flutter.dev/to/resolution-aware-images
|
||||
|
||||
# To add custom fonts to your package, add a fonts section here,
|
||||
# in this "flutter" section. Each entry in this list should have a
|
||||
# "family" key with the font family name, and a "fonts" key with a
|
||||
# list giving the asset and other descriptors for the font. For
|
||||
# example:
|
||||
# fonts:
|
||||
# - family: Schyler
|
||||
# fonts:
|
||||
# - asset: fonts/Schyler-Regular.ttf
|
||||
# - asset: fonts/Schyler-Italic.ttf
|
||||
# style: italic
|
||||
# - family: Trajan Pro
|
||||
# fonts:
|
||||
# - asset: fonts/TrajanPro.ttf
|
||||
# - asset: fonts/TrajanPro_Bold.ttf
|
||||
# weight: 700
|
||||
#
|
||||
# For details regarding fonts in packages, see
|
||||
# https://flutter.dev/to/font-from-package
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
# melos_managed_dependency_overrides: seed
|
||||
# melos_managed_dependency_overrides: seed,curl_parser
|
||||
dependency_overrides:
|
||||
curl_parser:
|
||||
path: ../curl_parser
|
||||
seed:
|
||||
path: ../seed
|
||||
|
||||
Reference in New Issue
Block a user