Go to file
2025-02-28 09:31:21 +01:00
.gitignore add Docker build and push scripts; update versioning and environment configuration 2025-02-27 21:50:20 +01:00
build.docker.image.sh add Docker build and push scripts; update versioning and environment configuration 2025-02-27 21:50:20 +01:00
Dockerfile inital commit 2025-02-21 17:14:55 +01:00
example.env add example environment configuration for upload path and groups 2025-02-27 22:53:43 +01:00
index.js docs: update README with configuration details and API endpoints; modify index.js logging message 2025-02-28 09:31:21 +01:00
package-lock.json add Docker build and push scripts; update versioning and environment configuration 2025-02-27 21:50:20 +01:00
package.json fix: enable file deletion in cleanup process; update version to 1.3.0 2025-02-28 06:08:28 +01:00
push.docker.image.sh add Docker build and push scripts; update versioning and environment configuration 2025-02-27 21:50:20 +01:00
README.md docs: update README with configuration details and API endpoints; modify index.js logging message 2025-02-28 09:31:21 +01:00
test-1.txt add auth 2025-02-21 23:37:46 +01:00

simple http file api

Configuration

API_KEY: if set, then the client must send the authrization header with the value "Bearer {API_KEY}", otherwise the api returnes 401. If not set, no authentication needed

UPLOAD_PATH: path, where the uploaded files will be stored CONFIG: config in json format e.g. { "uploadGroups": [ { "matcher": "^mmkb-android-[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}-int.apk$", "groupSize": 3 } ] }

uploadGroups: groups of files defined by a regex matcher. For each group can be set a groupSize property. If the file count in the group is more then the groupSize, then the oldest files in the group will be deleted.

API

get all uploaded files

path: / method: GET

get all uploaded files

get the sate of the actual upload groups

path: /state method: GET

Get the state of the actual upload groups

Cleanup

path: /clean

Execute a cleanup manually. Cleanup is beased on the uploadGroups configuration

Get file

path /:filename method: GET

get the file with the given name

Delete file

path /:filename method: DELETE

Delete the file with the given name

Upload file

path / method: POST

Upload a file. If file with the given name already exists, http status 409 will be returned. After a successfull file upload, a cleanup will be performed

Upload file

path / method: PUT

Upload a file. If the file with the given name already exists, it will be overwritten After a successfull file upload, a cleanup will be performed

Create Docker image

npm i

docker build -t simple-http-upload:0.1.0 .

docker build -t 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0 .

sudo vim /etc/docker/daemon.json

{
    "insecure-registries" : [ "172.22.102.100:40016" ]
}

docker login 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0 docker push 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0

Run

docker run --rm -p 3000:3000 -v ./data:/data simple-http-upload:0.1.0

docker run --rm -p 3000:3000 -v ./data:/data 172.22.102.100:40016/team-mmkb/simple-http-upload:0.1.0

docker run --rm -p 3000:3000 -v ./data:/data -e API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtbWtiIiwibmFtZSI6Im1ta2IiLCJpYXQiOjE1MTYyMzkwMjJ9.vBHcF6SFhImcGC4xDxKdPyq3shjNTPkVxkvdDyfx7Ss simple-http-upload:0.1.0

Test

curl -XPOST -F 'data=@test-5.txt' localhost:3000/ 

curl -XPOST -F 'data=@test-1.txt' --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtbWtiIiwibmFtZSI6Im1ta2IiLCJpYXQiOjE1MTYyMzkwMjJ9.vBHcF6SFhImcGC4xDxKdPyq3shjNTPkVxkvdDyfx7Ss" localhost:3000/