Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blossom #94

Merged
merged 31 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b91cee3
basic blossom without auth
leo-lox Jan 10, 2025
35ad939
wip: auth in blossom repo impl
leo-lox Jan 11, 2025
6489d84
wip: server urls as param
leo-lox Jan 11, 2025
d6b43ec
wip: serverUrls as optional arg
leo-lox Jan 11, 2025
cec6252
basic blossom tests
leo-lox Jan 11, 2025
a09f1cb
test with dead and unavailable data
leo-lox Jan 11, 2025
d20c9bd
basic getUserServerList
leo-lox Jan 11, 2025
1b52fd3
stream impl
leo-lox Jan 12, 2025
4e3d9ab
include content -range -length
leo-lox Jan 12, 2025
820ca02
files usecase
leo-lox Jan 12, 2025
1f3eafa
signer optional
leo-lox Jan 12, 2025
a510cac
expose to outside world
leo-lox Jan 12, 2025
4dc8d54
fix imports
leo-lox Jan 12, 2025
1489c6e
config description
leo-lox Jan 12, 2025
69c1d51
strategy tests
leo-lox Jan 12, 2025
1aacca1
fix: mirror uploads
leo-lox Jan 12, 2025
56ef911
upload all test
leo-lox Jan 12, 2025
042f310
comments
leo-lox Jan 12, 2025
967945c
wip: stream tests
leo-lox Jan 12, 2025
8e9a938
better exception msg
leo-lox Jan 12, 2025
76b64c1
move regex outside
leo-lox Jan 12, 2025
ba2bcc7
use ndk for blossom in test
leo-lox Jan 12, 2025
ce34919
remove non git files
leo-lox Jan 12, 2025
ddb7245
fix double assigned ports
leo-lox Jan 12, 2025
4f1b38b
update gitignore
leo-lox Jan 13, 2025
a581d6b
files test
leo-lox Jan 20, 2025
b037488
files, blossom show tests
leo-lox Jan 20, 2025
cb81927
files non blossom test
leo-lox Jan 20, 2025
3e23622
better file names
leo-lox Jan 20, 2025
e40542a
ci ports
leo-lox Jan 20, 2025
6fdc9c6
fix file test
leo-lox Jan 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ migrate_working_dir/
build/
/coverage/*
/lcov_badge_generator
/.flutter-plugins
/.flutter-plugins-dependencies
.flutter-plugins
.flutter-plugins-dependencies
/packages/ndk/coverage/*
/packages/ndk/coverage.lcov
2 changes: 1 addition & 1 deletion packages/amber/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ packages:
path: "../ndk"
relative: true
source: path
version: "0.2.0"
version: "0.2.4"
package_config:
dependency: transitive
description:
Expand Down
2 changes: 1 addition & 1 deletion packages/isar/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ packages:
path: "../ndk"
relative: true
source: path
version: "0.2.0"
version: "0.2.4"
node_preamble:
dependency: transitive
description:
Expand Down
22 changes: 22 additions & 0 deletions packages/ndk/example/files/blossom_example_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// ignore_for_file: avoid_print

import 'package:ndk/ndk.dart';
import 'package:test/test.dart';

void main() async {
test('download test', () async {
final ndk = Ndk.defaultConfig();

final downloadResult = await ndk.blossom.getBlob(
sha256:
"b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
serverUrls: ["https://cdn.hzrd149.com"],
);

print(
"file of type: ${downloadResult.mimeType}, size: ${downloadResult.data.length}",
);

expect(downloadResult.data.length, greaterThan(0));
});
}
31 changes: 31 additions & 0 deletions packages/ndk/example/files/files_example_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// ignore_for_file: avoid_print

import 'package:ndk/ndk.dart';
import 'package:test/test.dart';

void main() async {
test('download test - blossom', () async {
final ndk = Ndk.defaultConfig();

final downloadResult = await ndk.files.download(
url:
"https://cdn.hzrd149.com/b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553.pdf");

print(
"file of type: ${downloadResult.mimeType}, size: ${downloadResult.data.length}");

expect(downloadResult.data.length, greaterThan(0));
});

test('download test - non blossom', () async {
final ndk = Ndk.defaultConfig();

final downloadResult = await ndk.files
.download(url: "https://camelus.app/.well-known/nostr.json");

print(
"file of type: ${downloadResult.mimeType}, size: ${downloadResult.data.length}");

expect(downloadResult.data.length, greaterThan(0));
});
}
4 changes: 4 additions & 0 deletions packages/ndk/lib/config/blossom_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// ignore_for_file: constant_identifier_names

/// how long nostr auth messages are valid for
const Duration BLOSSOM_AUTH_EXPIRATION = Duration(minutes: 5);
90 changes: 90 additions & 0 deletions packages/ndk/lib/data_layer/data_sources/http_request.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:http/http.dart' as http;

Expand All @@ -21,4 +22,93 @@
}
return jsonDecode(response.body);
}

Future<http.Response> put({
required Uri url,
required Uint8List body,
required headers,
}) async {
http.Response response = await _client.put(
url,
body: body,
headers: headers,
);

if (response.statusCode != 200) {
throw Exception(
"error fetching STATUS: ${response.statusCode}, Link: $url");

Check warning on line 39 in packages/ndk/lib/data_layer/data_sources/http_request.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/data_layer/data_sources/http_request.dart#L38-L39

Added lines #L38 - L39 were not covered by tests
}

return response;
}

Future<http.Response> post({
required Uri url,
required Uint8List body,
required headers,
}) async {
http.Response response = await _client.post(
url,
body: body,
headers: headers,
);

if (response.statusCode != 200) {
throw Exception(
"error fetching STATUS: ${response.statusCode}, Link: $url");

Check warning on line 58 in packages/ndk/lib/data_layer/data_sources/http_request.dart

View check run for this annotation

Codecov / codecov/patch

packages/ndk/lib/data_layer/data_sources/http_request.dart#L57-L58

Added lines #L57 - L58 were not covered by tests
}

return response;
}

Future<http.Response> head({
required Uri url,
headers,
}) async {
http.Response response = await _client.head(
url,
headers: headers,
);

if (response.statusCode != 200) {
throw Exception(
"error fetching STATUS: ${response.statusCode}, Link: $url");
}

return response;
}

Future<http.Response> get({
required Uri url,
headers,
}) async {
http.Response response = await _client.get(
url,
headers: headers,
);

if (response.statusCode != 200) {
throw Exception(
"error fetching STATUS: ${response.statusCode}, Link: $url");
}

return response;
}

Future<http.Response> delete({
required Uri url,
required headers,
}) async {
http.Response response = await _client.delete(
url,
headers: headers,
);

if (response.statusCode != 200) {
throw Exception(
"error fetching STATUS: ${response.statusCode}, Link: $url");
}

return response;
}
}
Loading
Loading