https://github.com/linagora/Twake/wiki/Preview-service

The preview service is responsible for generating previews of uploaded files in Twake. It must work detached from the other services as a standalone sub service.

Generate a preview

Starting a preview generation is done with Rabbitmq

channel "services:preview"
{
  "document": {
	  "id": "uuid",
    "path": "a path",
    "provider": "S3",
		"encryption_algo": "aes-256-gcm",
    "encryption_key": "",
    "chunks": number,
    "mime": "type/subtype",
    "filename": "string",
  },
  "output": {
    "path": "a path",
    "provider": "S3",
		"encryption_algo": "aes-256-gcm",
    "encryption_key": "",
    "pages": 10, //Max number of pages for the document
    "width": 300, //Max width for the thumbnails
    "height": 200 //Max height for the thumbnails
  }
}

When preview generation ends, we get the following callback from a rmq event

channel "services:preview:callback"
{
	"document": {
	  "id": "uuid",
    "path": "a path",
    "provider": "S3"
  },
  "thumbnails": [
    {
	    "path": "a path",
			"size": number;
			"type": "type/subtype",
	    "provider": "S3",
		  "index": number,
	    "width": number,
	    "height": number
    },
    ...
  ]
}

And update the metadata with the following thumbnailResult

{
	"thumbnailResult": 
	    {
		    "path": "a path",
				"width": number,
				"height": number,
				"size": number,
				"type": "type/subtype"
	    },
}