Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions cmd/lite/lite.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ var rootCmd = &cobra.Command{
Database: viper.GetString("clickhouse-database"),
}

clickhouse.AutoMigrate(cmd.Context(), chConfig)
clickhouseClient := clickhouse.NewClient(chConfig)
clickhouseEnabled := shouldInitClickhouse(chConfig.Host)
if clickhouseEnabled {
clickhouse.AutoMigrate(cmd.Context(), chConfig)
}

clickhouseClient := clickhouse.NewClient(chConfig, clickhouseEnabled)

s3Provider := viper.GetString("s3-provider")
storageLayer := storage.New(s3Provider)
Expand Down Expand Up @@ -215,15 +219,19 @@ func init() {
)
}

func main() {
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}

func bindError(err error) {
if err != nil {
slog.Error("failed to bind env", slog.Any("error", err))
os.Exit(1)
}
}

func shouldInitClickhouse(clickhouseHost string) bool {
return clickhouseHost != ""
}

func main() {
if err := rootCmd.Execute(); err != nil {
panic(err)
}
}
17 changes: 14 additions & 3 deletions internal/clickhouse/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"log/slog"
"time"

"github.com/ClickHouse/clickhouse-go/v2"
Expand All @@ -18,7 +19,8 @@ type Config struct {
}

type Client struct {
conn driver.Conn
conn driver.Conn
Enabled bool
}

type Log struct {
Expand All @@ -36,8 +38,17 @@ type LogField struct {
Type string
}

func NewClient(config *Config) *Client {
c := &Client{}
func NewClient(config *Config, enabled bool) *Client {
if !enabled {
slog.Warn("clickhosue is disabled, logging is not available")
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'clickhosue' to 'clickhouse'.

Suggested change
slog.Warn("clickhosue is disabled, logging is not available")
slog.Warn("clickhouse is disabled, logging is not available")

Copilot uses AI. Check for mistakes.
return &Client{
Enabled: false,
}
}

c := &Client{
Enabled: true,
}

options := getClickhouseOptions(config)
conn, err := connect(options)
Expand Down
3 changes: 1 addition & 2 deletions internal/http/httputil/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ func GetMimeDetails(fileHeader *multipart.FileHeader, file multipart.File) (stri
var err error
var fileType string

// Get the file type from the header
buf := make([]byte, fileHeader.Size)
buf := make([]byte, 3072)
_, err = file.Read(buf)
if err != nil {
return "", "", "", fmt.Errorf("error reading file: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions internal/http/middleware/mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ func ValidateMime(fileKey string, whitelistedTypes []string) echo.MiddlewareFunc
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(ctx echo.Context) error {
var err error
file, header, err := httputil.File(ctx.Request(), fileKey)
file, _, err := httputil.File(ctx.Request(), fileKey)
if err != nil {
fmt.Printf("Failed to fine formdata file. Error: %v\n", err)
fmt.Printf("Failed to find FormData file. Error: %v\n", err)
return ctx.JSON(http.StatusBadRequest, echo.Map{
"error": err.Error(),
})
}

buf := make([]byte, header.Size)
buf := make([]byte, 3072)
_, err = file.Read(buf)
if err != nil {
fmt.Printf("Failed to read buffer. Error: %v\n", err)
Expand Down
2 changes: 2 additions & 0 deletions internal/service/file/file_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func NewService(db *bun.DB, storageLayer storage.StorageLayer) *Service {
}
}

// this is used in the public api only
func (s *Service) CreateFile(
ctx context.Context,
organizationID string,
Expand Down Expand Up @@ -103,6 +104,7 @@ func (s *Service) CreateFile(
return nil
}

// uhhh, this is used in the dashboard, not the public api
func (s *Service) CreateStorageFile(
ctx context.Context,
organizationID string,
Expand Down
Loading