mirror of
https://github.com/anikeen-com/print-utils.git
synced 2026-03-13 13:46:07 +00:00
Add fake printer
This commit is contained in:
29
index.js
29
index.js
@@ -10,6 +10,12 @@ const port = 1903
|
|||||||
|
|
||||||
const upload = multer({ dest: 'uploads/' })
|
const upload = multer({ dest: 'uploads/' })
|
||||||
|
|
||||||
|
const debug = process.argv.includes('--debug')
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
console.log('Running in debug mode')
|
||||||
|
}
|
||||||
|
|
||||||
app.use(cors())
|
app.use(cors())
|
||||||
app.use(bodyParser.json())
|
app.use(bodyParser.json())
|
||||||
app.use(bodyParser.urlencoded({ extended: true }))
|
app.use(bodyParser.urlencoded({ extended: true }))
|
||||||
@@ -19,10 +25,20 @@ app.get('/', (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
app.get('/printers', async (req, res) => {
|
app.get('/printers', async (req, res) => {
|
||||||
|
const printerList = []
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
printerList.push({
|
||||||
|
default: false,
|
||||||
|
format: 'PDF',
|
||||||
|
id: 'Fake Printer',
|
||||||
|
name: 'Fake Printer',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const printers = await getPrinters()
|
const printers = await getPrinters()
|
||||||
|
printerList.push(...printers.map(printer => {
|
||||||
return res.json(printers.map(printer => {
|
|
||||||
return {
|
return {
|
||||||
default: false,
|
default: false,
|
||||||
format: 'PDF',
|
format: 'PDF',
|
||||||
@@ -32,8 +48,9 @@ app.get('/printers', async (req, res) => {
|
|||||||
}))
|
}))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error getting printers', e)
|
console.error('Error getting printers', e)
|
||||||
return res.json([])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res.json(printerList)
|
||||||
})
|
})
|
||||||
|
|
||||||
app.post('/printers/:printer/print', upload.single('file'), async (req, res) => {
|
app.post('/printers/:printer/print', upload.single('file'), async (req, res) => {
|
||||||
@@ -42,6 +59,12 @@ app.post('/printers/:printer/print', upload.single('file'), async (req, res) =>
|
|||||||
// query: user-id: string, docType: label
|
// query: user-id: string, docType: label
|
||||||
// form data: file: binary, copies: string, shipment-ids: string
|
// form data: file: binary, copies: string, shipment-ids: string
|
||||||
|
|
||||||
|
if (printer === 'Fake Printer') {
|
||||||
|
return res.json({
|
||||||
|
jobs: ['0'],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const fileToPrint = req.file.path
|
const fileToPrint = req.file.path
|
||||||
const printJob = await print(fileToPrint, printer)
|
const printJob = await print(fileToPrint, printer)
|
||||||
|
|||||||
Reference in New Issue
Block a user