refactor(services): replace temporary variable pointer pattern with new() builtin
Simplify pointer creation in media scanner validation messages and worker job timestamps by using inline new() instead of local variable + address-of. In media_scanner.go this cleans up three validation error message returns (manga/comics library format checks). In worker.go it simplifies StartedAt and CompletedAt timestamp assignments.
This commit is contained in:
@@ -1297,13 +1297,12 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
|
||||
// Must be fixed-layout or comic archive
|
||||
if mediaItem.FormatGroup != "fixed_layout" &&
|
||||
mediaItem.FormatGroup != "comic_archive" {
|
||||
msg := fmt.Sprintf(
|
||||
return new(fmt.Sprintf(
|
||||
"EPUB file '%s' is reflowable (text-based), not fixed-layout (image-based). "+
|
||||
"Manga library only accepts fixed-layout EPUBs, CBZ, CBR, or image files. "+
|
||||
"Consider moving this file to an ebooks library.",
|
||||
mediaItem.Title,
|
||||
)
|
||||
return &msg
|
||||
))
|
||||
}
|
||||
|
||||
// Set manga-specific flags for fixed-layout EPUBs
|
||||
@@ -1328,12 +1327,11 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
|
||||
// Accept comic archives and fixed-layout
|
||||
if mediaItem.FormatGroup != "comic_archive" &&
|
||||
mediaItem.FormatGroup != "fixed_layout" {
|
||||
msg := fmt.Sprintf(
|
||||
return new(fmt.Sprintf(
|
||||
"File '%s' is not a comic archive format. "+
|
||||
"Comics library only accepts CBZ, CBR, CB7, CBT, PDF, or fixed-layout EPUBs.",
|
||||
mediaItem.Title,
|
||||
)
|
||||
return &msg
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1342,12 +1340,11 @@ func (s *MediaScanner) ValidateMediaItemForLibrary(
|
||||
// Flag manga for potential reorganization (info level)
|
||||
if mediaItem.FormatGroup == "fixed_layout" &&
|
||||
(!mediaItem.MangaType.Valid || mediaItem.MangaType.String == "yes" || mediaItem.MangaType.String == "yes_and_right_to_left") {
|
||||
msg := fmt.Sprintf(
|
||||
return new(fmt.Sprintf(
|
||||
"File '%s' appears to be manga (fixed-layout with images). "+
|
||||
"Consider moving to a manga or comics library for better organization.",
|
||||
mediaItem.Title,
|
||||
)
|
||||
return &msg
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -221,8 +221,7 @@ func (w *Worker) processJob(job *Job) {
|
||||
}
|
||||
w.mu.Unlock()
|
||||
|
||||
now := time.Now()
|
||||
job.StartedAt = &now
|
||||
job.StartedAt = new(time.Now())
|
||||
|
||||
w.mu.Lock()
|
||||
if result, exists := w.results[job.ID]; exists {
|
||||
@@ -254,8 +253,7 @@ func (w *Worker) processJob(job *Job) {
|
||||
err = fmt.Errorf("unknown job type: %s", job.Type)
|
||||
}
|
||||
|
||||
completedAt := time.Now()
|
||||
job.CompletedAt = &completedAt
|
||||
job.CompletedAt = new(time.Now())
|
||||
job.Error = err
|
||||
job.Result = result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user