Adding pdf output dirs as variable, updating go references

This commit is contained in:
Finley Ghosh 2026-01-12 22:47:23 +11:00
parent 45c4b416c3
commit fe1fc9ce77
6 changed files with 30 additions and 9 deletions

View file

@ -77,6 +77,8 @@ services:
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
DB_NAME: cmc
PORT: 8082
PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf
ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files
SMTP_HOST: postfix
SMTP_PORT: 25
SMTP_USER: ""

View file

@ -75,6 +75,8 @@ services:
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
DB_NAME: cmc
PORT: 8082
PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf
ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files
SMTP_HOST: postfix
SMTP_PORT: 25
SMTP_USER: ""

View file

@ -75,6 +75,8 @@ services:
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
DB_NAME: cmc
PORT: 8080
PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf
ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files
depends_on:
db:
condition: service_started

View file

@ -71,8 +71,12 @@ func main() {
// Static files
goRouter.PathPrefix("/static/").Handler(http.StripPrefix("/go/static/", http.FileServer(http.Dir("static"))))
// PDF files
goRouter.PathPrefix("/pdf/").Handler(http.StripPrefix("/go/pdf/", http.FileServer(http.Dir("webroot/pdf"))))
// PDF files - use PDF_OUTPUT_DIR env var or fallback to relative path
pdfDir := os.Getenv("PDF_OUTPUT_DIR")
if pdfDir == "" {
pdfDir = "webroot/pdf"
}
goRouter.PathPrefix("/pdf/").Handler(http.StripPrefix("/go/pdf/", http.FileServer(http.Dir(pdfDir))))
// Quote routes
goRouter.HandleFunc("/quotes", quoteHandler.QuotesOutstandingView).Methods("GET")
@ -91,6 +95,7 @@ func main() {
goRouter.HandleFunc("/pdf/generate-po", handlers.GeneratePurchaseOrderPDF).Methods("POST")
goRouter.HandleFunc("/pdf/generate-packinglist", handlers.GeneratePackingListPDF).Methods("POST")
goRouter.HandleFunc("/pdf/generate-orderack", handlers.GenerateOrderAckPDF).Methods("POST")
goRouter.HandleFunc("/pdf/count-pages", handlers.CountPages).Methods("POST")
// The following routes are currently disabled:
/*

View file

@ -127,8 +127,11 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) {
ext := filepath.Ext(handler.Filename)
filename := fmt.Sprintf("%d_%s%s", time.Now().Unix(), handler.Filename[:len(handler.Filename)-len(ext)], ext)
// Create attachments directory if it doesn't exist
attachDir := "webroot/attachments_files"
// Get attachments directory from environment or use default
attachDir := os.Getenv("ATTACHMENTS_DIR")
if attachDir == "" {
attachDir = "webroot/attachments_files"
}
if err := os.MkdirAll(attachDir, 0755); err != nil {
http.Error(w, "Failed to create attachments directory", http.StatusInternalServerError)
return
@ -172,13 +175,12 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) {
}
// Create database record
// Store path in PHP format: /var/www/cmc-sales/app/webroot/attachments_files/filename
phpPath := "/var/www/cmc-sales/app/webroot/attachments_files/" + filename
// Store the same path that was used to save the file (works across all environments)
params := db.CreateAttachmentParams{
PrincipleID: int32(principleID),
Name: name,
Filename: handler.Filename,
File: phpPath, // Store PHP container path for compatibility
File: filePath, // Store actual file path
Type: handler.Header.Get("Content-Type"),
Size: int32(handler.Size),
Description: description,

View file

@ -448,7 +448,11 @@ func (h *QuotesHandler) DailyQuoteExpirationCheck() {
// Construct PDF path from filesystem
enquiryRef := q["EnquiryRef"].(string)
pdfPath := fmt.Sprintf("/root/webroot/pdf/%s.pdf", enquiryRef)
pdfDir := os.Getenv("PDF_OUTPUT_DIR")
if pdfDir == "" {
pdfDir = "webroot/pdf"
}
pdfPath := fmt.Sprintf("%s/%s.pdf", pdfDir, enquiryRef)
pdfFilename := fmt.Sprintf("%s.pdf", enquiryRef)
err := h.SendQuoteReminderEmailWithPDF(
@ -680,7 +684,11 @@ func (h *QuotesHandler) SendManualReminder(w http.ResponseWriter, r *http.Reques
}
// Attach PDF quote from filesystem
pdfPath := fmt.Sprintf("/root/webroot/pdf/%s.pdf", enquiryRef)
pdfDir := os.Getenv("PDF_OUTPUT_DIR")
if pdfDir == "" {
pdfDir = "webroot/pdf"
}
pdfPath := fmt.Sprintf("%s/%s.pdf", pdfDir, enquiryRef)
pdfFilename := fmt.Sprintf("%s.pdf", enquiryRef)
// Get username from request