fix the file name sequence
This commit is contained in:
parent
c870d16b3e
commit
a80bf06272
1
.github/workflows/build.yaml
vendored
1
.github/workflows/build.yaml
vendored
@ -4,7 +4,6 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- master
|
|
||||||
tags:
|
tags:
|
||||||
- v*
|
- v*
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|||||||
@ -61,23 +61,23 @@ function getSize(width, height) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveLabel(blob, ext) {
|
async function saveLabel(blob, ext, counter) {
|
||||||
let items = global.localStorage.getItem('counter');
|
|
||||||
let counter = parseInt(items.counter);
|
|
||||||
const fileName = `LBL${pad(counter, 6)}.${ext}`;
|
const fileName = `LBL${pad(counter, 6)}.${ext}`;
|
||||||
|
|
||||||
global.localStorage.setItem('counter', ++counter);
|
|
||||||
|
|
||||||
// Creating and Writing to the sample.txt file
|
try {
|
||||||
fs.writeFile(fileName,
|
fs.writeFileSync(fileName, new Uint8Array(await blob.arrayBuffer()))
|
||||||
new Uint8Array(await blob.arrayBuffer()),
|
// file written successfully
|
||||||
function (err) {
|
notify('Label <b>{0}</b> saved in folder <b>{1}</b>'.format(fileName, $('#txt-path').val()), 'floppy-saved', 'info', 1000);
|
||||||
if (err) throw err;
|
} catch (err) {
|
||||||
notify('Label <b>{0}</b> saved in folder <b>{1}</b>'.format(fileName, $('#txt-path').val()), 'floppy-saved', 'info', 1000);
|
console.error(err);
|
||||||
});
|
notify(`error in saving label to ${fileName} ${err}`, 'floppy-saved', 'danger', 0)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchAndSavePDF(api_url, zpl) {
|
async function fetchAndSavePDF(api_url, zpl, counter) {
|
||||||
|
|
||||||
let r1 = await fetch(api_url, {
|
let r1 = await fetch(api_url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -90,7 +90,7 @@ async function fetchAndSavePDF(api_url, zpl) {
|
|||||||
|
|
||||||
if (r1.ok && r1.status === 200) {
|
if (r1.ok && r1.status === 200) {
|
||||||
let blob = await r1.blob()
|
let blob = await r1.blob()
|
||||||
await saveLabel(blob, 'pdf');
|
await saveLabel(blob, 'pdf', counter);
|
||||||
} else {
|
} else {
|
||||||
console.log('error in fetching pdf', `status = ${r1.status}`, await r1.text(), `zpl=${zpl}`)
|
console.log('error in fetching pdf', `status = ${r1.status}`, await r1.text(), `zpl=${zpl}`)
|
||||||
}
|
}
|
||||||
@ -125,7 +125,7 @@ function notify(text, glyphicon, type, delay) {
|
|||||||
}).show();
|
}).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function displayAndSaveImage(api_url, zpl, width, height, savePng) {
|
async function displayAndSaveImage(api_url, zpl, width, height, savePng, counter) {
|
||||||
let r1 = await fetch(api_url, {
|
let r1 = await fetch(api_url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: zpl,
|
body: zpl,
|
||||||
@ -153,7 +153,7 @@ async function displayAndSaveImage(api_url, zpl, width, height, savePng) {
|
|||||||
$('#label').animate({'top': '0px'}, 1500);
|
$('#label').animate({'top': '0px'}, 1500);
|
||||||
|
|
||||||
if (savePng) {
|
if (savePng) {
|
||||||
await saveLabel(blob, "png")
|
await saveLabel(blob, "png", counter)
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -203,15 +203,23 @@ function startTcpServer() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let items = global.localStorage.getItem('counter') || '0';
|
||||||
|
let counter = parseInt(items);
|
||||||
|
counter = isNaN(counter) ? 1 : counter;
|
||||||
|
console.log('counter?', items, counter)
|
||||||
|
|
||||||
let api_url = `https://api.labelary.com/v1/printers/${configs.density}dpmm/labels/${width}x${height}/0`;
|
let api_url = `https://api.labelary.com/v1/printers/${configs.density}dpmm/labels/${width}x${height}/0`;
|
||||||
console.warn("configs", configs["saveLabels"], "fileType", configs["fileType"])
|
console.warn("configs", configs["saveLabels"], "fileType", configs["fileType"])
|
||||||
let savePdf = configs['saveLabels'] && configs['filetype'] === '2';
|
let savePdf = configs['saveLabels'] && configs['filetype'] === '2';
|
||||||
let savePng = configs['saveLabels'] && configs['filetype'] === '1';
|
let savePng = configs['saveLabels'] && configs['filetype'] === '1';
|
||||||
if (savePdf) {
|
if (savePdf) {
|
||||||
await fetchAndSavePDF(api_url, zpl);
|
await fetchAndSavePDF(api_url, zpl, counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
await displayAndSaveImage(api_url, zpl, width, height, savePng);
|
await displayAndSaveImage(api_url, zpl, width, height, savePng, counter);
|
||||||
|
|
||||||
|
global.localStorage.setItem('counter', `${++counter}`);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user