Pobieranie i wysyłanie zdjęć i GPS

This commit is contained in:
2025-05-23 19:36:51 +02:00
parent 0ee2b8d702
commit f22de8150d
6 changed files with 254 additions and 179 deletions

View File

@@ -1,6 +1,6 @@
import axios from "axios";
const API_URL = "https://hopp.zikor.pl";
const API_URL = "http://192.168.0.118:9000";
export async function listLocations() {
try {
@@ -9,7 +9,6 @@ export async function listLocations() {
return "No locations found";
}
// Нормализуем изображения в полученных данных
return response.data.map(location => ({
...location,
imageSource: normalizeImageSource(location.image)
@@ -23,23 +22,18 @@ export async function listLocations() {
const normalizeImageSource = (image) => {
if (!image) return null;
// Проверка, является ли изображение URL
if (typeof image === 'string') {
// Если строка начинается с http или https, это URL
if (image.startsWith('http://') || image.startsWith('https://')) {
return { uri: image };
}
// Проверка на base64
if (image.startsWith('data:image')) {
return { uri: image };
} else if (image.length > 100) {
// Предполагаем, что это base64 без префикса
return { uri: `data:image/jpeg;base64,${image}` };
}
}
// Возвращаем null для неправильного формата
return null;
}
@@ -47,7 +41,8 @@ export async function getLocation(id) {
try {
const location = await axios.get(`${API_URL}/locations/${id}`);
if (!location) {
throw new Error("Location not found");
console.error("Could not find location");
return("Location not found");
}
return [...location.data, {image: normalizeImageSource(location.image)}];
@@ -65,7 +60,8 @@ export async function addLocation(location) {
},
});
if (!response) {
throw new Error("Failed to add location");
console.log("Error adding location");
return("Failed to add location");
}
return response.data;
} catch (error) {
@@ -80,7 +76,8 @@ export async function updateLocation(id, location) {
headers: { "Content-Type": "application/json" },
});
if (!response) {
throw new Error("Failed to add location");
console.log("Failed to update location");
return("Failed to update location");
}
return response.data;
} catch (error) {
@@ -93,7 +90,8 @@ export async function deleteLocation(id) {
try {
const response = await axios.delete(`${API_URL}/locations/${id}`);
if (!response) {
throw new Error("Failed to delete location");
console.log("Error deleting location");
return("Failed to delete location");
}
return response.data;
} catch (error) {