@blockspoon/cert-badge-renderer 1.0.2 → 1.0.3
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.
|
@@ -19,44 +19,6 @@ const qrcode_1 = __importDefault(require("qrcode"));
|
|
|
19
19
|
const svgTemplate_1 = require("../templates/svgTemplate");
|
|
20
20
|
const certificates_1 = __importDefault(require("../templates/certificates"));
|
|
21
21
|
const componentsDirection_1 = require("../constants/componentsDirection");
|
|
22
|
-
function convertImageToBase64(url) {
|
|
23
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
try {
|
|
25
|
-
// URL이 이미 baseUrl을 포함하고 있는지 확인
|
|
26
|
-
let finalUrls = [];
|
|
27
|
-
finalUrls = url.split("https://");
|
|
28
|
-
const finalUrl = "https://" + finalUrls.pop();
|
|
29
|
-
const response = yield fetch(finalUrl, {
|
|
30
|
-
credentials: "include",
|
|
31
|
-
headers: {
|
|
32
|
-
Accept: "image/*",
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
if (!response.ok) {
|
|
36
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
37
|
-
}
|
|
38
|
-
const contentType = response.headers.get("content-type");
|
|
39
|
-
if (!(contentType === null || contentType === void 0 ? void 0 : contentType.startsWith("image/"))) {
|
|
40
|
-
throw new Error(`Not an image! content-type: ${contentType}`);
|
|
41
|
-
}
|
|
42
|
-
const buffer = yield response.arrayBuffer();
|
|
43
|
-
let base64 = "";
|
|
44
|
-
if (typeof window === "undefined") {
|
|
45
|
-
// Node.js 환경
|
|
46
|
-
base64 = Buffer.from(buffer).toString("base64");
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
// 브라우저 환경
|
|
50
|
-
base64 = btoa(new Uint8Array(buffer).reduce((data, byte) => data + String.fromCharCode(byte), ""));
|
|
51
|
-
}
|
|
52
|
-
return `data:${contentType};base64,${base64}`;
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
console.error(`이미지 변환 실패: ${url}`, error);
|
|
56
|
-
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
22
|
function generateAchievementHTML(data_1) {
|
|
61
23
|
return __awaiter(this, arguments, void 0, function* (data, options = {}) {
|
|
62
24
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
@@ -280,9 +242,9 @@ function generateAchievementHTML(data_1) {
|
|
|
280
242
|
}
|
|
281
243
|
else if (element.src) {
|
|
282
244
|
// 이미지를 base64로 변환
|
|
283
|
-
const base64Image =
|
|
245
|
+
// const base64Image = await convertImageToBase64(element.src);
|
|
284
246
|
html += `<img
|
|
285
|
-
src="${
|
|
247
|
+
src="${element.src}"
|
|
286
248
|
alt="Uploaded"
|
|
287
249
|
style="
|
|
288
250
|
width: 100%;
|
package/package.json
CHANGED
|
@@ -14,51 +14,6 @@ import {
|
|
|
14
14
|
import Certificates from "../templates/certificates";
|
|
15
15
|
import { portraitComponents } from "../constants/componentsDirection";
|
|
16
16
|
|
|
17
|
-
async function convertImageToBase64(url: string): Promise<string> {
|
|
18
|
-
try {
|
|
19
|
-
// URL이 이미 baseUrl을 포함하고 있는지 확인
|
|
20
|
-
let finalUrls = [];
|
|
21
|
-
finalUrls = url.split("https://");
|
|
22
|
-
const finalUrl = "https://" + finalUrls.pop();
|
|
23
|
-
|
|
24
|
-
const response = await fetch(finalUrl, {
|
|
25
|
-
credentials: "include",
|
|
26
|
-
headers: {
|
|
27
|
-
Accept: "image/*",
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
if (!response.ok) {
|
|
32
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const contentType = response.headers.get("content-type");
|
|
36
|
-
if (!contentType?.startsWith("image/")) {
|
|
37
|
-
throw new Error(`Not an image! content-type: ${contentType}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const buffer = await response.arrayBuffer();
|
|
41
|
-
let base64 = "";
|
|
42
|
-
|
|
43
|
-
if (typeof window === "undefined") {
|
|
44
|
-
// Node.js 환경
|
|
45
|
-
base64 = Buffer.from(buffer).toString("base64");
|
|
46
|
-
} else {
|
|
47
|
-
// 브라우저 환경
|
|
48
|
-
base64 = btoa(
|
|
49
|
-
new Uint8Array(buffer).reduce(
|
|
50
|
-
(data, byte) => data + String.fromCharCode(byte),
|
|
51
|
-
""
|
|
52
|
-
)
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
return `data:${contentType};base64,${base64}`;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error(`이미지 변환 실패: ${url}`, error);
|
|
58
|
-
return "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
17
|
export async function generateAchievementHTML(
|
|
63
18
|
data: CertificateData,
|
|
64
19
|
options: CertificateOptions = {}
|
|
@@ -330,9 +285,9 @@ export async function generateAchievementHTML(
|
|
|
330
285
|
}
|
|
331
286
|
} else if (element.src) {
|
|
332
287
|
// 이미지를 base64로 변환
|
|
333
|
-
const base64Image = await convertImageToBase64(element.src);
|
|
288
|
+
// const base64Image = await convertImageToBase64(element.src);
|
|
334
289
|
html += `<img
|
|
335
|
-
src="${
|
|
290
|
+
src="${element.src}"
|
|
336
291
|
alt="Uploaded"
|
|
337
292
|
style="
|
|
338
293
|
width: 100%;
|