implement dummy printer

This commit is contained in:
2025-04-10 14:26:20 +02:00
parent 9e3a04cd78
commit f87a6352dd
4 changed files with 170 additions and 55 deletions

55
models/printer.go Normal file
View File

@@ -0,0 +1,55 @@
package models
import (
"fmt"
)
type PrintOption string
const (
CoverPage PrintOption = "-o FrontCoverPage=Printed -o FrontCoverTray=BypassTray -o InputSlot=Tray1"
Colored PrintOption = "-o SelectColor=Color"
Grayscale PrintOption = "-o SelectColor=Grayscale"
)
type PrintJob struct {
Pdf string
Amount uint
Options []PrintOption
}
func NewPrintJob(shopItem ShopItem, variant ItemVariant, coverPage bool, amount uint) (PrintJob, error) {
if shopItem.Pdf == "" {
return PrintJob{}, fmt.Errorf("ShopItem has no PDF assigned")
}
if amount > 100 {
return PrintJob{}, fmt.Errorf("Amount to big. This is denied for security reasons")
}
var result PrintJob
result.Pdf = shopItem.Pdf
result.Amount = amount
if variant.Name == "Colored" {
result.Options = append(result.Options, Colored)
}
if coverPage {
result.Options = append(result.Options, CoverPage)
}
return result, nil
}
func (p *PrintJob) Execute() error {
baseCommand := "lp -p KONICA_MINOLTA_KONICA_MINOLTA_bizhub_C258/Booklet "
baseCommand += fmt.Sprintf("-n %v ", p.Amount)
for _, option := range p.Options {
baseCommand += fmt.Sprintf(" %v ", option)
}
fmt.Println(baseCommand)
return nil
}