mirror of
https://github.com/inventree/inventree-app.git
synced 2026-02-06 04:45:43 +00:00
Image url fix (#765)
* Bump release notes * Improve URL resolution * Add URL tests * Add debug for CI * Fix stock adjustment URLs * Fix barcode URLs
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
## 0.22.1 - February 2026
|
||||
---
|
||||
|
||||
- Fixes bug related to fetching images from remote URLs
|
||||
|
||||
### 0.22.0 - February 2026
|
||||
---
|
||||
|
||||
|
||||
35
lib/api.dart
35
lib/api.dart
@@ -213,30 +213,27 @@ class InvenTreeAPI {
|
||||
return url;
|
||||
}
|
||||
|
||||
String _makeUrl(String url) {
|
||||
// Strip leading slash
|
||||
if (url.startsWith("/")) {
|
||||
url = url.substring(1, url.length);
|
||||
// Resolve a relative or absolute URL
|
||||
String _makeUrl(String url, {String base = ""}) {
|
||||
final baseUri = Uri.parse(base.isNotEmpty ? base : baseUrl);
|
||||
final pathUri = Uri.parse(url);
|
||||
|
||||
// If path is absolute (has scheme), ignore base
|
||||
if (pathUri.hasScheme) {
|
||||
return pathUri.toString();
|
||||
}
|
||||
|
||||
// Prevent double-slash
|
||||
url = url.replaceAll("//", "/");
|
||||
|
||||
return baseUrl + url;
|
||||
return baseUri.resolveUri(pathUri).toString();
|
||||
}
|
||||
|
||||
String get apiUrl => _makeUrl("/api/");
|
||||
|
||||
String get imageUrl => _makeUrl("/image/");
|
||||
|
||||
String makeApiUrl(String endpoint) {
|
||||
if (endpoint.startsWith("/api/") || endpoint.startsWith("api/")) {
|
||||
return _makeUrl(endpoint);
|
||||
} else {
|
||||
return _makeUrl("/api/${endpoint}");
|
||||
}
|
||||
String apiBase = makeUrl("/api/");
|
||||
|
||||
return _makeUrl(endpoint, base: apiBase);
|
||||
}
|
||||
|
||||
String get apiUrl => makeApiUrl("");
|
||||
|
||||
String makeUrl(String endpoint) => _makeUrl(endpoint);
|
||||
|
||||
UserProfile? profile;
|
||||
@@ -1143,7 +1140,7 @@ class InvenTreeAPI {
|
||||
* Perform a request to link a custom barcode to a particular item
|
||||
*/
|
||||
Future<bool> linkBarcode(Map<String, String> body) async {
|
||||
HttpClientRequest? request = await apiRequest("/barcode/link/", "POST");
|
||||
HttpClientRequest? request = await apiRequest("barcode/link/", "POST");
|
||||
|
||||
if (request == null) {
|
||||
return false;
|
||||
@@ -1162,7 +1159,7 @@ class InvenTreeAPI {
|
||||
* Perform a request to unlink a custom barcode from a particular item
|
||||
*/
|
||||
Future<bool> unlinkBarcode(Map<String, dynamic> body) async {
|
||||
HttpClientRequest? request = await apiRequest("/barcode/unlink/", "POST");
|
||||
HttpClientRequest? request = await apiRequest("barcode/unlink/", "POST");
|
||||
|
||||
if (request == null) {
|
||||
return false;
|
||||
|
||||
@@ -534,19 +534,19 @@ class InvenTreeStockItem extends InvenTreeModel {
|
||||
}
|
||||
|
||||
Future<bool> countStock(double q, {String? notes}) async {
|
||||
final bool result = await adjustStock("/stock/count/", q, notes: notes);
|
||||
final bool result = await adjustStock("stock/count/", q, notes: notes);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<bool> addStock(double q, {String? notes}) async {
|
||||
final bool result = await adjustStock("/stock/add/", q, notes: notes);
|
||||
final bool result = await adjustStock("stock/add/", q, notes: notes);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<bool> removeStock(double q, {String? notes}) async {
|
||||
final bool result = await adjustStock("/stock/remove/", q, notes: notes);
|
||||
final bool result = await adjustStock("stock/remove/", q, notes: notes);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -563,7 +563,7 @@ class InvenTreeStockItem extends InvenTreeModel {
|
||||
}
|
||||
|
||||
final bool result = await adjustStock(
|
||||
"/stock/transfer/",
|
||||
"stock/transfer/",
|
||||
q,
|
||||
notes: notes,
|
||||
location: location,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: inventree
|
||||
description: InvenTree stock management
|
||||
|
||||
version: 0.22.0+109
|
||||
version: 0.22.1+110
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
|
||||
@@ -23,6 +23,27 @@ void main() {
|
||||
assert(await UserProfileDBManager().selectProfileByName(testServerName));
|
||||
});
|
||||
|
||||
// Ensure that generated URLs are correct
|
||||
group("URL Tests:", () {
|
||||
test("Generate URLs", () async {
|
||||
UserProfile profile = await setupServerProfile();
|
||||
var api = InvenTreeAPI();
|
||||
|
||||
api.profile = profile;
|
||||
|
||||
Map<String, String> tests = {
|
||||
"": "http://localhost:8000/api/",
|
||||
"barcode/": "http://localhost:8000/api/barcode/",
|
||||
"https://remote-server.com/media/image.png":
|
||||
"https://remote-server.com/media/image.png",
|
||||
};
|
||||
|
||||
for (var test in tests.entries) {
|
||||
expect(api.makeApiUrl(test.key), equals(test.value));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
group("Login Tests:", () {
|
||||
test("Disconnected", () async {
|
||||
// Test that calling disconnect() does the right thing
|
||||
|
||||
Reference in New Issue
Block a user