fix: replace invalid new(expression) calls with proper pointer allocation
Go's new() builtin takes a type and allocates a zero value — it cannot wrap an expression. All instances of new(someExpression) were compile errors. Replace each with a local variable assignment and address-of operator. Affected files: - handlers/koreader.go: progress field pointers (Chapter, Page, etc.) - handlers/kobo.go: pagesRemaining pointer - handlers/queue.go: uuidPtrToString and timestamptzPtrToString helpers - router/reader.go: bookmark pageNumber and chapterNumber pointers - services/media_scanner.go: validation error message pointers - services/worker.go: StartedAt and CompletedAt timestamps - sync/offline.go: GetDeviceStatus return pointer - tests/device_test.go: SyncEnabled and SyncFrequencyMinutes pointers
This commit is contained in:
@@ -147,10 +147,12 @@ func TestUpdateDevice(t *testing.T) {
|
|||||||
device := setup.CreateDevice(t, "Test Device", "koreader", "test-device-123")
|
device := setup.CreateDevice(t, "Test Device", "koreader", "test-device-123")
|
||||||
|
|
||||||
// Update device
|
// Update device
|
||||||
|
syncEnabled := false
|
||||||
|
syncFreq := int32(10)
|
||||||
updateRequest := handlers.DeviceUpdateRequest{
|
updateRequest := handlers.DeviceUpdateRequest{
|
||||||
DeviceName: "Updated Device Name",
|
DeviceName: "Updated Device Name",
|
||||||
SyncEnabled: new(false),
|
SyncEnabled: &syncEnabled,
|
||||||
SyncFrequencyMinutes: new(int32(10)),
|
SyncFrequencyMinutes: &syncFreq,
|
||||||
}
|
}
|
||||||
updateBody, _ := json.Marshal(updateRequest)
|
updateBody, _ := json.Marshal(updateRequest)
|
||||||
|
|
||||||
|
|||||||
@@ -303,7 +303,8 @@ func (h *KoboHandler) Initialization(c *echo.Context) error {
|
|||||||
lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
|
lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
|
||||||
}
|
}
|
||||||
if progress.TotalPages.Valid && progress.CurrentPage.Valid {
|
if progress.TotalPages.Valid && progress.CurrentPage.Valid {
|
||||||
pagesRemaining = new(int(progress.TotalPages.Int32 - progress.CurrentPage.Int32))
|
remaining := int(progress.TotalPages.Int32 - progress.CurrentPage.Int32)
|
||||||
|
pagesRemaining = &remaining
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -602,19 +602,24 @@ func (h *KOReaderHandler) GetMetadata(c *echo.Context) error {
|
|||||||
progressData.Epubcfi = &progress.Epubcfi.String
|
progressData.Epubcfi = &progress.Epubcfi.String
|
||||||
}
|
}
|
||||||
if progress.Chapter.Valid {
|
if progress.Chapter.Valid {
|
||||||
progressData.Chapter = new(int(progress.Chapter.Int32))
|
progress := int(progress.Chapter.Int32)
|
||||||
|
progressData.Chapter = &progress
|
||||||
}
|
}
|
||||||
if progress.ChapterProgress.Valid {
|
if progress.ChapterProgress.Valid {
|
||||||
progressData.ChapterProgress = new(progress.ChapterProgress.Float64)
|
progress := progress.ChapterProgress.Float64
|
||||||
|
progressData.ChapterProgress = &progress
|
||||||
}
|
}
|
||||||
if progress.CharacterOffset.Valid {
|
if progress.CharacterOffset.Valid {
|
||||||
progressData.Character = new(progress.CharacterOffset.Int64)
|
progress := progress.CharacterOffset.Int64
|
||||||
|
progressData.Character = &progress
|
||||||
}
|
}
|
||||||
if progress.CurrentPage.Valid {
|
if progress.CurrentPage.Valid {
|
||||||
progressData.Page = new(int(progress.CurrentPage.Int32))
|
progress := int(progress.CurrentPage.Int32)
|
||||||
|
progressData.Page = &progress
|
||||||
}
|
}
|
||||||
if progress.TotalPages.Valid {
|
if progress.TotalPages.Valid {
|
||||||
progressData.TotalPages = new(int(progress.TotalPages.Int32))
|
progress := int(progress.TotalPages.Int32)
|
||||||
|
progressData.TotalPages = &progress
|
||||||
}
|
}
|
||||||
|
|
||||||
annotations, err := h.db.GetAnnotationsForBook(c.Request().Context(), database.GetAnnotationsForBookParams{
|
annotations, err := h.db.GetAnnotationsForBook(c.Request().Context(), database.GetAnnotationsForBookParams{
|
||||||
@@ -694,7 +699,8 @@ func (h *KOReaderHandler) GetLibrary(c *echo.Context) error {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
percentRead = progress.Percentage.Float64
|
percentRead = progress.Percentage.Float64
|
||||||
if progress.TotalPages.Valid && progress.CurrentPage.Valid {
|
if progress.TotalPages.Valid && progress.CurrentPage.Valid {
|
||||||
pagesRemaining = new(int(progress.TotalPages.Int32 - progress.CurrentPage.Int32))
|
pages := int(progress.TotalPages.Int32 - progress.CurrentPage.Int32)
|
||||||
|
pagesRemaining = &pages
|
||||||
}
|
}
|
||||||
if progress.LastReadAt.Valid {
|
if progress.LastReadAt.Valid {
|
||||||
lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
|
lastModified = progress.LastReadAt.Time.Format(time.RFC3339)
|
||||||
|
|||||||
@@ -310,7 +310,8 @@ func uuidPtrToString(u pgtype.UUID) *string {
|
|||||||
if !u.Valid {
|
if !u.Valid {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return new(uuid.UUID(u.Bytes).String())
|
s := uuid.UUID(u.Bytes).String()
|
||||||
|
return &s
|
||||||
}
|
}
|
||||||
|
|
||||||
func textPtrToString(t pgtype.Text) *string {
|
func textPtrToString(t pgtype.Text) *string {
|
||||||
@@ -324,5 +325,6 @@ func timestamptzPtrToString(t pgtype.Timestamptz) *string {
|
|||||||
if !t.Valid {
|
if !t.Valid {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return new(t.Time.Format("2006-01-02T15:04:05Z07:00"))
|
timeFormat := t.Time.Format("2006-01-02T15:04:05Z07:00")
|
||||||
|
return &timeFormat
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1320,12 +1320,13 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
|
|||||||
// Must be fixed-layout or comic archive
|
// Must be fixed-layout or comic archive
|
||||||
if mediaItem.FormatGroup != "fixed_layout" &&
|
if mediaItem.FormatGroup != "fixed_layout" &&
|
||||||
mediaItem.FormatGroup != "comic_archive" {
|
mediaItem.FormatGroup != "comic_archive" {
|
||||||
return new(fmt.Sprintf(
|
str := fmt.Sprintf(
|
||||||
"EPUB file '%s' is reflowable (text-based), not fixed-layout (image-based). "+
|
"EPUB file '%s' is reflowable (text-based), not fixed-layout (image-based). "+
|
||||||
"Manga library only accepts fixed-layout EPUBs, CBZ, CBR, or image files. "+
|
"Manga library only accepts fixed-layout EPUBs, CBZ, CBR, or image files. "+
|
||||||
"Consider moving this file to an ebooks library.",
|
"Consider moving this file to an ebooks library.",
|
||||||
mediaItem.Title,
|
mediaItem.Title,
|
||||||
))
|
)
|
||||||
|
return &str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set manga-specific flags for fixed-layout EPUBs
|
// Set manga-specific flags for fixed-layout EPUBs
|
||||||
@@ -1350,11 +1351,12 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
|
|||||||
// Accept comic archives and fixed-layout
|
// Accept comic archives and fixed-layout
|
||||||
if mediaItem.FormatGroup != "comic_archive" &&
|
if mediaItem.FormatGroup != "comic_archive" &&
|
||||||
mediaItem.FormatGroup != "fixed_layout" {
|
mediaItem.FormatGroup != "fixed_layout" {
|
||||||
return new(fmt.Sprintf(
|
str := fmt.Sprintf(
|
||||||
"File '%s' is not a comic archive format. "+
|
"File '%s' is not a comic archive format. "+
|
||||||
"Comics library only accepts CBZ, CBR, CB7, CBT, PDF, or fixed-layout EPUBs.",
|
"Comics library only accepts CBZ, CBR, CB7, CBT, PDF, or fixed-layout EPUBs.",
|
||||||
mediaItem.Title,
|
mediaItem.Title,
|
||||||
))
|
)
|
||||||
|
return &str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1363,11 +1365,12 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
|
|||||||
// Flag manga for potential reorganization (info level)
|
// Flag manga for potential reorganization (info level)
|
||||||
if mediaItem.FormatGroup == "fixed_layout" &&
|
if mediaItem.FormatGroup == "fixed_layout" &&
|
||||||
(!mediaItem.MangaType.Valid || mediaItem.MangaType.String == "yes" || mediaItem.MangaType.String == "yes_and_right_to_left") {
|
(!mediaItem.MangaType.Valid || mediaItem.MangaType.String == "yes" || mediaItem.MangaType.String == "yes_and_right_to_left") {
|
||||||
return new(fmt.Sprintf(
|
str := fmt.Sprintf(
|
||||||
"File '%s' appears to be manga (fixed-layout with images). "+
|
"File '%s' appears to be manga (fixed-layout with images). "+
|
||||||
"Consider moving to a manga or comics library for better organization.",
|
"Consider moving to a manga or comics library for better organization.",
|
||||||
mediaItem.Title,
|
mediaItem.Title,
|
||||||
))
|
)
|
||||||
|
return &str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -221,7 +221,8 @@ func (w *Worker) processJob(job *Job) {
|
|||||||
}
|
}
|
||||||
w.mu.Unlock()
|
w.mu.Unlock()
|
||||||
|
|
||||||
job.StartedAt = new(time.Now())
|
started := time.Now()
|
||||||
|
job.StartedAt = &started
|
||||||
|
|
||||||
w.mu.Lock()
|
w.mu.Lock()
|
||||||
if result, exists := w.results[job.ID]; exists {
|
if result, exists := w.results[job.ID]; exists {
|
||||||
@@ -253,7 +254,8 @@ func (w *Worker) processJob(job *Job) {
|
|||||||
err = fmt.Errorf("unknown job type: %s", job.Type)
|
err = fmt.Errorf("unknown job type: %s", job.Type)
|
||||||
}
|
}
|
||||||
|
|
||||||
job.CompletedAt = new(time.Now())
|
completed := time.Now()
|
||||||
|
job.CompletedAt = &completed
|
||||||
job.Error = err
|
job.Error = err
|
||||||
job.Result = result
|
job.Result = result
|
||||||
|
|
||||||
|
|||||||
@@ -226,7 +226,8 @@ func (d *OfflineDetector) GetDeviceStatus(ctx context.Context, deviceID pgtype.U
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return new(d.getDeviceStatus(device)), nil
|
deviceStatus := d.getDeviceStatus(device)
|
||||||
|
return &deviceStatus, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *OfflineDetector) ListOfflineDevices(ctx context.Context) ([]DeviceOnlineStatus, error) {
|
func (d *OfflineDetector) ListOfflineDevices(ctx context.Context) ([]DeviceOnlineStatus, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user