superdesk / web-publisher

Superdesk Publisher - the next generation publishing platform for journalists and newsrooms.
GNU Affero General Public License v3.0
97 stars 55 forks source link

Optimize heavy media file transport in getAssetAction #1244

Open NonSparkly opened 1 year ago

NonSparkly commented 1 year ago

Hi!

We've noticed that the resource return for media assets always contain the media asset itself as a base64 encoded string. This seems to slow down the return by a huge amount and since the URL to the hosted version of the file is also returned, it's unnecessary for a lot of use-cases. Could this be taken out, moved into a parameterized version of the same response or even moved into its own route entirely?

  public function getAssetsAction(string $mediaId, string $extension): SingleResourceResponseInterface {
    $fileProvider = $this->fileProvider;
    $file = $fileProvider->getFile(ArticleMedia::handleMediaId($mediaId), $extension);

    if (null === $file) {
      throw new NotFoundHttpException('Media don\'t exist in storage');
    }

    $mediaManager = $this->mediaManager;

    return new SingleResourceResponse([
        'media_id' => $mediaId,
        'URL' => $mediaManager->getMediaPublicUrl($file),
        //  'media' => base64_encode($mediaManager->getFile($file)), <----- THIS LINE IS HEAVY
        'mime_type' => Mime::getMimeFromExtension($file->getFileExtension()),
        'filemeta' => [],
    ]);
  }
antonborgstrom commented 1 year ago

I agree!