|
@@ -6,7 +6,12 @@ import fs from 'node:fs';
|
|
import PDFDocument from 'pdfkit';
|
|
import PDFDocument from 'pdfkit';
|
|
import log from 'electron-log/renderer';
|
|
import log from 'electron-log/renderer';
|
|
|
|
|
|
-import { getImagicPath, getTempPath } from './utils';
|
|
|
|
|
|
+import {
|
|
|
|
+ getImagicPath,
|
|
|
|
+ getTempPath,
|
|
|
|
+ makeDirSync,
|
|
|
|
+ getGmFontPath,
|
|
|
|
+} from './utils';
|
|
|
|
|
|
import {
|
|
import {
|
|
DrawTrackItem,
|
|
DrawTrackItem,
|
|
@@ -46,8 +51,11 @@ function drawTrack(
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
const gmObj = gmInst(imgPath);
|
|
const gmObj = gmInst(imgPath);
|
|
|
|
|
|
|
|
+ makeDirSync(path.dirname(outpath));
|
|
|
|
+
|
|
const defaultColor = '#f53f3f';
|
|
const defaultColor = '#f53f3f';
|
|
- const defaultFontSize = 14;
|
|
|
|
|
|
+ const defaultFontSize = 22;
|
|
|
|
+ gmObj.font(getGmFontPath());
|
|
|
|
|
|
drawTrackList.forEach((track) => {
|
|
drawTrackList.forEach((track) => {
|
|
// text
|
|
// text
|
|
@@ -83,24 +91,25 @@ function drawTrack(
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
-async function downloadFile(url: string, outputPath: string) {
|
|
|
|
- const writer = fs.createWriteStream(outputPath);
|
|
|
|
-
|
|
|
|
- const response = await axios({
|
|
|
|
- url,
|
|
|
|
- method: 'GET',
|
|
|
|
- responseType: 'stream',
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- response.data.pipe(writer);
|
|
|
|
-
|
|
|
|
|
|
+async function downloadFile(url: string, outputPath: string): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
- writer.on('finish', resolve);
|
|
|
|
- writer.on('error', reject);
|
|
|
|
|
|
+ axios({
|
|
|
|
+ url,
|
|
|
|
+ method: 'GET',
|
|
|
|
+ responseType: 'arraybuffer',
|
|
|
|
+ })
|
|
|
|
+ .then((response) => {
|
|
|
|
+ fs.writeFileSync(outputPath, Buffer.from(response.data, 'binary'));
|
|
|
|
+ resolve(outputPath);
|
|
|
|
+ })
|
|
|
|
+ .catch(() => {
|
|
|
|
+ reject();
|
|
|
|
+ });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
async function downloadImage(url: string, outputPath: string) {
|
|
async function downloadImage(url: string, outputPath: string) {
|
|
|
|
+ makeDirSync(path.dirname(outputPath));
|
|
await downloadFile(url, outputPath);
|
|
await downloadFile(url, outputPath);
|
|
const size = sizeOf(outputPath);
|
|
const size = sizeOf(outputPath);
|
|
|
|
|
|
@@ -125,8 +134,9 @@ async function imagesToPdf(
|
|
outpath: string
|
|
outpath: string
|
|
): Promise<string> {
|
|
): Promise<string> {
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
- const doc = new PDFDocument();
|
|
|
|
|
|
+ const doc = new PDFDocument({ autoFirstPage: false });
|
|
|
|
|
|
|
|
+ makeDirSync(path.dirname(outpath));
|
|
const steam = fs.createWriteStream(outpath);
|
|
const steam = fs.createWriteStream(outpath);
|
|
doc.pipe(steam);
|
|
doc.pipe(steam);
|
|
|
|
|