This commit is contained in:
Schneider Roland 2025-02-21 23:37:46 +01:00
parent cfc2d0040b
commit bc8e58e472
4 changed files with 25 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
node_modules
data

View File

@ -4,6 +4,9 @@
## 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 .
@ -20,10 +23,19 @@ 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/
```

View File

@ -9,6 +9,14 @@ const config = process.env.config || '{ "uploadGroups": [{ "matcher": "^test.*\.
app.use(fileUpload())
app.use((req, res, next) =>{
const authenticated = req.get('Authorization') === 'Bearer ' + process.env.API_KEY ;
if(!authenticated){
return res.status(401).send('Unauthorized');
}
next();
});
const processGroups = () => {
const files = [] = fs.readdirSync(uploadPath);

2
test-1.txt Normal file
View File

@ -0,0 +1,2 @@
curl -XPOST -F 'data=@test-5.txt' localhost:3000/