Add copies parameter
parent
8d66083f18
commit
3ef7a1f1a1
15
index.js
15
index.js
|
@ -61,7 +61,8 @@ app.get('/', (req, res) => {
|
|||
- Prints IPP jobs
|
||||
- POST /print?printer=:name (body: application/pdf)
|
||||
- Prints a PDF
|
||||
- :name - printer name or alias (case insensitive)
|
||||
- ?printer= printer name or alias (case insensitive)
|
||||
- ?copies= (optional) number of copies (1-10 allowed)
|
||||
- Response: 200 OK if sent to printer successfully (not necessarily printed), 4xx/5xx otherwise
|
||||
</pre>`)
|
||||
})
|
||||
|
@ -111,7 +112,7 @@ app.post('/print', bodyParser.raw({ type: '*/*', limit: 10_000_000 }), (req, res
|
|||
console.log("Received print job: ", { body, query })
|
||||
|
||||
// validate query params
|
||||
const { printer: printerName, ...otherParams } = query
|
||||
const { printer: printerName, copies: copiesParam, ...otherParams } = query
|
||||
if (!printerName) {
|
||||
res.status(400).send("No printer specified, pass ?printer=:name in the query params")
|
||||
return
|
||||
|
@ -136,14 +137,20 @@ app.post('/print', bodyParser.raw({ type: '*/*', limit: 10_000_000 }), (req, res
|
|||
return
|
||||
}
|
||||
|
||||
// validate job attributes
|
||||
const copies = Number(copiesParam) || 1
|
||||
if (!(copies >= 1 && copies <= 10)) {
|
||||
res.status(400).send("Copies must be between 1 and 10")
|
||||
return
|
||||
}
|
||||
|
||||
// send print job
|
||||
const msg = {
|
||||
"operation-attributes-tag": {
|
||||
"document-format": "application/pdf",
|
||||
},
|
||||
"job-attributes-tag": {
|
||||
// FIXME: This should work, but does not
|
||||
// "copies": 2,
|
||||
"copies": copies,
|
||||
},
|
||||
data: body
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue