Adding pdf output dirs as variable, updating go references
This commit is contained in:
parent
45c4b416c3
commit
fe1fc9ce77
|
|
@ -77,6 +77,8 @@ services:
|
||||||
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
||||||
DB_NAME: cmc
|
DB_NAME: cmc
|
||||||
PORT: 8082
|
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_HOST: postfix
|
||||||
SMTP_PORT: 25
|
SMTP_PORT: 25
|
||||||
SMTP_USER: ""
|
SMTP_USER: ""
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ services:
|
||||||
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
||||||
DB_NAME: cmc
|
DB_NAME: cmc
|
||||||
PORT: 8082
|
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_HOST: postfix
|
||||||
SMTP_PORT: 25
|
SMTP_PORT: 25
|
||||||
SMTP_USER: ""
|
SMTP_USER: ""
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ services:
|
||||||
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
DB_PASSWORD: xVRQI&cA?7AU=hqJ!%au
|
||||||
DB_NAME: cmc
|
DB_NAME: cmc
|
||||||
PORT: 8080
|
PORT: 8080
|
||||||
|
PDF_OUTPUT_DIR: /var/www/cmc-sales/app/webroot/pdf
|
||||||
|
ATTACHMENTS_DIR: /var/www/cmc-sales/app/webroot/attachments_files
|
||||||
depends_on:
|
depends_on:
|
||||||
db:
|
db:
|
||||||
condition: service_started
|
condition: service_started
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,12 @@ func main() {
|
||||||
// Static files
|
// Static files
|
||||||
goRouter.PathPrefix("/static/").Handler(http.StripPrefix("/go/static/", http.FileServer(http.Dir("static"))))
|
goRouter.PathPrefix("/static/").Handler(http.StripPrefix("/go/static/", http.FileServer(http.Dir("static"))))
|
||||||
|
|
||||||
// PDF files
|
// PDF files - use PDF_OUTPUT_DIR env var or fallback to relative path
|
||||||
goRouter.PathPrefix("/pdf/").Handler(http.StripPrefix("/go/pdf/", http.FileServer(http.Dir("webroot/pdf"))))
|
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
|
// Quote routes
|
||||||
goRouter.HandleFunc("/quotes", quoteHandler.QuotesOutstandingView).Methods("GET")
|
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-po", handlers.GeneratePurchaseOrderPDF).Methods("POST")
|
||||||
goRouter.HandleFunc("/pdf/generate-packinglist", handlers.GeneratePackingListPDF).Methods("POST")
|
goRouter.HandleFunc("/pdf/generate-packinglist", handlers.GeneratePackingListPDF).Methods("POST")
|
||||||
goRouter.HandleFunc("/pdf/generate-orderack", handlers.GenerateOrderAckPDF).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:
|
// The following routes are currently disabled:
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -127,8 +127,11 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||||
ext := filepath.Ext(handler.Filename)
|
ext := filepath.Ext(handler.Filename)
|
||||||
filename := fmt.Sprintf("%d_%s%s", time.Now().Unix(), handler.Filename[:len(handler.Filename)-len(ext)], ext)
|
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
|
// Get attachments directory from environment or use default
|
||||||
attachDir := "webroot/attachments_files"
|
attachDir := os.Getenv("ATTACHMENTS_DIR")
|
||||||
|
if attachDir == "" {
|
||||||
|
attachDir = "webroot/attachments_files"
|
||||||
|
}
|
||||||
if err := os.MkdirAll(attachDir, 0755); err != nil {
|
if err := os.MkdirAll(attachDir, 0755); err != nil {
|
||||||
http.Error(w, "Failed to create attachments directory", http.StatusInternalServerError)
|
http.Error(w, "Failed to create attachments directory", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
|
@ -172,13 +175,12 @@ func (h *AttachmentHandler) Create(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create database record
|
// Create database record
|
||||||
// Store path in PHP format: /var/www/cmc-sales/app/webroot/attachments_files/filename
|
// Store the same path that was used to save the file (works across all environments)
|
||||||
phpPath := "/var/www/cmc-sales/app/webroot/attachments_files/" + filename
|
|
||||||
params := db.CreateAttachmentParams{
|
params := db.CreateAttachmentParams{
|
||||||
PrincipleID: int32(principleID),
|
PrincipleID: int32(principleID),
|
||||||
Name: name,
|
Name: name,
|
||||||
Filename: handler.Filename,
|
Filename: handler.Filename,
|
||||||
File: phpPath, // Store PHP container path for compatibility
|
File: filePath, // Store actual file path
|
||||||
Type: handler.Header.Get("Content-Type"),
|
Type: handler.Header.Get("Content-Type"),
|
||||||
Size: int32(handler.Size),
|
Size: int32(handler.Size),
|
||||||
Description: description,
|
Description: description,
|
||||||
|
|
|
||||||
|
|
@ -448,7 +448,11 @@ func (h *QuotesHandler) DailyQuoteExpirationCheck() {
|
||||||
|
|
||||||
// Construct PDF path from filesystem
|
// Construct PDF path from filesystem
|
||||||
enquiryRef := q["EnquiryRef"].(string)
|
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)
|
pdfFilename := fmt.Sprintf("%s.pdf", enquiryRef)
|
||||||
|
|
||||||
err := h.SendQuoteReminderEmailWithPDF(
|
err := h.SendQuoteReminderEmailWithPDF(
|
||||||
|
|
@ -680,7 +684,11 @@ func (h *QuotesHandler) SendManualReminder(w http.ResponseWriter, r *http.Reques
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach PDF quote from filesystem
|
// 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)
|
pdfFilename := fmt.Sprintf("%s.pdf", enquiryRef)
|
||||||
|
|
||||||
// Get username from request
|
// Get username from request
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue