filebrowser/backend/http/public.go

50 lines
1.5 KiB
Go
Raw Permalink Normal View History

package http
import (
2024-11-21 00:15:30 +00:00
"encoding/json"
2024-08-24 22:02:33 +00:00
"fmt"
"net/http"
"strings"
2024-12-17 00:01:55 +00:00
"github.com/gtsteffaniak/filebrowser/backend/files"
"github.com/gtsteffaniak/filebrowser/backend/users"
2024-12-17 00:01:55 +00:00
_ "github.com/gtsteffaniak/filebrowser/backend/swagger/docs"
2024-11-21 00:15:30 +00:00
)
2024-11-21 00:15:30 +00:00
func publicShareHandler(w http.ResponseWriter, r *http.Request, d *requestContext) (int, error) {
2024-11-26 17:21:41 +00:00
file, ok := d.raw.(files.ExtendedFileInfo)
2024-08-24 22:02:33 +00:00
if !ok {
2025-01-09 01:02:57 +00:00
return http.StatusInternalServerError, fmt.Errorf("failed to assert type files.FileInfo")
2024-08-24 22:02:33 +00:00
}
2025-01-05 19:05:33 +00:00
file.Path = strings.TrimPrefix(file.Path, files.RootPaths["default"])
2020-11-03 19:17:22 +00:00
return renderJSON(w, r, file)
2024-11-21 00:15:30 +00:00
}
2024-11-21 00:15:30 +00:00
func publicUserGetHandler(w http.ResponseWriter, r *http.Request) {
2024-02-10 00:13:02 +00:00
// Call the actual handler logic here (e.g., renderJSON, etc.)
// You may need to replace `fn` with the actual handler logic.
2024-11-21 00:15:30 +00:00
status, err := renderJSON(w, r, users.PublicUser)
if err != nil {
http.Error(w, http.StatusText(status), status)
}
}
2021-03-21 11:30:48 +00:00
2024-11-21 00:15:30 +00:00
// health godoc
// @Summary Health Check
// @Schemes
// @Description Returns the health status of the API.
// @Tags Health
// @Accept json
// @Produce json
// @Success 200 {object} HttpResponse "successful health check response"
// @Router /health [get]
func healthHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
response := HttpResponse{Message: "ok"} // Create response with status "ok"
err := json.NewEncoder(w).Encode(response) // Encode the response into JSON
if err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
}
2021-03-21 11:30:48 +00:00
}