package components import ( "fmt" "github.com/starfleetcptn/gomft/internal/db" "context" ) type ConfigFormData struct { Config *db.TransferConfig IsNew bool } func getConfigFormTitle(isNew bool) string { if isNew { return "New Configuration" } return "Edit Configuration" } func getInitialData(config *db.TransferConfig) string { name := "" sourceType := "local" sourcePath := "" sourceHost := "" sourcePort := 22 sourceUser := "" sourcePassword := "" sourceKeyFile := "" // S3 fields sourceBucket := "" sourceRegion := "" sourceAccessKey := "" sourceSecretKey := "" sourceEndpoint := "" // SMB fields sourceShare := "" sourceDomain := "" // FTP fields sourcePassiveMode := true // OneDrive and Google Drive fields sourceClientId := "" sourceClientSecret := "" sourceDriveId := "" sourceTeamDrive := "" filePattern := "*" outputPattern := "" destinationType := "local" destinationPath := "" destHost := "" destPort := 22 destUser := "" destPassword := "" destKeyFile := "" // S3 fields destBucket := "" destRegion := "" destAccessKey := "" destSecretKey := "" destEndpoint := "" // SMB fields destShare := "" destDomain := "" // FTP fields destPassiveMode := true // OneDrive and Google Drive fields destClientId := "" destClientSecret := "" destDriveId := "" destTeamDrive := "" archivePath := "" archiveEnabled := false deleteAfterTransfer := false rcloneFlags := "" if config != nil { name = config.Name sourceType = config.SourceType sourcePath = config.SourcePath sourceHost = config.SourceHost sourcePort = config.SourcePort sourceUser = config.SourceUser sourcePassword = config.SourcePassword sourceKeyFile = config.SourceKeyFile // S3 fields sourceBucket = config.SourceBucket sourceRegion = config.SourceRegion sourceAccessKey = config.SourceAccessKey sourceSecretKey = config.SourceSecretKey sourceEndpoint = config.SourceEndpoint // SMB fields sourceShare = config.SourceShare sourceDomain = config.SourceDomain // FTP fields sourcePassiveMode = config.SourcePassiveMode // OneDrive and Google Drive fields sourceClientId = config.SourceClientID sourceClientSecret = config.SourceClientSecret sourceDriveId = config.SourceDriveID sourceTeamDrive = config.SourceTeamDrive filePattern = config.FilePattern outputPattern = config.OutputPattern destinationType = config.DestinationType destinationPath = config.DestinationPath destHost = config.DestHost destPort = config.DestPort destUser = config.DestUser destPassword = config.DestPassword destKeyFile = config.DestKeyFile // S3 fields destBucket = config.DestBucket destRegion = config.DestRegion destAccessKey = config.DestAccessKey destSecretKey = config.DestSecretKey destEndpoint = config.DestEndpoint // SMB fields destShare = config.DestShare destDomain = config.DestDomain // FTP fields destPassiveMode = config.DestPassiveMode // OneDrive and Google Drive fields destClientId = config.DestClientID destClientSecret = config.DestClientSecret destDriveId = config.DestDriveID destTeamDrive = config.DestTeamDrive archivePath = config.ArchivePath archiveEnabled = config.ArchiveEnabled deleteAfterTransfer = config.DeleteAfterTransfer rcloneFlags = config.RcloneFlags } return fmt.Sprintf(`{ name: '%s', sourceType: '%s', sourcePath: '%s', sourceHost: '%s', sourcePort: %d, sourceUser: '%s', sourcePassword: '%s', sourceKeyFile: '%s', sourceBucket: '%s', sourceRegion: '%s', sourceAccessKey: '%s', sourceSecretKey: '%s', sourceEndpoint: '%s', sourceShare: '%s', sourceDomain: '%s', sourcePassiveMode: %v, sourceClientId: '%s', sourceClientSecret: '%s', sourceDriveId: '%s', sourceTeamDrive: '%s', filePattern: '%s', outputPattern: '%s', destinationType: '%s', destinationPath: '%s', destHost: '%s', destPort: %d, destUser: '%s', destPassword: '%s', destKeyFile: '%s', // S3 fields destBucket: '%s', destRegion: '%s', destAccessKey: '%s', destSecretKey: '%s', destEndpoint: '%s', // SMB fields destShare: '%s', destDomain: '%s', // FTP fields destPassiveMode: %v, // OneDrive and Google Drive fields destClientId: '%s', destClientSecret: '%s', destDriveId: '%s', destTeamDrive: '%s', // Existing fields archivePath: '%s', archiveEnabled: %v, deleteAfterTransfer: %v, rcloneFlags: '%s', loading: false, validate() { if (this.sourceType === 'sftp') { if (!this.sourceHost || !this.sourceUser || (!this.sourcePassword && !this.sourceKeyFile)) { return false; } } else if (this.sourceType === 's3') { if (!this.sourceBucket || !this.sourceRegion || !this.sourceAccessKey || !this.sourceSecretKey) { return false; } } else if (this.sourceType === 'minio') { if (!this.sourceBucket || !this.sourceEndpoint || !this.sourceAccessKey || !this.sourceSecretKey) { return false; } } else if (this.sourceType === 'b2') { if (!this.sourceBucket || !this.sourceAccessKey || !this.sourceSecretKey) { return false; } } else if (this.sourceType === 'smb') { if (!this.sourceHost || !this.sourceShare || !this.sourceUser || !this.sourcePassword) { return false; } } else if (this.sourceType === 'ftp') { if (!this.sourceHost || !this.sourceUser || !this.sourcePassword) { return false; } } else if (this.sourceType === 'webdav') { if (!this.sourceHost || !this.sourceUser || !this.sourcePassword) { return false; } } else if (this.sourceType === 'nextcloud') { if (!this.sourceHost || !this.sourceUser || !this.sourcePassword) { return false; } } else if (this.sourceType === 'onedrive') { if (!this.sourceClientId || !this.sourceClientSecret) { return false; } } else if (this.sourceType === 'google_drive') { if (!this.sourceClientId || !this.sourceClientSecret) { return false; } } if (this.destinationType === 'sftp') { if (!this.destHost || !this.destUser || (!this.destPassword && !this.destKeyFile)) { return false; } } else if (this.destinationType === 's3') { if (!this.destBucket || !this.destRegion || !this.destAccessKey || !this.destSecretKey) { return false; } } else if (this.destinationType === 'minio') { if (!this.destBucket || !this.destEndpoint || !this.destAccessKey || !this.destSecretKey) { return false; } } else if (this.destinationType === 'b2') { if (!this.destBucket || !this.destAccessKey || !this.destSecretKey) { return false; } } else if (this.destinationType === 'smb') { if (!this.destHost || !this.destShare || !this.destUser || !this.destPassword) { return false; } } else if (this.destinationType === 'ftp') { if (!this.destHost || !this.destUser || !this.destPassword) { return false; } } else if (this.destinationType === 'webdav') { if (!this.destHost || !this.destUser || !this.destPassword) { return false; } } else if (this.destinationType === 'nextcloud') { if (!this.destHost || !this.destUser || !this.destPassword) { return false; } } else if (this.destinationType === 'onedrive') { if (!this.destClientId || !this.destClientSecret) { return false; } } else if (this.destinationType === 'google_drive') { if (!this.destClientId || !this.destClientSecret) { return false; } } return this.name && this.sourcePath && this.filePattern && this.destinationPath && (!this.archiveEnabled || this.archivePath); } }`, name, sourceType, sourcePath, sourceHost, sourcePort, sourceUser, sourcePassword, sourceKeyFile, sourceBucket, sourceRegion, sourceAccessKey, sourceSecretKey, sourceEndpoint, sourceShare, sourceDomain, sourcePassiveMode, sourceClientId, sourceClientSecret, sourceDriveId, sourceTeamDrive, filePattern, outputPattern, destinationType, destinationPath, destHost, destPort, destUser, destPassword, destKeyFile, destBucket, destRegion, destAccessKey, destSecretKey, destEndpoint, destShare, destDomain, destPassiveMode, destClientId, destClientSecret, destDriveId, destTeamDrive, archivePath, archiveEnabled, deleteAfterTransfer, rcloneFlags) } templ ConfigForm(ctx context.Context, data ConfigFormData) { @LayoutWithContext(getConfigFormTitle(data.IsNew), ctx) {

if data.IsNew { Create New Configuration } else { Edit Configuration: { data.Config.Name } }

Set up your file transfer configuration

Pattern to match files for transfer (e.g., *.txt, *.csv)

Pattern for output filenames. Available variables:
{`${filename}`} - Original filename without extension (e.g., "report")
{`${ext}`} - Original file extension (e.g., ".csv")
{`${date:format}`} - Current date using Go's time format:
2006-01-02 → YYYY-MM-DD
20060102 → YYYYMMDD
2006-01-02_15:04:05 → YYYY-MM-DD_HH:MM:SS
Example: {`${filename}_[date:2006-01-02]_${ext}`} → "report_2025-03-01.csv"

Original files will be permanently deleted from source after successful transfer and archiving

Cancel

Configure your file transfer settings carefully for optimal performance

} }