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:
@@ -28,11 +28,14 @@ void importToCollectionPane(
|
|||||||
(content) {
|
(content) {
|
||||||
kImporter
|
kImporter
|
||||||
.getHttpRequestModel(importFormatType, content)
|
.getHttpRequestModel(importFormatType, content)
|
||||||
.then((importedRequestModel) {
|
.then((importedRequestModels) {
|
||||||
if (importedRequestModel != null) {
|
if (importedRequestModels != null) {
|
||||||
|
for (var model in importedRequestModels) {
|
||||||
ref
|
ref
|
||||||
.read(collectionStateNotifierProvider.notifier)
|
.read(collectionStateNotifierProvider.notifier)
|
||||||
.addRequestModel(importedRequestModel);
|
.addRequestModel(model);
|
||||||
|
}
|
||||||
|
|
||||||
// Solves - Do not use BuildContexts across async gaps
|
// Solves - Do not use BuildContexts across async gaps
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
import 'package:apidash_core/apidash_core.dart';
|
import 'package:apidash_core/apidash_core.dart';
|
||||||
import 'curl/curl.dart';
|
|
||||||
|
|
||||||
class Importer {
|
class Importer {
|
||||||
Future<HttpRequestModel?> getHttpRequestModel(
|
Future<List<HttpRequestModel>?> getHttpRequestModel(
|
||||||
ImportFormat fileType,
|
ImportFormat fileType,
|
||||||
String content,
|
String content,
|
||||||
) async {
|
) async {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export 'extensions/extensions.dart';
|
|||||||
export 'models/models.dart';
|
export 'models/models.dart';
|
||||||
export 'utils/utils.dart';
|
export 'utils/utils.dart';
|
||||||
export 'services/services.dart';
|
export 'services/services.dart';
|
||||||
|
export 'parsers/parsers.dart';
|
||||||
|
|
||||||
// Export 3rd party packages
|
// Export 3rd party packages
|
||||||
export 'package:collection/collection.dart';
|
export 'package:collection/collection.dart';
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import 'package:apidash_core/apidash_core.dart';
|
|
||||||
import 'package:curl_parser/curl_parser.dart';
|
import 'package:curl_parser/curl_parser.dart';
|
||||||
|
import '../consts.dart';
|
||||||
|
import '../models/models.dart';
|
||||||
|
import '../utils/utils.dart';
|
||||||
|
|
||||||
class CurlFileImport {
|
class CurlFileImport {
|
||||||
HttpRequestModel? getHttpRequestModel(String content) {
|
List<HttpRequestModel>? getHttpRequestModel(String content) {
|
||||||
content = content.trim();
|
content = content.trim();
|
||||||
try {
|
try {
|
||||||
final curl = Curl.parse(content);
|
final curl = Curl.parse(content);
|
||||||
@@ -19,14 +21,17 @@ class CurlFileImport {
|
|||||||
? ContentType.formdata
|
? ContentType.formdata
|
||||||
: (getContentTypeFromHeadersMap(curl.headers) ?? ContentType.text);
|
: (getContentTypeFromHeadersMap(curl.headers) ?? ContentType.text);
|
||||||
|
|
||||||
return HttpRequestModel(
|
return [
|
||||||
|
HttpRequestModel(
|
||||||
method: method,
|
method: method,
|
||||||
url: url,
|
url: url,
|
||||||
headers: headers,
|
headers: headers,
|
||||||
params: params,
|
params: params,
|
||||||
body: body,
|
body: body,
|
||||||
bodyContentType: contentType,
|
bodyContentType: contentType,
|
||||||
formData: formData);
|
formData: formData,
|
||||||
|
),
|
||||||
|
];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
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:
|
flutter:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
collection: ^1.18.0
|
collection: ^1.18.0
|
||||||
|
curl_parser:
|
||||||
|
path: ../curl_parser
|
||||||
freezed_annotation: ^2.4.1
|
freezed_annotation: ^2.4.1
|
||||||
http: ^1.2.1
|
http: ^1.2.1
|
||||||
http_parser: ^4.0.2
|
http_parser: ^4.0.2
|
||||||
@@ -25,40 +27,3 @@ dev_dependencies:
|
|||||||
flutter_lints: ^4.0.0
|
flutter_lints: ^4.0.0
|
||||||
freezed: ^2.5.7
|
freezed: ^2.5.7
|
||||||
test: ^1.25.2
|
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:
|
dependency_overrides:
|
||||||
|
curl_parser:
|
||||||
|
path: ../curl_parser
|
||||||
seed:
|
seed:
|
||||||
path: ../seed
|
path: ../seed
|
||||||
|
|||||||
Reference in New Issue
Block a user