In the spirit of Seneca, we should make a plugin for our imagini service. Let's split our code into two parts:
- The imagini plugin, a service that manipulates images
- A Seneca microservice, which exposes the imagini plugin, and possibly others later on
There's lot of room for improvement on our code, starting with code we repeated constantly. It's important to detect repetitions while our service is still very small.
The most repeated part is the local filename. This is actually something you might want to configure when starting the service, so let's change that to a function. Start by changing our imagini.js file to be a plugin. Clear all content and write this code:
const sharp = require("sharp");const path = require("path");