modular
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import * as docx from "docx";
|
||||
import cookie from "cookie";
|
||||
import fs from "fs";
|
||||
|
||||
|
||||
function createDirectoryIfNotExists(dirPath) {
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
if (!fs.existsSync(dirPath)) {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
function extractCookie(cookies) {
|
||||
@@ -62,12 +62,39 @@ function getSessionCookie(jwtSession, jwtToken) {
|
||||
httpOnly: true,
|
||||
secure: true,
|
||||
sameSite: "Lax",
|
||||
}
|
||||
];
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
}
|
||||
function createDocx(content) {
|
||||
var paragraphs = [];
|
||||
content.split("\n").forEach((line) => {
|
||||
paragraphs.push(
|
||||
new docx.Paragraph({
|
||||
children: [new docx.TextRun(line)],
|
||||
})
|
||||
);
|
||||
});
|
||||
var doc = new docx.Document({
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
children: paragraphs,
|
||||
},
|
||||
],
|
||||
});
|
||||
return docx.Packer.toBuffer(doc).then((buffer) => buffer);
|
||||
}
|
||||
// eventStream util
|
||||
function createEvent(event, data) {
|
||||
// if data is object, stringify it
|
||||
if (typeof data === "object") {
|
||||
data = JSON.stringify(data);
|
||||
}
|
||||
return `event: ${event}\ndata: ${data}\n\n`;
|
||||
}
|
||||
|
||||
export { createDirectoryIfNotExists, sleep, extractCookie, getSessionCookie };
|
||||
export { createEvent, createDirectoryIfNotExists, sleep, extractCookie, getSessionCookie, createDocx };
|
||||
|
||||
Reference in New Issue
Block a user