The service saves the Bearer token in
SESSION
, all services are server-side. Database is a MUST!!!
The instance
function creates an axios instance with the user's authorization token, which is stored in the session object.
The getCurrentUser
function retrieves the details of the currently logged-in user.
The getCountImages
function retrieves the total number of images downloaded by the user, and the getLocalCount
function retrieves the number of images downloaded and those yet to be downloaded.
The retrieveGettyImagesData
function retrieves the user's downloaded images from the Getty Images API, stores them in a local database, and returns an array of the downloaded image IDs.
The retrieveGettyUri
function retrieves the URIs for the images that are yet to be downloaded and updates their records in the local database.
The retrieveGettyMeta
function retrieves the metadata for the images that are yet to be downloaded and updates their records in the local database.
2 cronjobs
as following
- every
30min
- runs count query (checking all new images)
- saves into db the new images with
filename
andmeta
- every
35min
- runs the query to send to cloudinary donwloadable
Urls
from getty (url expires after some time) - after upload successfull, update
downloaded: TRUE
into db, so service will know that image was uploaded - finally running query to bulk edit
filename
&meta
on all the iamges that was just uploaded
- runs the query to send to cloudinary donwloadable
Folder & Files architecture
Folder & Files architecture
- index.js
- config (all config keys for making service work)
- api (folder contains all api files with all functions)
- api.postman_collection.json (all requests collection for Postman)
- db.sql (mysql database schema)
Node.js v16.8+ is required to run the microservice.
- Make sure you have git, node, and npm installed.
- Clone this repository locally.
- Uplaod the
db.sql
file - Execute
npm i
and thennode index
from the root directory of the repository. - Open
localhost:3000
in yourPostman
or similar. - Deploy on Vercel or other platforms
There are some routes inside
/
/count
you will get images_count previous request & total images to sync/test
this action simpky updloas some random 3 getty images to cloudinary/logs
this route exports all logs saved into DB, so it makes a clear view foir you is any errors was found/sync
this route donloads and uplaods iamges between dates - can pass paramsfrom
&to
default istoday
Name | Link | Installed |
---|---|---|
NodeJS | https://nodejs.org/en | ✅ |
Express | https://expressjs.com | ✅ |
Axios | https://axios-http.com/docs/intro | ✅ |
Knex | https://knexjs.org/ | ✅ |
Cloudinary SDK | https://cloudinary.com/documentation/cloudinary_sdks | ✅ |
GettyImages API | https://api.gettyimages.com/swagger/index.html | ✅ |
Dayjs | https://day.js.org/ | ✅ |