This commit is contained in:
Sergey Zhemoytel 2025-01-31 22:35:47 +03:00
parent b9d5f0b884
commit 140721e7fc
4 changed files with 40 additions and 5 deletions

View file

@ -1,2 +1,6 @@
# r11_urpm-repo
Проверим успешную загрузку пакета:
curl -X POST "http://localhost:8888/x86_64" -H "Authorization: Bearer your_secret_token_here" -F "package=@/path/to/your/package.rpm"

23
api.go
View file

@ -3,9 +3,32 @@ package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"strings"
"github.com/spf13/viper"
)
func (r *Repository) UploadHandler(w http.ResponseWriter, req *http.Request) {
authHeader := req.Header.Get("Authorization")
if authHeader == "" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
logger.Error("Authorization header missing")
return
}
parts := strings.Split(authHeader, " ")
if len(parts) != 2 || parts[0] != "Bearer" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
logger.Error("Invalid Authorization header format")
return
}
token := parts[1]
if token != viper.GetString("auth.token") {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
logger.Error("Invalid token")
return
}
arch := chi.URLParam(req, "arch")
if arch == "" {
http.Error(w, "Invalid architecture", http.StatusBadRequest)

View file

@ -4,3 +4,6 @@ repository:
path: "/var/www/html/urpm-repo"
log:
level: "info"
auth:
token: "your_secret_token_here"

View file

@ -30,15 +30,21 @@ http {
listen 8080;
server_name localhost;
location / {
root /var/www/html/urpm-repo;
location / {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
location ~ ^/(x86_64|i386|aarch64|riscv64|noarch|src)/ {
alias /var/www/html/urpm-repo/$1/;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
location ~ ^/(x86_64|i386|aarch64|riscv64|noarch|src)/media_info/ {
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
@ -50,4 +56,3 @@ http {
}
}
}