- 000006 : users.username/username_normalized/password_hash/is_admin, index unique partiel sur username_normalized, DROP idx_users_email (unicité V1 = username, jamais email) ; 000007 destructif : resources.owner_id→user_id (FK→users, reset base dev), l'unicité racine devient par user - pkg/passwd : argon2id (t=1,m=64MiB,p=4,k=32), comparaison constant-time, VerifyTimedEqual (délai égalisé dummy-hash) ; pkg/auth : subject=user_id + claim device_id, TTL 7 j sans refresh - repository : Users (count/get/resolve-exact/create/update-password/ mark-deleted), Devices.MarkUser (user_id INFORMATIF uniquement) - handlers : POST /devices sans token, POST /auth/login (401 indistinguable user inconnu/mauvais mdp, device requis), PATCH /users/me/password (current_password, tokens non révoqués — limite V1), GET /users/resolve (exact lowercase, jamais email/is_admin) ; middleware RequireAuth (user authorisant, device porté) ; tout le scoping ressources passe user - bootstrap admin : users vide + ADMIN_* absents → refus de démarrer ; .env.example ; docs/api-v1.md §2/§3/§7/§8 - tests : migrations 000006/000007 (up/down), pkg/auth Identity, handlers login/password/resolve, helpers refactorés registerAndLogin, repo tests scopés user — suite backend verte
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/vaultdrop/backend/pkg/api"
|
|
"github.com/vaultdrop/backend/repository"
|
|
)
|
|
|
|
type ocrJobRequest struct {
|
|
FileID string `json:"fileId"`
|
|
}
|
|
|
|
func OcrJobsCreate(c *gin.Context) {
|
|
if Store == nil || Ocr == nil {
|
|
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
|
|
return
|
|
}
|
|
userID := c.GetString(UserIDKey)
|
|
|
|
var req ocrJobRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
api.Error(c, http.StatusBadRequest, "INVALID_REQUEST", "invalid request")
|
|
return
|
|
}
|
|
|
|
job, err := Ocr.Create(userID, c.GetString(DeviceIDKey), req.FileID)
|
|
if err != nil {
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
api.OK(c, job)
|
|
}
|
|
|
|
func OcrJobsGet(c *gin.Context) {
|
|
if Ocr == nil {
|
|
api.Error(c, http.StatusServiceUnavailable, "SERVICE_UNAVAILABLE", "backend not initialized")
|
|
return
|
|
}
|
|
deviceID := c.GetString(DeviceIDKey)
|
|
job, err := Ocr.Get(deviceID, c.Param("id"))
|
|
if err != nil {
|
|
if err == repository.ErrJobNotFound {
|
|
api.Error(c, http.StatusNotFound, "NOT_FOUND", "ocr job not found")
|
|
return
|
|
}
|
|
writeError(c, err)
|
|
return
|
|
}
|
|
api.OK(c, job)
|
|
}
|