mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 18:57:05 +08:00
Move curl import to core
This commit is contained in:
@@ -28,11 +28,14 @@ void importToCollectionPane(
|
||||
(content) {
|
||||
kImporter
|
||||
.getHttpRequestModel(importFormatType, content)
|
||||
.then((importedRequestModel) {
|
||||
if (importedRequestModel != null) {
|
||||
.then((importedRequestModels) {
|
||||
if (importedRequestModels != null) {
|
||||
for (var model in importedRequestModels) {
|
||||
ref
|
||||
.read(collectionStateNotifierProvider.notifier)
|
||||
.addRequestModel(importedRequestModel);
|
||||
.addRequestModel(model);
|
||||
}
|
||||
|
||||
// Solves - Do not use BuildContexts across async gaps
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'curl/curl.dart';
|
||||
|
||||
class Importer {
|
||||
Future<HttpRequestModel?> getHttpRequestModel(
|
||||
Future<List<HttpRequestModel>?> getHttpRequestModel(
|
||||
ImportFormat fileType,
|
||||
String content,
|
||||
) async {
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:apidash_core/apidash_core.dart';
|
||||
import 'package:curl_parser/curl_parser.dart';
|
||||
import '../consts.dart';
|
||||
import '../models/models.dart';
|
||||
import '../utils/utils.dart';
|
||||
|
||||
class CurlFileImport {
|
||||
HttpRequestModel? getHttpRequestModel(String content) {
|
||||
List<HttpRequestModel>? getHttpRequestModel(String content) {
|
||||
content = content.trim();
|
||||
try {
|
||||
final curl = Curl.parse(content);
|
||||
@@ -19,14 +21,17 @@ class CurlFileImport {
|
||||
? ContentType.formdata
|
||||
: (getContentTypeFromHeadersMap(curl.headers) ?? ContentType.text);
|
||||
|
||||
return HttpRequestModel(
|
||||
return [
|
||||
HttpRequestModel(
|
||||
method: method,
|
||||
url: url,
|
||||
headers: headers,
|
||||
params: params,
|
||||
body: body,
|
||||
bodyContentType: contentType,
|
||||
formData: formData);
|
||||
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