query getThumbnails($id: string!) {
thumbnail(id: $id) {
id:int
created_at:int //timestamp
status:String //processing|completed|failed
error_message:String //not empty when `status` value is `failed`
error_code:int //not empty when `status` value is `failed`
website:String //url
urls {
_256:String //url
_512:String //url
}
}
}
mutation addThumbnails($website: String) {
insert_thumbnail(objects: {website: $website}){
returning {
id:int
created_at:int //timestamp
status:String //processing|completed|failed
error_message:String //not empty when `status` value is `failed`
error_code:int //not empty when `status` value is `failed`
website:String //url
urls {
_256:String //url
_512:String //url
}
}
}
}
- Code is written in Typescript.
- Solution is dockerized. ( setup is described with a
Dockerfile). - Runnable with docker compose ( there is
docker-compose.yamlto run).
-
(primary)
thumbnailquery andinsert_thumbnailmutation works as follows:-
insert_thumbnailreceives awebsitestring input withprotocol://domain.tldformat and makes a PNG screenshot out of it. -
statusrepresents thumbnail generation status. status can have following values:processing: thumbnail is being generated. in this stateurlvalues are empty as processing is still ongoing. For current challenge,insert_thumbnailmutation is synchronous and only returns a value after generating thumbnail attempt is done. So in practice, we should NOT see this value at all.completed: thumbnail generation finished successfully. now ´url´ should have thumbnails with corresponding resolution.failed: thumbnail generation has failed.error_messageanderror_codeneeds to be set.(these fields can be random even. It does not matter much)
-
Screenshots are served as static files and their urls returned to client(via
insert_thumbnailmutation andthumbnailquery) under:urls { _256 #url of 256x256 thumbnail _512 #url of 512x512 thumbnail }
-
-
(minor bonus) Files are served using minio.
-
(big bonus) Add an additional
thumbnailSubscription with exact spec with its Query counterpartinsert_thumbnailMutation will immediately return a response withstatus:processingand upon generation completion it needs to be resolved withstatus:failedorcompleted.- Subscription will emit complete object on each
statuschange.
- DB usage is not mandatory
- Puppeteer is your friend.
// for local env
cp .env.example .env
// change .env to your credentials
yarn install
yarn start:dev
// or using docker
docker-compose up -d