Skip to content

Commit

Permalink
Big refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jmugliston committed Jul 24, 2024
1 parent e3cb07a commit ae14f2b
Show file tree
Hide file tree
Showing 33 changed files with 2,687 additions and 5,211 deletions.
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
commit-message:
# Prefix all commit messages with "chore: "
prefix: "chore"
schedule:
interval: "weekly"
30 changes: 30 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: build

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: npm run lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
tmp
.env*

.vscode

# Logs
logs
*.log
Expand Down
12 changes: 12 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @see https://prettier.io/docs/en/configuration.html
* @type {import("prettier").Config}
*/
const config = {
trailingComma: 'es5',
tabWidth: 2,
semi: false,
singleQuote: true,
}

export default config
4 changes: 0 additions & 4 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ COPY --chown=node:node src ./src
USER node

HEALTHCHECK --interval=60s --timeout=10s --start-period=5s \
CMD node ./src/healthcheck.js
CMD node ./src/scripts/healthcheck.js

CMD ["dumb-init", "npm", "start"]
7 changes: 7 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright (c) 2024 James Mugliston

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 changes: 69 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
# Putio Downloader
# Put.io File Downloader

An API that can receive callbacks from [Put.io](https://put.io) and download files to a local directory.
<div align="center">
<img
src="https://github.com/atheius/putio-downloader/raw/HEAD/logo.jpeg"
width="150"
height="auto"
/>
</div>

This project was created using the [fastify-cli](https://github.com/fastify/fastify-cli).
<div align="center">

## Install
![buiild](https://github.com/atheius/putio-downloader/actions/workflows/main.yml/badge.svg) ![docker](https://img.shields.io/docker/v/atheius/putio-downloader) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

```
npm install
</div>

**Put.io File Downloader** is an API that can receive file callbacks (webhooks) from [Put.io](https://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:

```mermaid
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)
```

## Getting Started
Expand All @@ -17,10 +40,12 @@ Create a .env file in the root of the project like the following:
```sh
# Put.io access token
ACCESS_TOKEN=XXXXXXXX
# Processing directory for in-progress downloads
PROCESSING_DIR=./processing
# Location for downloaded files
DOWNLOAD_DIR=./download
# Processing directory for in-progress downloads
PROCESSING_DIR=./tmp
# Specify whether files should be deleted after download
DELETE_REMOTE_FILES_AFTER_DOWNLOAD=true
```

### Download Schedule
Expand All @@ -33,22 +58,54 @@ DOWNLOAD_SCHEDULE_ENABLED=true
DOWNLOAD_SCHEDULE_CRON=0 7 * * *
```

## Callbacks

This API is designed to process callbacks from put.io.
## Install

Go to https://app.put.io/settings/callback-url and add the URL where you want to receive callbacks.
```
npm install
```

## Development

Use the following to run the development server:

```sh
npm run dev
```

Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

You can test a file callback using curl e.g.

```sh
curl -X POST localhost:3000/file \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "file_id=<the-file-id>"
```

## Test

```sh
npm test
```

## Docker

To build and run the Docker container:

```sh
# 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
```
19 changes: 19 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import js from '@eslint/js'
import eslintConfigPrettier from 'eslint-config-prettier'
import globals from 'globals'

export default [
js.configs.recommended,
{
plugins: {},
rules: {
'no-unused-vars': 'off',
},
languageOptions: {
ecmaVersion: 2022,
sourceType: 'module',
globals: globals.node,
},
},
eslintConfigPrettier,
]
Binary file added logo.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ae14f2b

Please sign in to comment.