mycorrhiza/internal/shroom/unattach.go
Timur Ismagilov 4c31c8cc32 Move a lot of files into internal dir
Outside of it are web and stuff that needs further refactoring
2024-06-04 23:26:49 +03:00

33 lines
971 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package shroom
import (
"fmt"
hyphae2 "github.com/bouncepaw/mycorrhiza/internal/hyphae"
"github.com/bouncepaw/mycorrhiza/internal/user"
"github.com/bouncepaw/mycorrhiza/history"
)
// RemoveMedia removes media from the media hypha and makes a history record about that. If it only had media, the hypha will be deleted. If it also had text, the hypha will become textual.
func RemoveMedia(u *user.User, h *hyphae2.MediaHypha) error {
hop := history.
Operation(history.TypeRemoveMedia).
WithFilesRemoved(h.MediaFilePath()).
WithMsg(fmt.Sprintf("Remove media from %s", h.CanonicalName())).
WithUser(u).
Apply()
if len(hop.Errs) > 0 {
rejectRemoveMediaLog(h, u, "fail")
// FIXME: something may be wrong here
return fmt.Errorf("Could not unattach this hypha due to internal server errors: <code>%v</code>", hop.Errs)
}
if h.HasTextFile() {
hyphae2.Insert(hyphae2.ShrinkMediaToTextual(h))
} else {
hyphae2.DeleteHypha(h)
}
return nil
}