app: only query meshtastic provider (#664)

* app: only query meshtastic provider

* app: address review comments
This commit is contained in:
l5y
2026-03-30 19:04:34 +02:00
committed by GitHub
parent d6a2e263cc
commit e03675168b
4 changed files with 30 additions and 5 deletions
+5 -1
View File
@@ -2944,6 +2944,9 @@ class MeshNode {
}
}
/// The protocol identifier sent to the API to filter results to Meshtastic only.
const String _kProtocolFilter = 'meshtastic';
/// Build a messages API URI for a given domain or absolute URL.
Uri _buildMessagesUri(String domain, {int since = 0, int limit = 1000}) {
final trimmed = domain.trim();
@@ -2951,6 +2954,7 @@ Uri _buildMessagesUri(String domain, {int since = 0, int limit = 1000}) {
'limit': limit.toString(),
'encrypted': 'false',
'since': since.toString(),
'protocol': _kProtocolFilter,
};
if (trimmed.isEmpty) {
return Uri.https('potatomesh.net', '/api/messages', params);
@@ -2988,7 +2992,7 @@ Uri _buildNodeUri(String domain, String nodeId) {
/// Build the bulk nodes API URI for fetching recent nodes.
Uri _buildNodesUri(String domain, {int limit = 1000}) {
final trimmedDomain = domain.trim();
final params = {'limit': limit.toString()};
final params = {'limit': limit.toString(), 'protocol': _kProtocolFilter};
if (trimmedDomain.isEmpty) {
return Uri.https('potatomesh.net', '/api/nodes', params);
+2
View File
@@ -206,8 +206,10 @@ void main() {
expect(calls[0].host, 'mesh.example.org');
expect(calls[0].path, '/api/messages');
expect(calls[0].queryParameters['protocol'], 'meshtastic');
expect(calls[1].scheme, 'https');
expect(calls[1].path, '/api/messages');
expect(calls[1].queryParameters['protocol'], 'meshtastic');
});
});
+1
View File
@@ -145,6 +145,7 @@ void main() {
if (request.url.path == '/api/messages') {
sinces.add(request.url.queryParameters['since'] ?? '');
expect(request.url.queryParameters['limit'], '1000');
expect(request.url.queryParameters['protocol'], 'meshtastic');
if (sinces.length == 1) {
return http.Response(
jsonEncode([
+22 -4
View File
@@ -19,6 +19,11 @@ use tokio::sync::RwLock;
use crate::config::PotatomeshConfig;
/// Protocol identifier sent as a query parameter to restrict API results to
/// Meshtastic data only. Other protocols (e.g. MeshCore) are excluded until
/// the clients are updated to support them.
const PROTOCOL_FILTER: &str = "meshtastic";
#[allow(dead_code)]
#[derive(Debug, Deserialize, Clone)]
pub struct PotatoMessage {
@@ -131,7 +136,10 @@ impl PotatoClient {
}
pub async fn fetch_messages(&self, params: FetchParams) -> anyhow::Result<Vec<PotatoMessage>> {
let mut req = self.http.get(self.messages_url());
let mut req = self
.http
.get(self.messages_url())
.query(&[("protocol", PROTOCOL_FILTER)]);
if let Some(limit) = params.limit {
req = req.query(&[("limit", limit)]);
}
@@ -336,7 +344,10 @@ mod tests {
let mut server = mockito::Server::new_async().await;
let mock = server
.mock("GET", "/api/messages")
.match_query(mockito::Matcher::Any) // allow optional query params
.match_query(mockito::Matcher::UrlEncoded(
"protocol".into(),
"meshtastic".into(),
))
.with_status(200)
.with_header("content-type", "application/json")
.with_body(
@@ -427,7 +438,10 @@ mod tests {
let mut server = mockito::Server::new_async().await;
let mock = server
.mock("GET", "/api/messages")
.match_query(mockito::Matcher::Any)
.match_query(mockito::Matcher::UrlEncoded(
"protocol".into(),
PROTOCOL_FILTER.into(),
))
.with_status(500)
.create();
@@ -448,7 +462,11 @@ mod tests {
let mut server = mockito::Server::new_async().await;
let mock = server
.mock("GET", "/api/messages")
.match_query("limit=10&since=123")
.match_query(mockito::Matcher::AllOf(vec![
mockito::Matcher::UrlEncoded("protocol".into(), PROTOCOL_FILTER.into()),
mockito::Matcher::UrlEncoded("limit".into(), "10".into()),
mockito::Matcher::UrlEncoded("since".into(), "123".into()),
]))
.with_status(200)
.with_header("content-type", "application/json")
.with_body("[]")