Use the correct tmpDir

This commit is contained in:
Jason Streifling 2025-01-19 09:00:02 +01:00
parent 5d251c3659
commit 62e75eaea8

View File

@ -14,15 +14,13 @@ import (
func ConvertToMarkdown(c *Config, filename string) ([]byte, error) { func ConvertToMarkdown(c *Config, filename string) ([]byte, error) {
var stderr bytes.Buffer var stderr bytes.Buffer
articleID := uuid.New() tmpDir, err := os.MkdirTemp(os.TempDir(), "cpolis_images")
articleFileName := fmt.Sprint("/tmp/", articleID, ".md")
tmpDir, err := os.MkdirTemp("/tmp", "cpolis_images")
if err != nil { if err != nil {
return nil, fmt.Errorf("error creating temporary directory: %v", err) return nil, fmt.Errorf("error creating temporary directory: %v", err)
} }
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
articleFileName := filepath.Join(os.TempDir(), fmt.Sprint(uuid.New(), ".md"))
cmd := exec.Command("pandoc", "-s", "-f", "docx", "-t", "commonmark_x", "-o", articleFileName, "--extract-media", tmpDir, filename) // TODO: Is writing to a file necessary? cmd := exec.Command("pandoc", "-s", "-f", "docx", "-t", "commonmark_x", "-o", articleFileName, "--extract-media", tmpDir, filename) // TODO: Is writing to a file necessary?
cmd.Stderr = &stderr cmd.Stderr = &stderr
if err = cmd.Run(); err != nil { if err = cmd.Run(); err != nil {