implement dummy printer
This commit is contained in:
55
models/printer.go
Normal file
55
models/printer.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user