mirror of
https://github.com/inventree/inventree-app.git
synced 2026-02-06 12:55:50 +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:
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,
|
||||
|
||||
Reference in New Issue
Block a user