|
| 1 | +import cssTemplate from "./defaultPage.css"; |
| 2 | +import htmlTemplate from "./defaultPage.html"; |
| 3 | + |
| 4 | +function asText(templateModule) { |
| 5 | + if (typeof templateModule === "string") { |
| 6 | + return templateModule; |
| 7 | + } |
| 8 | + |
| 9 | + if (templateModule && typeof templateModule.default === "string") { |
| 10 | + return templateModule.default; |
| 11 | + } |
| 12 | + |
| 13 | + return String(templateModule ?? ""); |
| 14 | +} |
| 15 | + |
| 16 | +const UUID_EXAMPLE = { |
| 17 | + cache: { |
| 18 | + HIT: true, |
| 19 | + cache_time: 43200, |
| 20 | + cache_time_left: 28910, |
| 21 | + cached_at: 1774166400, |
| 22 | + cached_until: 1774209600 |
| 23 | + }, |
| 24 | + id: "853c80ef3c3749fdaa49938b674adae6", |
| 25 | + name: "jeb_", |
| 26 | + status: "OK" |
| 27 | +}; |
| 28 | + |
| 29 | +const PROFILE_EXAMPLE = { |
| 30 | + decoded: { |
| 31 | + profileId: "853c80ef3c3749fdaa49938b674adae6", |
| 32 | + profileName: "jeb_", |
| 33 | + signatureRequired: true, |
| 34 | + textures: { |
| 35 | + SKIN: { |
| 36 | + url: "http://textures.minecraft.net/texture/a846b82963924cb13211122489263941d1403689f90151120d5234be4a73fb" |
| 37 | + } |
| 38 | + }, |
| 39 | + timestamp: 1521401553373 |
| 40 | + }, |
| 41 | + raw: { |
| 42 | + id: "853c80ef3c3749fdaa49938b674adae6", |
| 43 | + name: "jeb_", |
| 44 | + properties: [ |
| 45 | + { |
| 46 | + name: "textures", |
| 47 | + value: "<base64>", |
| 48 | + signature: "<signature>" |
| 49 | + } |
| 50 | + ], |
| 51 | + cache: { |
| 52 | + HIT: true, |
| 53 | + cache_time: 43200, |
| 54 | + cache_time_left: 29712, |
| 55 | + cached_at: 1774166400, |
| 56 | + cached_until: 1774209600 |
| 57 | + }, |
| 58 | + status: "OK" |
| 59 | + } |
| 60 | +}; |
| 61 | + |
| 62 | +function escapeHtml(value) { |
| 63 | + return value |
| 64 | + .replace(/&/g, "&") |
| 65 | + .replace(/</g, "<") |
| 66 | + .replace(/>/g, ">") |
| 67 | + .replace(/\"/g, """) |
| 68 | + .replace(/'/g, "'"); |
| 69 | +} |
| 70 | + |
| 71 | +function renderJson(value) { |
| 72 | + return escapeHtml(JSON.stringify(value, null, 2)); |
| 73 | +} |
| 74 | + |
| 75 | +export function serveDefaultPage(request) { |
| 76 | + const url = new URL(request.url); |
| 77 | + const base = `${url.protocol}//${url.host}`; |
| 78 | + const htmlSource = asText(htmlTemplate); |
| 79 | + const cssSource = asText(cssTemplate); |
| 80 | + |
| 81 | + const html = htmlSource |
| 82 | + .replace("/*__INLINE_CSS__*/", cssSource) |
| 83 | + .replace("__UUID_USAGE__", escapeHtml(`${base}/uuid/jeb_\n${base}/uuid/853c80ef3c3749fdaa49938b674adae6`)) |
| 84 | + .replace("__PROFILE_USAGE__", escapeHtml(`${base}/profile/853c80ef3c3749fdaa49938b674adae6`)) |
| 85 | + .replace("__UUID_EXAMPLE__", renderJson(UUID_EXAMPLE)) |
| 86 | + .replace("__PROFILE_EXAMPLE__", renderJson(PROFILE_EXAMPLE)); |
| 87 | + |
| 88 | + return new Response(html, { |
| 89 | + headers: { |
| 90 | + "content-type": "text/html; charset=utf-8" |
| 91 | + } |
| 92 | + }); |
| 93 | +} |
0 commit comments