diff options
| author | Paul Buetow <paul@buetow.org> | 2025-08-02 15:54:18 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-08-02 15:54:18 +0300 |
| commit | f8574d5ecf31021b1aee7fcb0c8b45c190bffead (patch) | |
| tree | 77ee9a55771d496f1338017f4402f2c91f5f59e5 | |
| parent | 0968c9e0df98580d628f06f7afe1764fd857fb17 (diff) | |
add timestamps to .apkg exports and num of cardsv0.7.5
| -rw-r--r-- | internal/anki/apkg_generator.go | 12 | ||||
| -rw-r--r-- | internal/anki/apkg_generator_test.go | 13 | ||||
| -rw-r--r-- | internal/gui/app.go | 4 | ||||
| -rw-r--r-- | internal/processor/processor_test.go | 17 | ||||
| -rw-r--r-- | internal/version.go | 2 |
5 files changed, 34 insertions, 14 deletions
diff --git a/internal/anki/apkg_generator.go b/internal/anki/apkg_generator.go index 7f0538e..9707937 100644 --- a/internal/anki/apkg_generator.go +++ b/internal/anki/apkg_generator.go @@ -68,8 +68,16 @@ func (g *APKGGenerator) GenerateAPKG(outputPath string) error { return fmt.Errorf("failed to create database: %w", err) } - // Create the .apkg zip file - if err := g.createZipPackage(tempDir, outputPath); err != nil { + // Create the .apkg zip file with a timestamped name + timestamp := time.Now().Format("2006-01-02-15:04:05") + safeDeckName := strings.ReplaceAll(g.deckName, " ", "_") + safeDeckName = strings.ReplaceAll(safeDeckName, "/", "-") + numberOfCards := len(g.cards) + outputDir := filepath.Dir(outputPath) + finalName := fmt.Sprintf("%s-%s-%d.apkg", safeDeckName, timestamp, numberOfCards) + finalPath := filepath.Join(outputDir, finalName) + + if err := g.createZipPackage(tempDir, finalPath); err != nil { return fmt.Errorf("failed to create zip package: %w", err) } diff --git a/internal/anki/apkg_generator_test.go b/internal/anki/apkg_generator_test.go index 95be7d7..01e5a26 100644 --- a/internal/anki/apkg_generator_test.go +++ b/internal/anki/apkg_generator_test.go @@ -106,13 +106,18 @@ func TestGenerateAPKG(t *testing.T) { t.Fatalf("GenerateAPKG() error = %v", err) } - // Verify file exists - if _, err := os.Stat(outputPath); os.IsNotExist(err) { - t.Fatal("APKG file was not created") + // Find the generated file + files, err := filepath.Glob(filepath.Join(tempDir, "*.apkg")) + if err != nil { + t.Fatalf("Error finding apkg file: %v", err) + } + if len(files) != 1 { + t.Fatalf("Expected 1 apkg file, found %d", len(files)) } + actualOutputPath := files[0] // Verify it's a valid zip file - reader, err := zip.OpenReader(outputPath) + reader, err := zip.OpenReader(actualOutputPath) if err != nil { t.Fatalf("Failed to open APKG as zip: %v", err) } diff --git a/internal/gui/app.go b/internal/gui/app.go index f776d9b..9374973 100644 --- a/internal/gui/app.go +++ b/internal/gui/app.go @@ -1203,7 +1203,7 @@ func (a *Application) onExportToAnki() { // Update status bar instead of showing dialog a.updateStatus(fmt.Sprintf("Exported %d cards to %s (%d with audio, %d with images)", - total, outputPath, withAudio, withImages)) + total, selectedDir, withAudio, withImages)) } else { filename = "anki_import.csv" outputPath = filepath.Join(selectedDir, filename) @@ -1232,7 +1232,7 @@ func (a *Application) onExportToAnki() { // Update status bar instead of showing dialog a.updateStatus(fmt.Sprintf("Exported %d cards to %s (%d with audio, %d with images)", - total, outputPath, withAudio, withImages)) + total, selectedDir, withAudio, withImages)) } }, a.window) diff --git a/internal/processor/processor_test.go b/internal/processor/processor_test.go index 40f5cbe..2c8eaa6 100644 --- a/internal/processor/processor_test.go +++ b/internal/processor/processor_test.go @@ -252,11 +252,18 @@ func TestGenerateAnkiFile_APKG(t *testing.T) { t.Errorf("GenerateAnkiFile (APKG) failed: %v", err) } - // Check APKG file was created in home directory + // Check that an .apkg file was created in the home directory homeDir, _ := os.UserHomeDir() - apkgFile := filepath.Join(homeDir, "Test_Deck.apkg") - if _, err := os.Stat(apkgFile); os.IsNotExist(err) { - t.Error("APKG file was not created in home directory") + files, err := filepath.Glob(filepath.Join(homeDir, "*.apkg")) + if err != nil { + t.Fatalf("Error finding apkg file: %v", err) + } + if len(files) == 0 { + t.Fatal("No .apkg file found in home directory") + } + + // Clean up the created file + for _, file := range files { + os.Remove(file) } - os.Remove(apkgFile) // Clean up } diff --git a/internal/version.go b/internal/version.go index 75223b8..17deabe 100644 --- a/internal/version.go +++ b/internal/version.go @@ -1,3 +1,3 @@ package internal -const Version = "0.7.4" +const Version = "0.7.5" |
