| 1 | 'use strict';
|
| 2 |
|
| 3 | const zlib = require('zlib');
|
| 4 |
|
| 5 | /**
|
| 6 | * Build a posprint:// URL from a .pos document (object or JSON string).
|
| 7 | *
|
| 8 | * Encoding: UTF-8 JSON → raw deflate → base64url (no padding).
|
| 9 | *
|
| 10 | * @param {object|string} pos
|
| 11 | * @param {{ noconfirm?: boolean }} [options]
|
| 12 | * @returns {string}
|
| 13 | */
|
| 14 | function posprintUrl(pos, options = {}) {
|
| 15 | const json = typeof pos === 'string' ? pos : JSON.stringify(pos);
|
| 16 | const compressed = zlib.deflateRawSync(Buffer.from(json, 'utf8'), { level: 9 });
|
| 17 | const b64 = compressed.toString('base64url');
|
| 18 | let url = `posprint://print?v=1&d=${b64}`;
|
| 19 | if (options.noconfirm) {
|
| 20 | url += '&noconfirm=1';
|
| 21 | }
|
| 22 | return url;
|
| 23 | }
|
| 24 |
|
| 25 | module.exports = { posprintUrl };
|