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" const baseUrl = "http://localhost:8080"
export function getImagePathOrDefault(path) { export function getImagePathOrDefault(path) {
return (path == "" || typeof path === 'undefined') ? if (path == "" || typeof path === 'undefined') {
"../defaultbook.png" : baseUrl + path; return "../defaultbook.png";
} else if (path.startsWith("https://")) {
return path;
} else {
return baseUrl + path;
}
} }
function useFetch(data, error, url) { function useFetch(data, error, url) {

View File

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

View File

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