Skip to content
Snippets Groups Projects
Select Git revision
  • ce542c61bba5684c5b9422dc280eb3b95deccd27
  • master default protected
  • improved-skeleton
  • xsrf-token
4 results

media-library.md

Blame
  • user avatar
    Alessandro Cerioni authored
    a6cc0f09
    History

    Media library service

    What it does

    This service allows you to upload a file on the Minio instance (compatible with S3) of your choice. The file will be stored in the bucket defined in the configuration of the service.

    How it works

    media-library-service

    The entrypoint of the service is a REST API provided by a NestJS application. The service uses the Javascript MinIO SDK to interact with a running instance of Minio.

    Before uploading the file, it makes sure that the specified bucket is created. If this is not the case, it creates it with a public read access.

    The files are folded in sub-buckets as following /<specified-bucket-name>/<year-YYYY>/<month-MM>/.

    The uploaded file keep its original name but is prefixed by an md5 computed based on its content witch gives the following pattern for file names: <md5>-<original-name>. This means that if we upload twice the exact same file, with the same name there will be only one file stored in MinIO.

    API documentation

    NestJS provides a swagger module that can be easily integrated. Using specific annotations alongside your endpoints declaration, this module will automatically generates a swagger documentation, reachable at /api-doc.

    Service health

    NestJS provides a health module based on Terminus, that gives you the opportunity to declare predefined or custom health indicators. It exposes the health status of the service at /health.
    This service will return a 200 http status code when all indicators are healthy. Otherwise it will return a 503 http status code.

    For this service we implemented a custom health indicator that checks the connection to MinIO giving the total number of buckets when the connection is succesful.

    Stats

    We are using a Node module called swagger-stats.
    It traces API calls, monitors API performance and usage statistics. It exposes the metrics in different formats, such as Prometheus format, so you may use Prometheus and Graphana for API monitoring and alerting.
    Those metrics are available at /swagger-stats/metrics.

    For more information about this module, visit the official swagger-stat page.

    Docker

    It is possible to run this service using Docker containers, using the docker-compose.yml and Dockerfile files.
    For more information, refer to the project [service-media-library][add a link]