internal

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

AuthMiddleware checks for a valid session cookie

func CleanExpiredSessions

func CleanExpiredSessions() error

CleanExpiredSessions removes all expired sessions

func ClearUploadProgress

func ClearUploadProgress()

ClearUploadProgress clears the upload progress

func CustomCORSMiddleware

func CustomCORSMiddleware() echo.MiddlewareFunc

CustomCORSMiddleware creates a custom CORS middleware that properly handles credentials

func DeleteSession

func DeleteSession(sessionID string) error

DeleteSession deletes a session by ID

func GenerateSessionID

func GenerateSessionID() (string, error)

GenerateSessionID generates a random session ID

func GetDateRange

func GetDateRange(userDB *sql.DB) (time.Time, time.Time, error)

func GetMessageMedia

func GetMessageMedia(userDB *sql.DB, messageID string) ([]byte, string, error)

func GetUserDB

func GetUserDB(userID string, username string) (*sql.DB, error)

GetUserDB retrieves the database connection for a specific user

func HandleActivity

func HandleActivity(c echo.Context) error

func HandleCalls added in v0.1.3

func HandleCalls(c echo.Context) error

func HandleChangePassword

func HandleChangePassword(c echo.Context) error

func HandleConversations

func HandleConversations(c echo.Context) error

func HandleDateRange

func HandleDateRange(c echo.Context) error

func HandleLogin

func HandleLogin(c echo.Context) error

func HandleLogout

func HandleLogout(c echo.Context) error

func HandleMe

func HandleMe(c echo.Context) error

func HandleMedia

func HandleMedia(c echo.Context) error

func HandleMessages

func HandleMessages(c echo.Context) error

func HandleProgress

func HandleProgress(c echo.Context) error

func HandleRegister

func HandleRegister(c echo.Context) error

func HandleSearch

func HandleSearch(c echo.Context) error

func HandleUpload

func HandleUpload(c echo.Context) error

func InitAuthDB

func InitAuthDB(filepath string) error

InitAuthDB initializes the authentication database

func InitDB

func InitDB(filepath string) error

func InitUserDB

func InitUserDB(userID string, filepath string) error

InitUserDB initializes a database for a specific user

func InsertCallLog

func InsertCallLog(userDB *sql.DB, call *CallLog) error

func InsertCallLogBatch

func InsertCallLogBatch(userDB *sql.DB, calls []CallLog) error

InsertCallLogBatch inserts multiple call logs in a single transaction for better performance

func InsertMessage

func InsertMessage(userDB *sql.DB, msg *Message) error

func NoCacheMiddleware

func NoCacheMiddleware(next echo.HandlerFunc) echo.HandlerFunc

NoCacheMiddleware adds cache control headers to prevent browser caching This ensures that dynamic API responses are always fetched fresh from the server

func ParseSMSBackupStreaming

func ParseSMSBackupStreaming(userDB *sql.DB, r io.Reader, batchSize int) (int, int, error)

ParseSMSBackupStreaming parses SMS backup file with streaming to reduce memory usage Each message is inserted immediately and memory is freed aggressively

func ProcessUploadedFile

func ProcessUploadedFile(userID string, username string, filePath string)

ProcessUploadedFile processes the uploaded file in the background

func SanitizeUsername

func SanitizeUsername(username string) string

SanitizeUsername converts a username to a safe filesystem name

func SaveUploadedFile

func SaveUploadedFile(file io.Reader, filename string) (string, error)

SaveUploadedFile saves the uploaded file to a temporary location

func SetUploadProgress

func SetUploadProgress(total, processed int, status string)

SetUploadProgress initializes or updates the upload progress

func UpdateCallProgress

func UpdateCallProgress(processed int)

UpdateCallProgress updates the progress for calls

func UpdateMessageProgress

func UpdateMessageProgress(processed int)

UpdateMessageProgress updates the progress for messages

func UpdatePassword

func UpdatePassword(userID string, newPassword string) error

UpdatePassword updates a user's password

func VerifyPassword

func VerifyPassword(user *User, password string) bool

VerifyPassword checks if the provided password matches the user's password hash

Types

type ActivityItem

type ActivityItem struct {
	Type        string    `json:"type"` // "message" or "call"
	Date        time.Time `json:"date"`
	Address     string    `json:"address"`
	ContactName string    `json:"contact_name,omitempty"`
	// Message-specific fields
	Message *Message `json:"message,omitempty"`
	// Call-specific fields
	Call *CallLog `json:"call,omitempty"`
}

func GetActivity

func GetActivity(userDB *sql.DB, startDate, endDate *time.Time, limit, offset int) ([]ActivityItem, error)

func GetActivityByAddress

func GetActivityByAddress(userDB *sql.DB, address string, startDate, endDate *time.Time, limit, offset int) ([]ActivityItem, error)

type AuthResponse

type AuthResponse struct {
	Success bool     `json:"success"`
	User    *User    `json:"user,omitempty"`
	Session *Session `json:"session,omitempty"`
	Error   string   `json:"error,omitempty"`
}

type CallEntry

type CallEntry struct {
	Number         string `xml:"number,attr"`
	Duration       string `xml:"duration,attr"`
	Date           string `xml:"date,attr"`
	Type           string `xml:"type,attr"`
	Presentation   string `xml:"presentation,attr"`
	SubscriptionID string `xml:"subscription_id,attr"`
	ReadableDate   string `xml:"readable_date,attr"`
	ContactName    string `xml:"contact_name,attr"`
}

type CallLog

type CallLog struct {
	ID             int64     `json:"id"`
	Number         string    `json:"number"`
	Duration       int       `json:"duration"` // in seconds
	Date           time.Time `json:"date"`
	Type           int       `json:"type"`                   // 1 = incoming, 2 = outgoing, 3 = missed, 4 = voicemail, 5 = rejected, 6 = refused
	Presentation   int       `json:"presentation,omitempty"` // 1 = allowed, 2 = restricted, 3 = unknown, 4 = payphone
	SubscriptionID string    `json:"subscription_id,omitempty"`
	ContactName    string    `json:"contact_name,omitempty"`
}

func GetAllCalls added in v0.1.3

func GetAllCalls(userDB *sql.DB, startDate, endDate *time.Time, limit, offset int) ([]CallLog, error)

func GetCallLogs

func GetCallLogs(userDB *sql.DB, number string, startDate, endDate *time.Time) ([]CallLog, error)

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword     string `json:"old_password"`
	NewPassword     string `json:"new_password"`
	ConfirmPassword string `json:"confirm_password"`
}

type Conversation

type Conversation struct {
	Address      string    `json:"address"`
	ContactName  string    `json:"contact_name,omitempty"`
	Subject      string    `json:"subject,omitempty"`
	LastMessage  string    `json:"last_message"`
	LastDate     time.Time `json:"last_date"`
	MessageCount int       `json:"message_count"`
	Type         string    `json:"type"` // "sms", "mms", or "call"
}

func GetConversations

func GetConversations(userDB *sql.DB, startDate, endDate *time.Time) ([]Conversation, error)

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type MMSAddr

type MMSAddr struct {
	Address string `xml:"address,attr"`
	Type    string `xml:"type,attr"`
	Charset string `xml:"charset,attr"`
}

type MMSEntry

type MMSEntry struct {
	Address      string    `xml:"address,attr"`
	Date         string    `xml:"date,attr"`
	Type         string    `xml:"msg_box,attr"`
	Read         string    `xml:"read,attr"`
	ThreadID     string    `xml:"thread_id,attr"`
	Subject      string    `xml:"sub,attr"`
	TrID         string    `xml:"tr_id,attr"`
	ContentType  string    `xml:"ct_t,attr"`
	ReadReport   string    `xml:"rr,attr"`
	ReadStatus   string    `xml:"read_status,attr"`
	MessageID    string    `xml:"m_id,attr"`
	MessageSize  string    `xml:"m_size,attr"`
	MessageType  string    `xml:"m_type,attr"`
	SimSlot      string    `xml:"sim_slot,attr"`
	ReadableDate string    `xml:"readable_date,attr"`
	ContactName  string    `xml:"contact_name,attr"`
	Parts        []MMSPart `xml:"parts>part"`
	Addrs        []MMSAddr `xml:"addrs>addr"`
	Body         string    `xml:"body,attr"`
}

type MMSPart

type MMSPart struct {
	Seq         string `xml:"seq,attr"`
	ContentType string `xml:"ct,attr"`
	Name        string `xml:"name,attr"`
	Charset     string `xml:"chset,attr"`
	CL          string `xml:"cl,attr"`
	Text        string `xml:"text,attr"`
	Data        string `xml:"data,attr"`
}

type Message

type Message struct {
	ID          int64     `json:"id"`
	Address     string    `json:"address"`
	Body        string    `json:"body"`
	Type        int       `json:"type"` // 1 = received, 2 = sent, 3 = draft, 4 = outbox, 5 = failed, 6 = queued
	Date        time.Time `json:"date"`
	Read        bool      `json:"read"`
	ThreadID    int       `json:"thread_id"`
	Subject     string    `json:"subject,omitempty"`
	MediaType   string    `json:"media_type,omitempty"`
	MediaData   []byte    `json:"-"`
	MediaBase64 string    `json:"media_base64,omitempty"`
	// Additional SMS fields
	Protocol      int    `json:"protocol,omitempty"`
	Status        int    `json:"status,omitempty"` // -1 = none, 0 = complete, 32 = pending, 64 = failed
	ServiceCenter string `json:"service_center,omitempty"`
	SubID         int    `json:"sub_id,omitempty"`
	ContactName   string `json:"contact_name,omitempty"`
	Sender        string `json:"sender,omitempty"` // Sender phone number for received messages
	// Additional MMS fields
	ContentType string   `json:"content_type,omitempty"` // ct_t field
	ReadReport  int      `json:"read_report,omitempty"`  // rr field
	ReadStatus  int      `json:"read_status,omitempty"`
	MessageID   string   `json:"message_id,omitempty"`   // m_id field
	MessageSize int      `json:"message_size,omitempty"` // m_size field
	MessageType int      `json:"message_type,omitempty"` // m_type field
	SimSlot     int      `json:"sim_slot,omitempty"`
	Addresses   []string `json:"addresses,omitempty"` // All phone numbers in conversation (for MMS)
}

func GetMessages

func GetMessages(userDB *sql.DB, address string, startDate, endDate *time.Time) ([]Message, error)

type ParseResult

type ParseResult struct {
	Messages []Message
	Calls    []CallLog
}

func ParseSMSBackup

func ParseSMSBackup(r io.Reader) (ParseResult, error)

type RegisterRequest

type RegisterRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type SMSBackup

type SMSBackup struct {
	XMLName  xml.Name    `xml:"smses"`
	Count    int         `xml:"count,attr"`
	Messages []SMSEntry  `xml:"sms"`
	MMS      []MMSEntry  `xml:"mms"`
	Calls    []CallEntry `xml:"call"`
}

type SMSEntry

type SMSEntry struct {
	Address       string `xml:"address,attr"`
	Date          string `xml:"date,attr"`
	Type          string `xml:"type,attr"`
	Body          string `xml:"body,attr"`
	Read          string `xml:"read,attr"`
	ThreadID      string `xml:"thread_id,attr"`
	Subject       string `xml:"subject,attr"`
	Protocol      string `xml:"protocol,attr"`
	TOA           string `xml:"toa,attr"`
	SCTOA         string `xml:"sc_toa,attr"`
	ServiceCenter string `xml:"service_center,attr"`
	Status        string `xml:"status,attr"`
	SubID         string `xml:"sub_id,attr"`
	ReadableDate  string `xml:"readable_date,attr"`
	ContactName   string `xml:"contact_name,attr"`
}

type SearchResult

type SearchResult struct {
	MessageID   int64     `json:"message_id"`
	Address     string    `json:"address"`
	ContactName string    `json:"contact_name"`
	Body        string    `json:"body"`
	Date        time.Time `json:"date"`
	Snippet     string    `json:"snippet"`
}

SearchResult represents a message search result

func SearchMessages

func SearchMessages(userDB *sql.DB, query string, limit int) ([]SearchResult, error)

SearchMessages performs full-text search on message contents

type Session

type Session struct {
	ID        string    `json:"id"`
	UserID    string    `json:"user_id"`
	Username  string    `json:"username"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at"`
}

func CreateSession

func CreateSession(userID string, username string) (*Session, error)

CreateSession creates a new session for a user

func GetSession

func GetSession(sessionID string) (*Session, error)

GetSession retrieves a session by ID

type UploadProgress

type UploadProgress struct {
	TotalMessages     int       `json:"total_messages"`
	ProcessedMessages int       `json:"processed_messages"`
	TotalCalls        int       `json:"total_calls"`
	ProcessedCalls    int       `json:"processed_calls"`
	Status            string    `json:"status"` // "parsing", "importing", "completed", "error"
	ErrorMessage      string    `json:"error_message,omitempty"`
	StartTime         time.Time `json:"start_time"`
	// contains filtered or unexported fields
}

UploadProgress tracks the progress of an ongoing upload

func GetUploadProgress

func GetUploadProgress() *UploadProgress

GetUploadProgress returns the current upload progress

type UploadResponse

type UploadResponse struct {
	Success      bool   `json:"success"`
	MessageCount int    `json:"message_count"`
	CallLogCount int    `json:"call_log_count"`
	Processing   bool   `json:"processing,omitempty"`
	Error        string `json:"error,omitempty"`
}

type User

type User struct {
	ID           string    `json:"id"`
	Username     string    `json:"username"`
	PasswordHash string    `json:"-"` // Never send password hash to client
	CreatedAt    time.Time `json:"created_at"`
}

func CreateUser

func CreateUser(username, password string) (*User, error)

CreateUser creates a new user with hashed password

func GetUserByUsername

func GetUserByUsername(username string) (*User, error)

GetUserByUsername retrieves a user by username

Jump to

Keyboard shortcuts

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