Inventaire API: display search image

This commit is contained in:
2026-01-17 16:15:34 +01:00
parent a04aff6056
commit 8d3569e5d6
4 changed files with 25 additions and 10 deletions

View File

@@ -3,8 +3,13 @@ import { useAuthStore } from './auth.store.js'
const baseUrl = "http://localhost:8080"
export function getImagePathOrDefault(path) {
return (path == "" || typeof path === 'undefined') ?
"../defaultbook.png" : baseUrl + path;
if (path == "" || typeof path === 'undefined') {
return "../defaultbook.png";
} else if (path.startsWith("https://")) {
return path;
} else {
return baseUrl + path;
}
}
function useFetch(data, error, url) {

View File

@@ -15,16 +15,21 @@ type InventaireSearchBook struct {
ID string `json:"id"`
Label string `json:"label"`
Description string `json:"description"`
Image string `json:"image"`
}
func computeInventaireUrl(paths ...string) (*url.URL, error) {
baseUrl := "https://inventaire.io/api"
func GetBaseInventaireUrl() string {
return "https://inventaire.io"
}
func computeInventaireApiUrl(paths ...string) (*url.URL, error) {
baseUrl := GetBaseInventaireUrl() + "/api"
return callapiutils.ComputeUrl(baseUrl, paths...)
}
func CallInventaireSearch(searchterm string, limit int, offset int) (InventaireSearchResult, error) {
var queryResult InventaireSearchResult
u, err := computeInventaireUrl("search")
u, err := computeInventaireApiUrl("search")
if err != nil {
return queryResult, err
}

View File

@@ -88,7 +88,7 @@ func findLangageField(multipleMessageFields map[string]json.RawMessage, lang str
func CallInventaireBook(inventaireId string, lang string) (InventaireBookResult, error) {
queryResult := InventaireBookResult{ID: inventaireId, Lang: lang}
u, err := computeInventaireUrl("entities")
u, err := computeInventaireApiUrl("entities")
if err != nil {
return queryResult, err
}

View File

@@ -2,6 +2,7 @@ package routes
import (
"net/http"
"strings"
"git.artlef.fr/PersonalLibraryManager/internal/appcontext"
"git.artlef.fr/PersonalLibraryManager/internal/inventaire"
@@ -44,14 +45,18 @@ func GetSearchBooksHandler(ac appcontext.AppContext) {
myvalidator.ReturnErrorsAsJsonResponse(&ac, err)
return
}
returnedBooks = OpenLibraryBooksToBookSearchGet(queryResult.Results)
returnedBooks = InventaireBooksToBookSearchGet(queryResult.Results)
}
ac.C.JSON(http.StatusOK, returnedBooks)
}
func OpenLibraryBooksToBookSearchGet(OLbooks []inventaire.InventaireSearchBook) []query.BookSearchGet {
func InventaireBooksToBookSearchGet(inventairebooks []inventaire.InventaireSearchBook) []query.BookSearchGet {
var books []query.BookSearchGet
for _, b := range OLbooks {
for _, b := range inventairebooks {
coverPath := ""
if b.Image != "" && strings.HasPrefix(b.Image, "/") {
coverPath = inventaire.GetBaseInventaireUrl() + b.Image
}
bookSearchGet := query.BookSearchGet{
ID: 0,
Title: b.Label,
@@ -60,7 +65,7 @@ func OpenLibraryBooksToBookSearchGet(OLbooks []inventaire.InventaireSearchBook)
Rating: 0,
Read: false,
WantRead: false,
CoverPath: "",
CoverPath: coverPath,
}
books = append(books, bookSearchGet)
}