plac-micro-common 1.3.4 → 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -37,54 +37,43 @@ exports.generateFormSIO = generateFormSIO;
|
|
|
37
37
|
const fs = __importStar(require("fs"));
|
|
38
38
|
const path = __importStar(require("path"));
|
|
39
39
|
const ejs = __importStar(require("ejs"));
|
|
40
|
-
/*
|
|
41
|
-
|--------------------------------------------------------------------------
|
|
42
|
-
| Cache storage
|
|
43
|
-
|--------------------------------------------------------------------------
|
|
44
|
-
*/
|
|
45
40
|
let cached_font_base64 = null;
|
|
46
41
|
const cached_templates = {};
|
|
47
|
-
/*
|
|
48
|
-
|--------------------------------------------------------------------------
|
|
49
|
-
| Resolve assets root
|
|
50
|
-
|--------------------------------------------------------------------------
|
|
51
|
-
*/
|
|
52
42
|
function getAssetsRootPath() {
|
|
53
43
|
return path.join(__dirname, "..", "..", "assets");
|
|
54
44
|
}
|
|
55
|
-
/*
|
|
56
|
-
|--------------------------------------------------------------------------
|
|
57
|
-
| Load font (cached)
|
|
58
|
-
|--------------------------------------------------------------------------
|
|
59
|
-
*/
|
|
60
45
|
function getFontBase64() {
|
|
61
46
|
if (!cached_font_base64) {
|
|
62
47
|
const font_path = path.join(getAssetsRootPath(), "fonts", "KhmerOS.ttf");
|
|
48
|
+
if (!fs.existsSync(font_path)) {
|
|
49
|
+
throw new Error(`Khmer font not found at path: ${font_path}`);
|
|
50
|
+
}
|
|
51
|
+
console.log("[generateFormSIO] __dirname =", __dirname);
|
|
52
|
+
console.log("[generateFormSIO] assets_root =", getAssetsRootPath());
|
|
53
|
+
console.log("[generateFormSIO] font_path =", font_path);
|
|
54
|
+
console.log("[generateFormSIO] font exists =", fs.existsSync(font_path));
|
|
63
55
|
const font_buffer = fs.readFileSync(font_path);
|
|
64
56
|
cached_font_base64 = font_buffer.toString("base64");
|
|
65
57
|
}
|
|
66
58
|
return cached_font_base64;
|
|
67
59
|
}
|
|
68
|
-
/*
|
|
69
|
-
|--------------------------------------------------------------------------
|
|
70
|
-
| Load template (cached)
|
|
71
|
-
|--------------------------------------------------------------------------
|
|
72
|
-
*/
|
|
73
60
|
function getTemplate(lang) {
|
|
74
61
|
if (!cached_templates[lang]) {
|
|
75
62
|
const template_path = lang === "en"
|
|
76
63
|
? path.join(getAssetsRootPath(), "templates", "sio-form-en.ejs")
|
|
77
64
|
: path.join(getAssetsRootPath(), "templates", "sio-form-kh.ejs");
|
|
65
|
+
if (!fs.existsSync(template_path)) {
|
|
66
|
+
throw new Error(`SIO template not found at path: ${template_path}`);
|
|
67
|
+
}
|
|
68
|
+
console.log("[generateFormSIO] __dirname =", __dirname);
|
|
69
|
+
console.log("[generateFormSIO] assets_root =", getAssetsRootPath());
|
|
70
|
+
console.log("[generateFormSIO] template_path =", template_path);
|
|
71
|
+
console.log("[generateFormSIO] template exists =", fs.existsSync(template_path));
|
|
78
72
|
const template = fs.readFileSync(template_path, "utf8");
|
|
79
73
|
cached_templates[lang] = ejs.compile(template);
|
|
80
74
|
}
|
|
81
75
|
return cached_templates[lang];
|
|
82
76
|
}
|
|
83
|
-
/*
|
|
84
|
-
|--------------------------------------------------------------------------
|
|
85
|
-
| Main generator
|
|
86
|
-
|--------------------------------------------------------------------------
|
|
87
|
-
*/
|
|
88
77
|
async function generateFormSIO(data, lang) {
|
|
89
78
|
const template = getTemplate(lang);
|
|
90
79
|
const font_base64 = getFontBase64();
|