Now actually use Thumbnail that was loaded from db, instead of re downloading it every time. Also save Thumbnail to Manga if it couldnt be saved before

This commit is contained in:
Pablu23
2024-03-01 16:46:19 +01:00
parent b7f2a389cd
commit ad1fcbc68a
3 changed files with 32 additions and 10 deletions

View File

@@ -157,16 +157,21 @@ func (s *Server) LoadCurr() {
fmt.Println("Loaded current")
}
func (s *Server) LoadThumbnail(mangaId int) (path string, err error) {
strId := strconv.Itoa(mangaId)
func (s *Server) LoadThumbnail(manga *database.Manga) (path string, err error) {
strId := strconv.Itoa(manga.Id)
//s.Mutex.Lock()
//defer s.Mutex.Unlock()
s.Mutex.Lock()
defer s.Mutex.Unlock()
if s.ImageBuffers[strId] != nil {
return strId, nil
}
url, err := s.Provider.GetThumbnail(strconv.Itoa(mangaId))
if manga.Thumbnail != nil {
s.ImageBuffers[strId] = manga.Thumbnail
return strId, nil
}
url, err := s.Provider.GetThumbnail(strId)
if err != nil {
return "", err
}
@@ -174,6 +179,7 @@ func (s *Server) LoadThumbnail(mangaId int) (path string, err error) {
if err != nil {
return "", err
}
manga.Thumbnail = ram
s.ImageBuffers[strId] = ram
return strId, nil
}