diff --git a/controllers/download_controller/download_resource_handler.go b/controllers/download_controller/download_resource_handler.go index b985f19a23bdb670af9066edae19c4ef538dd370..fb15be23c66711af8095f3a4ff91d228a45de878 100644 --- a/controllers/download_controller/download_resource_handler.go +++ b/controllers/download_controller/download_resource_handler.go @@ -9,7 +9,6 @@ import ( "time" "github.com/getsentry/sentry-go" - "github.com/turt2live/matrix-media-repo/util" "github.com/turt2live/matrix-media-repo/util/stream_util" "github.com/djherbis/stream" @@ -140,7 +139,7 @@ func downloadResourceWorkFn(request *resource_handler.WorkRequest) (resp *worker resp.filename = "" resp.contentType = "" resp.media = nil - resp.err = util.PanicToError(err) + resp.err = nil } }() diff --git a/controllers/info_controller/info_controller.go b/controllers/info_controller/info_controller.go deleted file mode 100644 index 98eb09699fd1aa1d15df2564dcf8884b69961054..0000000000000000000000000000000000000000 --- a/controllers/info_controller/info_controller.go +++ /dev/null @@ -1,70 +0,0 @@ -package info_controller - -import ( - "bytes" - "image/png" - - "github.com/buckket/go-blurhash" - "github.com/disintegration/imaging" - "github.com/turt2live/matrix-media-repo/common/rcontext" - "github.com/turt2live/matrix-media-repo/controllers/download_controller" - "github.com/turt2live/matrix-media-repo/storage" - "github.com/turt2live/matrix-media-repo/types" - "github.com/turt2live/matrix-media-repo/util/stream_util" -) - -func GetOrCalculateBlurhash(media *types.Media, rctx rcontext.RequestContext) (string, error) { - rctx.Log.Info("Attempting fetch of blurhash for sha256 of " + media.Sha256Hash) - db := storage.GetDatabase().GetMetadataStore(rctx) - cached, err := db.GetBlurhash(media.Sha256Hash) - if err != nil { - return "", err - } - - if cached != "" { - rctx.Log.Info("Returning cached blurhash: " + cached) - return cached, nil - } - - rctx.Log.Info("Getting minimal media record to calculate blurhash") - minMedia, err := download_controller.FindMinimalMediaRecord(media.Origin, media.MediaId, true, rctx) - if err != nil { - return "", err - } - defer stream_util.DumpAndCloseStream(minMedia.Stream) - - // No cached blurhash: calculate one - rctx.Log.Info("Decoding image for blurhash calculation") - imgSrc, err := imaging.Decode(minMedia.Stream) - if err != nil { - return "", err - } - - // Resize the image to make the blurhash a bit more reasonable to calculate - rctx.Log.Info("Resizing image for blurhash (faster calculation)") - smallImg := imaging.Fill(imgSrc, rctx.Config.Features.MSC2448Blurhash.GenerateWidth, rctx.Config.Features.MSC2448Blurhash.GenerateHeight, imaging.Center, imaging.Lanczos) - imgBuf := &bytes.Buffer{} - err = imaging.Encode(imgBuf, smallImg, imaging.PNG) - if err != nil { - return "", err - } - decoded, err := png.Decode(imgBuf) - if err != nil { - return "", err - } - - rctx.Log.Info("Calculating blurhash") - encoded, err := blurhash.Encode(rctx.Config.Features.MSC2448Blurhash.XComponents, rctx.Config.Features.MSC2448Blurhash.YComponents, decoded) - if err != nil { - return "", err - } - - // Save the blurhash for next time - rctx.Log.Infof("Saving blurhash %s and returning", encoded) - err = db.InsertBlurhash(media.Sha256Hash, encoded) - if err != nil { - return "", err - } - - return encoded, nil -} diff --git a/types/MAYBE_LEGACY.txt b/types/MAYBE_LEGACY.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/util/LEGACY_errors.go b/util/LEGACY_errors.go deleted file mode 100644 index 8393f82bf3cf4a5c267c4e3e9b9b357d34782964..0000000000000000000000000000000000000000 --- a/util/LEGACY_errors.go +++ /dev/null @@ -1,14 +0,0 @@ -package util - -import "errors" - -func PanicToError(err interface{}) error { - switch x := err.(type) { - case string: - return errors.New(x) - case error: - return x - default: - return errors.New("unknown panic") - } -}