Pobieranie zdjęć z backendu
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
const API_URL = "http://10.224.1.86:8080/api/v1/notices";
|
||||
import axios from "axios";
|
||||
|
||||
const API_URL = "https://testowe.zikor.pl/api/v1";
|
||||
|
||||
export async function listNotices() {
|
||||
const response = await fetch(`${API_URL}/get/all`);
|
||||
const response = await fetch(`${API_URL}/notices/get/all`);
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
throw new Error(response.toString());
|
||||
@@ -10,7 +12,7 @@ export async function listNotices() {
|
||||
}
|
||||
|
||||
export async function getNoticeById(noticeId) {
|
||||
const response = await fetch(`${API_URL}/get/${noticeId}`);
|
||||
const response = await fetch(`${API_URL}/notices/get/${noticeId}`);
|
||||
|
||||
const data = await response.json();
|
||||
if (!response.ok) {
|
||||
@@ -19,16 +21,20 @@ export async function getNoticeById(noticeId) {
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function getImagesByNoticeId(noticeId) {
|
||||
const response = await fetch(`http://10.224.1.86:8080/api/v1/images/list/${noticeId}`);
|
||||
export async function getImageByNoticeId(noticeId) {
|
||||
let imageUrl;
|
||||
try {
|
||||
const listResponse = await axios.get(`${API_URL}/images/list/${noticeId}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.toString());
|
||||
const imageName = listResponse.data[0];
|
||||
imageUrl = `${API_URL}/images/get/${imageName}`;
|
||||
|
||||
console.log(`Pobrano zdjęcie o nazwie: ${imageName}`);
|
||||
|
||||
return imageUrl;
|
||||
} catch (err) {
|
||||
console.log(`Zdjęcie nie istnieje dla notice o id: ${noticeId}`);
|
||||
imageUrl = "https://http.cat/404.jpg";
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
const Image = await fetch(`http://10.224.1.86:8080/api/v1/images/get/${data.first}`);
|
||||
|
||||
return Image.blob();
|
||||
}
|
||||
Reference in New Issue
Block a user