112 lines
2.6 KiB
Markdown
112 lines
2.6 KiB
Markdown
# 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
|
|
|
|
```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
|
|
|
|
```bash
|
|
curl -XPOST -F 'data=@test-5.txt' localhost:3000/
|
|
|
|
curl -XPOST -F 'data=@test-1.txt' --header "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtbWtiIiwibmFtZSI6Im1ta2IiLCJpYXQiOjE1MTYyMzkwMjJ9.vBHcF6SFhImcGC4xDxKdPyq3shjNTPkVxkvdDyfx7Ss" localhost:3000/
|
|
```
|
|
|