Put.io File Downloader is an API that can receive file callbacks (webhooks) from Put.io and download them to a local directory.
To receive file callbacks from Put.io, configure the URL here: https://app.put.io/settings/callback-url
The API can receive multiple file callbacks simultaneously, but downloads are queued and retrieved one at a time.
See below for a flow of how the API works:
flowchart TD
A("New file(s) added in Put.io") -->|Callback via POST request| B
B[Receive callback on /file endpoint] --> C
C[Queue download] --> D
D["Download and unzip file(s)"] -->|Request zip| A
D --> E
E-->|Delete file| A
E["Delete remote file (optional)"] --> F(Done)
Create a .env file in the root of the project like the following:
# Put.io access token
ACCESS_TOKEN=XXXXXXXX
# Processing directory for in-progress downloads
PROCESSING_DIR=./processing
# Location for downloaded files
DOWNLOAD_DIR=./download
# Specify whether files should be deleted after download
DELETE_REMOTE_FILES_AFTER_DOWNLOAD=true
You can enable a download schedule with a cron e.g.
DOWNLOAD_SCHEDULE_ENABLED=true
# Download files at 7am every day...
DOWNLOAD_SCHEDULE_CRON=0 7 * * *
npm install
Use the following to run the development server:
npm run dev
Open http://localhost:3000 to view it in the browser.
You can test a file callback using curl e.g.
curl -X POST localhost:3000/file \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "file_id=<the-file-id>"
npm test
To build and run the Docker container:
# Build the container
docker build -t putio-downloader .
# Create a folder to mount as a volume for downloads
mkdir data
chmod 755 data
# Run the container
docker run \
--volume ${PWD}/data:/data \
--env ACCESS_TOKEN="token" \
--env PROCESSING_DIR="/data/processing" \
--env DOWNLOAD_DIR="/data/download" \
-p 3000:3000 \
putio-downloader:latest