This is a server for my PicoFrame.
It uses a Google Cloud Service Account to find images uploaded to google drive and then crop and resize them for a Pimoroni InkyFrame.
Requirements: Node.js
yarn run build
Development with hot reload
yarn run dev
Production (after building)
node dist/server/main.js
# Port the server listens to
PORT=4000
# API Key protecting the endpoints
API_KEY=
# Path to Google Cloud Service Account credentials
# (see below)
CREDENTIALS=./credentials.json
# Google Drive folder ids to look in.
# If this is empty then the server will download
# anything shared with the google service account
FOLDER_IDS=
# Path to save images to
IMAGE_DIR=./pico_frame_images/
# Supported image mime types
IMAGE_MIME_TYPES=image/jpeg,image/png,image/gif,image/bmp
# Image height
IMAGE_HEIGHT=480
# Image width
IMAGE_WIDTH=800
# cron schedule for syncing drive files.
# See https://crontab.guru/#*/5_*_*_*_*
SYNC_DRIVE_SCHEDULE="*/5 * * * *"
# Whether to sync drive on start up
SYNC_DRIVE_IMMEDIATELY=false
To list and download images from your google drive you will need a google cloud service account.
Head over to https://console.cloud.google.com/apis/credentials. If you've not already signed up, you will need to agree to the terms and services.
Create a new project and give it a name.
-
Click on Enabled APIs & Services then + Enable APIs and Services
-
Search for Drive and click on Google Drive API and then Enable
-
Click on OAuth consent screen and select External then create
-
Fill in the required details and anything else you want and click Save and continue.
-
Click Add or remove scopes
-
Search for /auth/drive.readonly and check it
-
Click Update at the bottom.
-
Click Save and continue
-
Add any test users you'd like and then click Save and continue
-
Click Credentials
-
Click + Create Credentials then Service account
-
Fill in the name
-
Click Save and continue
-
Click Continue
-
Click Done
-
Click on the service account you just created
-
Click the Keys tab
-
Click Add Key then Create new key
-
Select JSON then Create
-
Save the key and place it in the project folder named credentials.json
-
Click on your service account then Details
-
Copy the email address
-
Go to https://drive.google.com/drive/ and click on a file or folder your want to make available to your service account
-
Click Share and paste the email address into the text box and click Send
-
Repeat for each file and folder your want to share