@@ -2,10 +2,9 @@ package backend
2
2
3
3
import (
4
4
"fmt"
5
+ "log/slog"
5
6
"strings"
6
7
7
- "github.com/sirupsen/logrus"
8
-
9
8
"github.com/pgaskin/koboutils/v2/kobo"
10
9
)
11
10
@@ -155,14 +154,20 @@ func (Bookmark) TableName() string {
155
154
return "Bookmark"
156
155
}
157
156
158
- func GetKoboMetadata (detectedPaths []string ) []Kobo {
157
+ func GetKoboMetadata (detectedPaths []string , logger * slog. Logger ) []Kobo {
159
158
var kobos []Kobo
160
159
for _ , path := range detectedPaths {
161
160
_ , _ , deviceId , err := kobo .ParseKoboVersion (path )
162
161
if err != nil {
163
- logrus .WithField ("kobo_path" , path ).WithError (err ).Error ("Failed to parse Kobo version" )
162
+ logger .Error ("Failed to parse Kobo version" ,
163
+ slog .String ("error" , err .Error ()),
164
+ slog .String ("kobo_path" , path ),
165
+ )
164
166
}
165
- logrus .WithField ("device_id" , deviceId ).Info ("Found an attached device" )
167
+ logger .Info ("Found attached device" ,
168
+ slog .String ("device_id" , deviceId ),
169
+ slog .String ("kobo_path" , path ),
170
+ )
166
171
device , found := kobo .DeviceByID (deviceId )
167
172
if found {
168
173
kobos = append (kobos , Kobo {
@@ -187,7 +192,9 @@ func GetKoboMetadata(detectedPaths []string) []Kobo {
187
192
})
188
193
continue
189
194
}
190
- logrus .WithField ("device_id" , deviceId ).Warn ("Found a device that isn't officially supported but will likely still operate just fine" )
195
+ logger .Warn ("Found a device that isn't officially supported but will likely still operate just fine" ,
196
+ slog .String ("device_id" , deviceId ),
197
+ )
191
198
// We can handle unsupported Kobos in future but at present, there are none
192
199
kobos = append (kobos , Kobo {
193
200
MntPath : path ,
@@ -197,55 +204,67 @@ func GetKoboMetadata(detectedPaths []string) []Kobo {
197
204
return kobos
198
205
}
199
206
200
- func (k * Kobo ) ListDeviceContent (includeStoreBought bool ) ([]Content , error ) {
207
+ func (k * Kobo ) ListDeviceContent (includeStoreBought bool , logger * slog. Logger ) ([]Content , error ) {
201
208
var content []Content
202
- logrus .Debug ("Retrieving content list from device" )
209
+ logger .Debug ("Retrieving content list from device" )
203
210
result := Conn .Where (& Content {ContentType : "6" , VolumeIndex : - 1 })
204
211
if ! includeStoreBought {
205
212
result = result .Where ("ContentID LIKE '%file:///%'" )
206
213
}
207
214
result = result .Order ("___PercentRead desc, title asc" ).Find (& content )
208
215
if result .Error != nil {
209
- logrus .WithError (result .Error ).Error ("Failed to retrieve content from device" )
216
+ logger .Error ("Failed to retrieve content from device" ,
217
+ slog .String ("error" , result .Error .Error ()),
218
+ )
210
219
return nil , result .Error
211
220
}
212
- logrus .WithField ("content_count" , len (content )).Debug ("Successfully retrieved device content" )
221
+ logger .Debug ("Successfully retrieved device content" ,
222
+ slog .Int ("content_count" , len (content )),
223
+ )
213
224
return content , nil
214
225
}
215
226
216
- func (k * Kobo ) ListDeviceBookmarks (includeStoreBought bool ) ([]Bookmark , error ) {
227
+ func (k * Kobo ) ListDeviceBookmarks (includeStoreBought bool , logger * slog. Logger ) ([]Bookmark , error ) {
217
228
var bookmarks []Bookmark
218
- logrus .Debug ("Retrieving bookmarks from device" )
229
+ logger .Debug ("Retrieving bookmarks from device" )
219
230
result := Conn
220
231
if ! includeStoreBought {
221
232
result = result .Where ("VolumeID LIKE '%file:///%'" )
222
233
}
223
234
result = result .Order ("VolumeID ASC, ChapterProgress ASC" ).Find (& bookmarks ).Limit (1 )
224
235
if result .Error != nil {
225
- logrus .WithError (result .Error ).Error ("Failed to retrieve bookmarks from device" )
236
+ logger .Error ("Failed to retrieve bookmarks from device" ,
237
+ slog .String ("error" , result .Error .Error ()),
238
+ )
226
239
return nil , result .Error
227
240
}
228
- logrus .WithField ("bookmark_count" , len (bookmarks )).Debug ("Successfully retrieved device bookmarks" )
241
+ logger .Debug ("Successfully retrieved device bookmarks" ,
242
+ slog .Int ("bookmark_count" , len (bookmarks )),
243
+ )
229
244
return bookmarks , nil
230
245
}
231
246
232
- func (k * Kobo ) BuildContentIndex (content []Content ) map [string ]Content {
233
- logrus .Debug ("Building an index out of device content" )
247
+ func (k * Kobo ) BuildContentIndex (content []Content , logger * slog. Logger ) map [string ]Content {
248
+ logger .Debug ("Building an index out of device content" )
234
249
contentIndex := make (map [string ]Content )
235
250
for _ , item := range content {
236
251
contentIndex [item .ContentID ] = item
237
252
}
238
- logrus .WithField ("index_count" , len (contentIndex )).Debug ("Built content index" )
253
+ logger .Debug ("Built content index" ,
254
+ slog .Int ("index_count" , len (contentIndex )),
255
+ )
239
256
return contentIndex
240
257
}
241
258
242
- func (k * Kobo ) CountDeviceBookmarks () HighlightCounts {
259
+ func (k * Kobo ) CountDeviceBookmarks (logger * slog. Logger ) HighlightCounts {
243
260
var totalCount int64
244
261
var officialCount int64
245
262
var sideloadedCount int64
246
263
result := Conn .Model (& Bookmark {}).Count (& totalCount )
247
264
if result .Error != nil {
248
- logrus .WithError (result .Error ).Error ("Failed to count bookmarks on device" )
265
+ logger .Error ("Failed to count bookmarks on device" ,
266
+ slog .String ("error" , result .Error .Error ()),
267
+ )
249
268
}
250
269
Conn .Model (& Bookmark {}).Where ("VolumeID LIKE '%file:///%'" ).Count (& sideloadedCount )
251
270
Conn .Model (& Bookmark {}).Where ("VolumeID NOT LIKE '%file:///%'" ).Count (& officialCount )
0 commit comments