Skip to content
Snippets Groups Projects
Commit 72e13105 authored by Ophestra's avatar Ophestra
Browse files

record child for grouped images, correct logging in ImageUpdate

parent b2991228
No related branches found
No related tags found
No related merge requests found
...@@ -24,6 +24,7 @@ type Image struct { ...@@ -24,6 +24,7 @@ type Image struct {
User string `json:"user"` User string `json:"user"`
Source string `json:"source"` Source string `json:"source"`
Parent string `json:"parent"` Parent string `json:"parent"`
Child string `json:"child"`
Commentary string `json:"commentary"` Commentary string `json:"commentary"`
CommentaryTranslation string `json:"commentary_translation"` CommentaryTranslation string `json:"commentary_translation"`
} }
...@@ -302,27 +303,61 @@ func (s *Store) ImageUpdate(hash, source, parent, commentary, commentaryTranslat ...@@ -302,27 +303,61 @@ func (s *Store) ImageUpdate(hash, source, parent, commentary, commentaryTranslat
s.getLock(hash).Lock() s.getLock(hash).Lock()
defer s.getLock(hash).Unlock() defer s.getLock(hash).Unlock()
var msg string
// Update and save // Update and save
if source != "\000" { if source != "\000" {
info.Source = source info.Source = source
msg += "source"
} }
if parent != "\000" && s.ImageSnowflake(parent).Snowflake == parent { if parent != "\000" {
if p := s.ImageSnowflake(parent); p.Snowflake == parent {
s.getLock(p.Hash).Lock()
defer s.getLock(p.Hash).Unlock()
info.Parent = parent info.Parent = parent
// Update the parent to reflect the child
p.Child = info.Snowflake
s.imageMetadataWrite(p)
if msg != "" {
msg += ", "
}
msg += "parent " + parent
}
} }
if commentary != "\000" { if commentary != "\000" {
info.Commentary = commentary info.Commentary = commentary
if msg != "" {
msg += ", "
}
msg += "commentary"
} }
if commentaryTranslation != "\000" { if commentaryTranslation != "\000" {
info.CommentaryTranslation = commentaryTranslation info.CommentaryTranslation = commentaryTranslation
if msg != "" {
msg += ", "
} }
msg += "commentary translation"
}
if msg != "" {
s.imageMetadataWrite(info)
log.Infof("Image %s %s updated.", info.Snowflake, msg)
}
}
func (s *Store) imageMetadataWrite(info Image) {
if payload, err := json.Marshal(info); err != nil { if payload, err := json.Marshal(info); err != nil {
s.fatalClose(fmt.Sprintf("Error encoding metadata of image %s while updating, %s", hash, err)) s.fatalClose(fmt.Sprintf("Error encoding metadata of image %s, %s", info.Hash, err))
} else { } else {
if err = os.WriteFile(s.ImageMetadataPath(hash), payload, s.PermissionFile); err != nil { if err = os.WriteFile(s.ImageMetadataPath(info.Hash), payload, s.PermissionFile); err != nil {
s.fatalClose(fmt.Sprintf("Error saving metadata of image %s while updating, %s", hash, err)) s.fatalClose(fmt.Sprintf("Error saving metadata of image %s, %s", info.Hash, err))
} }
} }
log.Infof("Image hash %s source set to %s.", hash, source)
} }
// ImageSnowflakes returns a slice of image snowflakes. // ImageSnowflakes returns a slice of image snowflakes.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment