handlers

package
v0.0.0-...-9ea8a2c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeJson

func DecodeJson(w http.ResponseWriter, r *http.Request, v any) error

Decode json

func DeleteAllUserS3Obj

func DeleteAllUserS3Obj(ctx context.Context, s3Client *s3.Client, bucket, prefix string) error

func GenerateUserIDHash

func GenerateUserIDHash(userID string, secretKey string) string

Generate hash from UserID to use it as prefix of s3key

func GetJWTToken

func GetJWTToken(userData database.User, jwtSecret string, expiry time.Duration) (string, error)

func RespondWithError

func RespondWithError(w http.ResponseWriter, logger *slog.Logger, msgToDev string, err error, code int)

Helper function to log error and also give appropriate response to the client To be used when the user needs an error but something in our code broke that needs to be fixed ASAP

func RespondWithJSON

func RespondWithJSON(w http.ResponseWriter, status int, payload interface{}) error

func RespondWithWarn

func RespondWithWarn(w http.ResponseWriter, logger *slog.Logger, msgToDev, msgToClient string, err error, code int)

Helper function to log warnings and also give appropirate response to the client To be used when the user needs an error message but our backend code is intact

func UserIDFromContext

func UserIDFromContext(ctx context.Context) (uuid.UUID, bool)

Fetches userID set in the auth middleware

Types

type AccessTokenResponse

type AccessTokenResponse struct {
	AccessToken string `json:"access_token"`
}

Outgoing: new access token

type CliVersion

type CliVersion struct {
	CompatibleVersion string `json:"compatible_version"`
}

Outgoing: CLI version response

type FileDetailedData

type FileDetailedData struct {
	FileName           string    `json:"file_name"`
	ID                 uuid.UUID `json:"file_id"`
	Status             string    `json:"status"`
	PlaintextSizeBytes int64     `json:"plaintext_size_bytes"`
	EncryptedSizeBytes int64     `json:"encrypted_size_bytes"`
	S3Key              string    `json:"s3_key"`
	KeyManagementMode  string    `json:"key_management_mode"`
	PlaintextHash      string    `json:"plaintext_hash"`
}

Outgoing: Send deatils of one file

type FileHash

type FileHash struct {
	Hash string `json:"hash"`
}

Outgoing: send file hash

type FileIDConflictMatches

type FileIDConflictMatches struct {
	FileName string    `json:"file_name"`
	FileID   uuid.UUID `json:"file_id"`
}

Outgoing: send multiple file matches to resolve file id conflict

type FileUploadMetadata

type FileUploadMetadata struct {
	FileID             uuid.UUID `json:"file_id"`
	PlaintextHash      string    `json:"plaintext_hash"`
	PlaintextSizeBytes int64     `json:"plaintext_size_bytes"`
	PassphraseSalt     string    `json:"passphrase_salt"`
}

Incoming: send by the client after successful file upload

type FileUploadRequest

type FileUploadRequest struct {
	FileName string `json:"file_name"`
	MimeType string `json:"mime_type"`
}

Incoming: sent by the client before we generate a presigned S3 POST URL. It carries basic metadata for the upload.

type FileUploadSuccessResponse

type FileUploadSuccessResponse struct {
	S3ObjectKey      string `json:"s3_object_key"`
	UploadedFileSize int64  `json:"uploaded_file_size"`
}

Outgoing: Send status if file upload is successfull

type FilesMetadata

type FilesMetadata struct {
	FileName           string    `json:"file_name"`
	EncryptedSizeBytes int64     `json:"encrypted_size_bytes"`
	Status             string    `json:"status"`
	KeyManagementMode  string    `json:"key_management_mode"`
	CreatedAt          time.Time `json:"created_at"`
	ID                 uuid.UUID `json:"file_id"`
}

Outgoing: Send all files of a user

type PassphraseSaltRes

type PassphraseSaltRes struct {
	Salt string `json:"salt"`
}

Outgoing: Send passphrase salt

type PresignResponse

type PresignResponse struct {
	FileID         uuid.UUID         `json:"file_id"`
	UploadResource aws.S3PutResponse `json:"upload_resource"`
}

Outgoing: presigned url response to the client

type RefreshToken

type RefreshToken struct {
	RefreshToken string `json:"refresh_token"`
}

Incoming: refresh token

type Server

type Server struct {
	Store     *store.Store
	Logger    *slog.Logger
	Cfg       *config.Config
	AwsConfig aws.Config
	S3Client  *s3.Client
	SESClient *sesv2.Client
}

Server struct to give access of store and logger to each handler as a method

func NewServer

func NewServer(store *store.Store, cfg *config.Config, awsConfig aws.Config, s3Client *s3.Client, sesClient *sesv2.Client) *Server

func (*Server) Auth

func (s *Server) Auth(next http.Handler) http.Handler

func (*Server) HandlerCliVersion

func (s *Server) HandlerCliVersion(w http.ResponseWriter, r *http.Request)

Sends the current cli version compatible with the server

func (*Server) HandlerCompleteFileUpload

func (s *Server) HandlerCompleteFileUpload(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerCreateUser

func (s *Server) HandlerCreateUser(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerDeleteFile

func (s *Server) HandlerDeleteFile(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerDeleteUser

func (s *Server) HandlerDeleteUser(w http.ResponseWriter, r *http.Request)
func (s *Server) HandlerGenerateDownloadLink(w http.ResponseWriter, r *http.Request)

Generates a signed cloudfront link and redirects to it after validating if the daily downloads limit is not hit

func (s *Server) HandlerGeneratePresignLink(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerGetAllFiles

func (s *Server) HandlerGetAllFiles(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerGetDetailedFile

func (s *Server) HandlerGetDetailedFile(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerGetFileHash

func (s *Server) HandlerGetFileHash(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerGetPassphraseSalt

func (s *Server) HandlerGetPassphraseSalt(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerLogin

func (s *Server) HandlerLogin(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerReadiness

func (s *Server) HandlerReadiness(w http.ResponseWriter, r *http.Request)

HandlerReadiness reports whether the API is healthy and ready to serve requests

func (*Server) HandlerRefreshToken

func (s *Server) HandlerRefreshToken(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerReset

func (s *Server) HandlerReset(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerResolveFileMatches

func (s *Server) HandlerResolveFileMatches(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerRevokeToken

func (s *Server) HandlerRevokeToken(w http.ResponseWriter, r *http.Request)

func (*Server) HandlerVerifyUser

func (s *Server) HandlerVerifyUser(w http.ResponseWriter, r *http.Request)

type UserIncoming

type UserIncoming struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

Incoming: struct to receive from the user

type UserLoginIncoming

type UserLoginIncoming struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

Incoming: Login struct to receive from the user

type UserLoginOutgoing

type UserLoginOutgoing struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

Outgoing: struct to send the user once they are logged in

type UserOutgoing

type UserOutgoing struct {
	ID        any       `json:"id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Email     string    `json:"email"`
}

Outgoing: User struct to send a response after creation

type VerifyRequest

type VerifyRequest struct {
	Email string `json:"email"`
	OTP   string `json:"otp"`
}

Incoming: receive account verification data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL