mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +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';
|
||||
Reference in New Issue
Block a user