manul sync backend works now

This commit is contained in:
Sticks
2025-05-20 13:01:02 -04:00
parent 7aa2dee280
commit 96abb94f21
9 changed files with 397 additions and 147 deletions

42
app.go
View File

@ -5,7 +5,6 @@ import (
"FanslySync/structs"
"FanslySync/utils"
"context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/logger"
"github.com/wailsapp/wails/v2/pkg/runtime"
@ -16,7 +15,6 @@ type App struct {
ctx context.Context
ConfigManager handlers.ConfigManager
AppConfig *structs.Config
Logger logger.Logger
}
// NewApp creates a new App application struct
@ -40,10 +38,20 @@ func (a *App) startup(ctx context.Context, logger logger.Logger) {
}
// Create our config manager
a.ConfigManager = handlers.NewFileConfigManager(configPath, logger)
a.Logger = logger
configMgr, configMgrCreateErr := handlers.NewFileConfigManager(configPath)
logger.Info("[startup] initializing FanslySync...")
if configMgrCreateErr != nil {
// Show message box and quit
utils.ShowMessageBox(a.ctx, "FanslySync | Initialization Error", "Could not create config manager.\n\nError: "+configMgrCreateErr.Error(), utils.WithDialogType(runtime.ErrorDialog))
runtime.Quit(a.ctx)
return
}
// Set the config manager
a.ConfigManager = configMgr
logger.Info("initializing FanslySync...")
// Check our config path to see if it was set correctly. Will not contain FailedConfigPathFetch
// Do we have an old config file?
@ -56,7 +64,7 @@ func (a *App) startup(ctx context.Context, logger logger.Logger) {
}
if shouldMigrate {
logger.Info("[startup] migrating old config file...")
logger.Info("migrating old config file...")
// Migrate the old config file
err := a.ConfigManager.MigrateOldAppConfig()
if err != nil {
@ -66,7 +74,7 @@ func (a *App) startup(ctx context.Context, logger logger.Logger) {
return
} else {
// Show success message
logger.Info("[startup] old config file migrate ok")
logger.Info("old config file migrate ok")
utils.ShowMessageBox(a.ctx, "FanslySync | Notice", "We've detected an old config file (app version < 2.x and below).\n\nThe old config file has been migrated to the new format for you automatically, and the old config file has been deleted.\n\nPlease check your settings to ensure everything is correct.", utils.WithDialogType(runtime.InfoDialog))
// Now grab the new config
@ -82,7 +90,7 @@ func (a *App) startup(ctx context.Context, logger logger.Logger) {
}
} else {
// Load config as normal
logger.Info("[startup] loading config file...")
logger.Info("loading config file...")
cfg, err := a.ConfigManager.LoadConfigOrCreate()
if err != nil {
// Show the error in a message box
@ -91,26 +99,24 @@ func (a *App) startup(ctx context.Context, logger logger.Logger) {
}
// Set the config
logger.Info("[startup] config file loaded ok")
logger.Info("config file loaded ok")
a.AppConfig = cfg
}
logger.Info("FanslySync initialized successfully")
}
// Greet returns a greeting for the given name
func (a *App) Greet(token string) string {
// Create fansly API instance
fanslyAPI := handlers.NewFanslyAPIController(token, a.Logger)
fanslyAPI, createErr := handlers.NewFanslyAPIController(token)
// Get the user info
account, accountErr := fanslyAPI.GetMe()
if accountErr != nil {
return "Failed to get account info: " + accountErr.Error()
if createErr != nil {
return "Failed to create Fansly API instance: " + createErr.Error()
}
// Print the response we got
a.Logger.Info(fmt.Sprintf("[Greet] Account info: %+v", account))
// Sync
fanslyAPI.Sync(a.ctx, token, false)
// Return the greeting
return fmt.Sprintf("Hello %s! You have %d fans and %d posts likes.", account.Username, account.FollowCount, account.PostLikes)
return "Sync dispatched, check the logs for more info."
}