Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
60
cloud/maplefile-backend/cmd/daemon.go
Normal file
60
cloud/maplefile-backend/cmd/daemon.go
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/app"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
)
|
||||
|
||||
// formatBuildTime converts ISO 8601 timestamp to human-readable 12-hour format
|
||||
func formatBuildTime(isoTime string) string {
|
||||
t, err := time.Parse(time.RFC3339, isoTime)
|
||||
if err != nil {
|
||||
return isoTime // Return original if parsing fails
|
||||
}
|
||||
return t.Format("Jan 2, 2006 3:04:05 PM MST")
|
||||
}
|
||||
|
||||
var daemonCmd = &cobra.Command{
|
||||
Use: "daemon",
|
||||
Short: "Start the MapleFile backend server",
|
||||
Long: `Start the MapleFile backend HTTP server and listen for requests.`,
|
||||
Run: runDaemon,
|
||||
}
|
||||
|
||||
func runDaemon(cmd *cobra.Command, args []string) {
|
||||
// Validate configuration on startup
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
}
|
||||
|
||||
if err := cfg.Validate(); err != nil {
|
||||
log.Fatalf("Invalid configuration: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("🚀 Starting MapleFile Backend v%s\n", version)
|
||||
fmt.Printf("📝 Git Commit: %s\n", gitCommit)
|
||||
fmt.Printf("🕐 Build Time: %s\n", formatBuildTime(buildTime))
|
||||
fmt.Printf("📝 Environment: %s\n", cfg.App.Environment)
|
||||
fmt.Printf("🌐 Server will listen on %s:%d\n", cfg.Server.Host, cfg.Server.Port)
|
||||
|
||||
// Create and run the Wire-based application
|
||||
application, err := app.InitializeApplication(cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize application: %v", err)
|
||||
}
|
||||
|
||||
// Start the application
|
||||
// Wire application handles lifecycle and graceful shutdown
|
||||
if err := application.Start(); err != nil {
|
||||
log.Fatalf("Application terminated with error: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("👋 Server stopped gracefully")
|
||||
}
|
||||
54
cloud/maplefile-backend/cmd/migrate.go
Normal file
54
cloud/maplefile-backend/cmd/migrate.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var migrateCmd = &cobra.Command{
|
||||
Use: "migrate",
|
||||
Short: "Database migration commands",
|
||||
Long: `Run database migrations up, down, or create new migrations.`,
|
||||
}
|
||||
|
||||
var migrateUpCmd = &cobra.Command{
|
||||
Use: "up",
|
||||
Short: "Run migrations up",
|
||||
Long: `Apply all pending database migrations.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("Running migrations up...")
|
||||
// TODO: Implement migration logic in Phase 4
|
||||
fmt.Println("✅ Migrations completed")
|
||||
},
|
||||
}
|
||||
|
||||
var migrateDownCmd = &cobra.Command{
|
||||
Use: "down",
|
||||
Short: "Run migrations down",
|
||||
Long: `Rollback the last database migration.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("Running migrations down...")
|
||||
// TODO: Implement migration logic in Phase 4
|
||||
fmt.Println("✅ Migration rolled back")
|
||||
},
|
||||
}
|
||||
|
||||
var migrateCreateCmd = &cobra.Command{
|
||||
Use: "create [name]",
|
||||
Short: "Create a new migration file",
|
||||
Long: `Create a new migration file with the given name.`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
name := args[0]
|
||||
fmt.Printf("Creating migration: %s\n", name)
|
||||
// TODO: Implement migration creation in Phase 4
|
||||
fmt.Println("✅ Migration files created")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
migrateCmd.AddCommand(migrateUpCmd)
|
||||
migrateCmd.AddCommand(migrateDownCmd)
|
||||
migrateCmd.AddCommand(migrateCreateCmd)
|
||||
}
|
||||
92
cloud/maplefile-backend/cmd/recalculate_file_counts.go
Normal file
92
cloud/maplefile-backend/cmd/recalculate_file_counts.go
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/repo/collection"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/pkg/storage/database/cassandradb"
|
||||
)
|
||||
|
||||
var recalculateFileCountsCmd = &cobra.Command{
|
||||
Use: "recalculate-file-counts",
|
||||
Short: "Recalculate file counts for all collections",
|
||||
Long: `Recalculates the file_count field for all collections by counting
|
||||
the actual number of active files in each collection.
|
||||
|
||||
This command is useful for:
|
||||
- Fixing collections created before file count tracking was implemented
|
||||
- Repairing file counts that may have become out of sync
|
||||
- Data migration and maintenance tasks
|
||||
|
||||
Example:
|
||||
maplefile-backend recalculate-file-counts`,
|
||||
Run: runRecalculateFileCounts,
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(recalculateFileCountsCmd)
|
||||
}
|
||||
|
||||
func runRecalculateFileCounts(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("🔧 Recalculating file counts for all collections...")
|
||||
|
||||
// Load configuration
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
}
|
||||
|
||||
// Create logger
|
||||
logger, err := zap.NewProduction()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create logger: %v", err)
|
||||
}
|
||||
defer logger.Sync()
|
||||
|
||||
// Connect to Cassandra
|
||||
fmt.Println("📦 Connecting to database...")
|
||||
session, err := cassandradb.NewCassandraConnection(cfg, logger)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to connect to Cassandra: %v", err)
|
||||
}
|
||||
defer session.Close()
|
||||
|
||||
// Create collection repository
|
||||
collectionRepo := collection.NewRepository(cfg, session, logger)
|
||||
|
||||
// Create context with timeout
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
|
||||
defer cancel()
|
||||
|
||||
// Run recalculation
|
||||
fmt.Println("🔄 Starting recalculation...")
|
||||
startTime := time.Now()
|
||||
|
||||
result, err := collectionRepo.RecalculateAllFileCounts(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to recalculate file counts: %v", err)
|
||||
}
|
||||
|
||||
duration := time.Since(startTime)
|
||||
|
||||
// Print results
|
||||
fmt.Println("")
|
||||
fmt.Println("✅ Recalculation completed!")
|
||||
fmt.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
fmt.Printf(" Total collections: %d\n", result.TotalCollections)
|
||||
fmt.Printf(" Updated: %d\n", result.UpdatedCount)
|
||||
fmt.Printf(" Errors: %d\n", result.ErrorCount)
|
||||
fmt.Printf(" Duration: %s\n", duration.Round(time.Millisecond))
|
||||
fmt.Println("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
||||
|
||||
if result.ErrorCount > 0 {
|
||||
fmt.Println("⚠️ Some collections had errors. Check the logs for details.")
|
||||
}
|
||||
}
|
||||
28
cloud/maplefile-backend/cmd/root.go
Normal file
28
cloud/maplefile-backend/cmd/root.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "maplefile-backend",
|
||||
Short: "MapleFile Backend Server",
|
||||
Long: `MapleFile - Standalone encrypted file storage backend server.`,
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Add subcommands
|
||||
rootCmd.AddCommand(daemonCmd)
|
||||
rootCmd.AddCommand(migrateCmd)
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
37
cloud/maplefile-backend/cmd/version.go
Normal file
37
cloud/maplefile-backend/cmd/version.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// Build information set at compile time
|
||||
var (
|
||||
version = "1.0.0"
|
||||
gitCommit = "unknown"
|
||||
buildTime = "unknown"
|
||||
)
|
||||
|
||||
// SetBuildInfo sets the build information from main package
|
||||
func SetBuildInfo(v, commit, time string) {
|
||||
version = v
|
||||
gitCommit = commit
|
||||
buildTime = time
|
||||
}
|
||||
|
||||
// GetBuildInfo returns the current build information
|
||||
func GetBuildInfo() (string, string, string) {
|
||||
return version, gitCommit, buildTime
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version number",
|
||||
Long: `Print the version number of MapleFile backend.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Printf("MapleFile Backend v%s\n", version)
|
||||
fmt.Printf("Git Commit: %s\n", gitCommit)
|
||||
fmt.Printf("Build Time: %s\n", buildTime)
|
||||
},
|
||||
}
|
||||
32
cloud/maplefile-backend/cmd/wire-test/main.go
Normal file
32
cloud/maplefile-backend/cmd/wire-test/main.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/app"
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/config"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Load configuration
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Initialize application using Wire
|
||||
application, err := app.InitializeApplication(cfg)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize application: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Start the application
|
||||
log.Println("Starting MapleFile Backend with Wire DI...")
|
||||
if err := application.Start(); err != nil {
|
||||
log.Fatalf("Application failed: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue