services

package
v0.0.0-...-17c6d09 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCodeImage

func GenerateCodeImage(code string) ([]byte, error)

func GenerateCodeImageWithConfig

func GenerateCodeImageWithConfig(code, language string, config ImageConfig) (image.Image, error)

func HdurDurationConverter

func HdurDurationConverter(value string) reflect.Value

Types

type APIKeyRequest

type APIKeyRequest struct {
	Email string `json:"email" xml:"email" form:"email"`
	Name  string `json:"name" xml:"name" form:"name"`
}

APIKeyRequest represents the request structure for creating an API key

type APIKeyResponse

type APIKeyResponse struct {
	Message string `json:"message" xml:"message" form:"message"`
}

APIKeyResponse represents the response sent after an API key is requested

type APIKeyService

type APIKeyService struct {
	// contains filtered or unexported fields
}

func NewAPIKeyService

func NewAPIKeyService(db *gorm.DB, logger *zap.Logger, config *config.Config) *APIKeyService

func (*APIKeyService) CleanupUnverifiedKeys

func (s *APIKeyService) CleanupUnverifiedKeys() int64

CleanupUnverifiedKeys removes unverified API keys older than 24 hours

func (*APIKeyService) HasMailer

func (s *APIKeyService) HasMailer() bool

func (*APIKeyService) RequestKey

func (s *APIKeyService) RequestKey(c *fiber.Ctx) error

RequestKey handles the initial API key request

func (*APIKeyService) VerifyKey

func (s *APIKeyService) VerifyKey(c *fiber.Ctx) error

VerifyKey verifies the email and activates the API key

type AnalyticsService

type AnalyticsService struct {
	// contains filtered or unexported fields
}

func NewAnalyticsService

func NewAnalyticsService(db *gorm.DB, logger *zap.Logger, config *config.Config) *AnalyticsService

func (*AnalyticsService) GetResourceStats

func (s *AnalyticsService) GetResourceStats(resourceType string, resourceID string, timeframe AnalyticsTimeframe) (*AnalyticsStats, error)

GetResourceStats retrieves analytics statistics for a given resource

func (*AnalyticsService) GetStatsHistory

func (s *AnalyticsService) GetStatsHistory(days int) (*StatsHistory, error)

GetStatsHistory generates usage statistics for the specified number of days

func (*AnalyticsService) LogEvent

func (s *AnalyticsService) LogEvent(c *fiber.Ctx, eventType models.EventType, resourceType string, resourceID string) error

LogEvent creates a new analytics event with common request information

func (*AnalyticsService) LogPasteView

func (s *AnalyticsService) LogPasteView(c *fiber.Ctx, pasteID string) error

LogPasteView creates an analytics event for paste views

func (*AnalyticsService) LogShortlinkClick

func (s *AnalyticsService) LogShortlinkClick(c *fiber.Ctx, shortlinkID string) error

LogShortlinkClick creates an analytics event for shortlink clicks

type AnalyticsStats

type AnalyticsStats struct {
	TotalViews   int64            `json:"total_views"`
	UniqueViews  int64            `json:"unique_views"`
	ViewsByDay   []ChartDataPoint `json:"views_by_day"`
	TopReferrers map[string]int64 `json:"top_referrers"`
	TopCountries map[string]int64 `json:"top_countries"`
	TopBrowsers  map[string]int64 `json:"top_browsers"`
}

AnalyticsStats contains aggregated statistics for a resource

type AnalyticsTimeframe

type AnalyticsTimeframe struct {
	StartTime *time.Time
	EndTime   *time.Time
}

AnalyticsTimeframe represents a time period for analytics queries

type ChartDataPoint

type ChartDataPoint struct {
	Value any       `json:"value" xml:"value" form:"value"` // The value at this point (can be number or string)
	Date  time.Time `json:"date" xml:"date" form:"date"`    // The timestamp for this data point
}

ChartDataPoint represents a single point of data in time-series statistics

type CleanupService

type CleanupService struct {
	// contains filtered or unexported fields
}

func NewCleanupService

func NewCleanupService(db *gorm.DB, logger *zap.Logger, config *config.Config, services *Services) *CleanupService

func (*CleanupService) RunCleanup

func (s *CleanupService) RunCleanup()

RunCleanup performs all cleanup tasks

func (*CleanupService) StartCleanupScheduler

func (s *CleanupService) StartCleanupScheduler(interval time.Duration)

StartCleanupScheduler starts a periodic cleanup task

type ExpiryOptions

type ExpiryOptions struct {
	Size      int64
	HasAPIKey bool
	ExpiresAt *time.Time
	ExpiresIn *hdur.Duration
}

ExpiryOptions contains parameters for calculating paste expiration

type ImageConfig

type ImageConfig struct {
	Width        int
	Height       int
	MaxLines     int
	FontSize     float64
	LineSpacing  float64
	Padding      float64
	BorderWidth  float64
	BorderRadius float64
	FontPath     string
	Watermark    WatermarkConfig
}

ImageConfig holds all configuration for image generation

func DefaultImageConfig

func DefaultImageConfig() ImageConfig

DefaultImageConfig returns the default image configuration

type ListPastesResponse

type ListPastesResponse struct {
	Pastes []PasteResponse `json:"pastes"`
	Total  int64           `json:"total"`
	Page   int             `json:"page"`
	Limit  int             `json:"limit"`
}

ListPastesResponse represents the response structure for listing pastes

func NewListPastesResponse

func NewListPastesResponse(pastes []models.Paste, baseURL string) ListPastesResponse

NewListPastesResponse creates a new ListPastesResponse from a list of pastes

type PasteOptions

type PasteOptions struct {
	Content   string         `json:"content" xml:"content" form:"content"`          // Content to be pasted
	Extension string         `json:"extension" xml:"extension" form:"extension"`    // File extension (optional)
	Private   bool           `json:"private" xml:"private" form:"private"`          // Whether the paste is private
	Filename  string         `json:"filename" xml:"filename" form:"filename"`       // Original filename
	APIKey    *models.APIKey `json:"api_key" xml:"api_key" form:"api_key"`          // Associated API key for authentication
	URL       string         `json:"url" xml:"url" form:"url"`                      // URL to be pasted
	ExpiresIn *hdur.Duration `json:"expires_in" xml:"expires_in" form:"expires_in"` // Duration string for paste expiry (e.g. "24h")
	ExpiresAt *time.Time     `json:"expires_at" xml:"expires_at" form:"expires_at"` // Expiration time for the paste
}

PasteOptions contains configuration options for creating a new paste

type PasteResponse

type PasteResponse struct {
	ID        string     `json:"id" xml:"id" form:"id"`
	Filename  string     `json:"filename" xml:"filename" form:"filename"`
	URL       string     `json:"url" xml:"url" form:"url"`
	DeleteURL string     `json:"delete_url" xml:"delete_url" form:"delete_url"`
	MimeType  string     `json:"mime_type" xml:"mime_type" form:"mime_type"`
	Size      int64      `json:"size" xml:"size" form:"size"`
	ExpiresAt *time.Time `json:"expires_at" xml:"expires_at" form:"expires_at"`
	Private   bool       `json:"private" xml:"private" form:"private"`
}

PasteResponse represents the response structure for creating a new paste

func NewPasteResponse

func NewPasteResponse(paste *models.Paste, baseURL string) PasteResponse

NewPasteResponse creates a new PasteResponse from a paste

type PasteService

type PasteService struct {
	// contains filtered or unexported fields
}

func NewPasteService

func NewPasteService(db *gorm.DB, logger *zap.Logger, config *config.Config) *PasteService

func (*PasteService) CleanupExpired

func (s *PasteService) CleanupExpired() (int64, error)

CleanupExpired removes expired pastes and their associated files

func (*PasteService) Delete

func (s *PasteService) Delete(c *fiber.Ctx, id string) error

Delete removes a paste and its associated files

func (*PasteService) DeleteWithKey

func (s *PasteService) DeleteWithKey(c *fiber.Ctx, id string) error

DeleteWithKey deletes a paste using its deletion key

func (*PasteService) GetPaste

func (s *PasteService) GetPaste(id string) (*models.Paste, error)

GetPaste retrieves a paste by ID with expiry checking

func (*PasteService) GetPasteImage

func (s *PasteService) GetPasteImage(c *fiber.Ctx, paste *models.Paste) error

GetPasteImage returns an image of the paste suitable for Open Graph

func (*PasteService) ListPastes

func (s *PasteService) ListPastes(c *fiber.Ctx) error

ListPastes returns a paginated list of pastes for the API key

func (*PasteService) RenderDownload

func (s *PasteService) RenderDownload(c *fiber.Ctx, paste *models.Paste) error

RenderDownload serves the content as a downloadable file

func (*PasteService) RenderPaste

func (s *PasteService) RenderPaste(c *fiber.Ctx, paste *models.Paste) error

RenderPaste renders the paste view for text content

func (*PasteService) RenderPasteJSON

func (s *PasteService) RenderPasteJSON(c *fiber.Ctx, paste *models.Paste) error

RenderPasteJSON serves the paste as JSON. If the paste is text, the content will be included in the response. Otherwise only the URL will be included for downloading purposes.

func (*PasteService) RenderPasteRaw

func (s *PasteService) RenderPasteRaw(c *fiber.Ctx, paste *models.Paste) error

RenderPasteRaw serves the raw content with proper content type

func (*PasteService) UpdateExpiration

func (s *PasteService) UpdateExpiration(c *fiber.Ctx, id string) error

UpdateExpiration updates a paste's expiration time

func (*PasteService) UploadPaste

func (s *PasteService) UploadPaste(c *fiber.Ctx) error

CreatePaste handles the creation of a new paste

type RequestParser

type RequestParser struct {
	// contains filtered or unexported fields
}

RequestParser handles unified request parsing for different content types

func NewRequestParser

func NewRequestParser(c *fiber.Ctx) *RequestParser

NewRequestParser creates a new RequestParser instance

func (*RequestParser) ParseJSON

func (p *RequestParser) ParseJSON(out interface{}) error

ParseJSON attempts to parse the request body as JSON into the provided struct

func (*RequestParser) ParseUploadRequest

func (p *RequestParser) ParseUploadRequest() (*UploadRequest, error)

ParseUploadRequest parses various types of upload requests into a unified format

type Services

type Services struct {
	Paste     *PasteService
	URL       *URLService
	APIKey    *APIKeyService
	Analytics *AnalyticsService
	Stats     *StatsService
	Cleanup   *CleanupService
}

Services holds all service instances

func NewServices

func NewServices(db *gorm.DB, logger *zap.Logger, config *config.Config) *Services

NewServices creates a new Services instance with all service dependencies

func (*Services) StartCleanupScheduler

func (s *Services) StartCleanupScheduler(interval string) error

StartCleanupScheduler starts the cleanup scheduler with the configured interval

type ShortlinkOptions

type ShortlinkOptions struct {
	URL       string         `json:"url" xml:"url" form:"url"`                      // URL to be shortened
	Title     string         `json:"title" xml:"title" form:"title"`                // Display title for the shortlink
	ExpiresIn *hdur.Duration `json:"expires_in" xml:"expires_in" form:"expires_in"` // Duration string for shortlink expiry (e.g. "24h")
}

ShortlinkOptions contains configuration options for creating a new shortlink

type ShortlinkResponse

type ShortlinkResponse struct {
	ID        string `json:"id" xml:"id" form:"id"`
	URL       string `json:"url" xml:"url" form:"url"`
	Title     string `json:"title" xml:"title" form:"title"`
	ShortURL  string `json:"short_url" xml:"short_url" form:"short_url"`
	StatsURL  string `json:"stats_url" xml:"stats_url" form:"stats_url"`
	DeleteURL string `json:"delete_url" xml:"delete_url" form:"delete_url"`
}

ShortlinkResponse represents the response structure for creating a new shortlink

type StatsHistory

type StatsHistory struct {
	Pastes     []ChartDataPoint
	URLs       []ChartDataPoint
	Storage    []ChartDataPoint
	AvgSize    []ChartDataPoint
	APIKeys    []ChartDataPoint
	Extensions []ChartDataPoint // Top extensions per day
	ErrorRates []ChartDataPoint // If we add error tracking
}

StatsHistory contains time-series data for system statistics

type StatsService

type StatsService struct {
	// contains filtered or unexported fields
}

func NewStatsService

func NewStatsService(db *gorm.DB, logger *zap.Logger, config *config.Config) *StatsService

func (*StatsService) GetSystemStats

func (s *StatsService) GetSystemStats() (fiber.Map, error)

GetSystemStats returns current system statistics and historical data

type URLService

type URLService struct {
	// contains filtered or unexported fields
}

func NewURLService

func NewURLService(db *gorm.DB, logger *zap.Logger, config *config.Config) *URLService

func (*URLService) CleanupExpired

func (s *URLService) CleanupExpired() (int64, error)

CleanupExpired removes expired shortlinks

func (s *URLService) CreateShortlink(c *fiber.Ctx) error

CreateShortlink creates a new URL shortlink

func (*URLService) Delete

func (s *URLService) Delete(c *fiber.Ctx) error

Delete deletes a URL (requires API key ownership)

func (s *URLService) FindShortlink(id string) (*models.Shortlink, error)

FindShortlink retrieves a shortlink by ID with expiry checking

func (*URLService) GetStats

func (s *URLService) GetStats(c *fiber.Ctx) error

GetStats returns statistics for a shortened URL

func (*URLService) ListURLs

func (s *URLService) ListURLs(c *fiber.Ctx) error

ListURLs returns a paginated list of URLs for the API key

func (*URLService) UpdateExpiration

func (s *URLService) UpdateExpiration(c *fiber.Ctx) error

UpdateExpiration updates a URL's expiration time

type UpdatePasteExpirationRequest

type UpdatePasteExpirationRequest struct {
	ExpiresIn *hdur.Duration `json:"expires_in" xml:"expires_in" form:"expires_in"` // Duration string for paste expiry (e.g. "24h")
	ExpiresAt *time.Time     `json:"expires_at" xml:"expires_at" form:"expires_at"` // Expiration time for the paste
}

UpdatePasteExpirationRequest represents the request structure for updating a paste's expiration time

type UploadRequest

type UploadRequest struct {
	Content     []byte // Raw content bytes
	Filename    string // Original filename
	Extension   string // File extension
	ExpiresIn   string // Expiration duration
	Private     bool   // Privacy flag
	ContentType string // MIME type
	URL         string // Optional URL for URL-based uploads
}

UploadRequest represents a unified structure for all upload types

type WatermarkConfig

type WatermarkConfig struct {
	Enabled  bool
	Text     string
	FontSize float64
	Color    color.Color
	PaddingX float64
	PaddingY float64
	FontPath string
}

WatermarkConfig holds configuration for the image watermark

func DefaultWatermarkConfig

func DefaultWatermarkConfig() WatermarkConfig

DefaultWatermarkConfig returns the default watermark configuration

Jump to

Keyboard shortcuts

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