Skip to content

Commit

Permalink
feat: hide server url in error message in svg
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Jul 8, 2024
1 parent 7978f78 commit 5d2f498
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 417 deletions.
12 changes: 8 additions & 4 deletions lib/utils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ export function isKroki(alias = []) {

const failImage = new URL('fail.svg', import.meta.url);

function createFailImage(message) {
function createFailImage(server, message) {
console.error(message);

return readFileSync(failImage, 'utf8').replace(
'======',
message.slice(0, 500),
message.replaceAll(server, '$server').slice(0, 500),
);
}

function Fetch({ server, headers, type, value }) {
const serverURL = server.replace(/\/$/, '');

return httpPost({
url: `${server}/${type}/svg`,
url: `${serverURL}/${type}/svg`,
body: value,
headers,
})
.catch((error) => createFailImage(error.message))
.catch((error) => createFailImage(serverURL, error.message))
.then((data) => Buffer.from(data));
}

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-kroki",
"version": "0.3.6",
"version": "0.3.7",
"description": "Remark plugin for showing Kroki diagram",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -50,27 +50,27 @@
},
"dependencies": {
"is-plain-obj": "^4.1.0",
"kebab-case": "^1.0.2",
"kebab-case": "^2.0.1",
"markdown-code-block-meta": "^0.0.2",
"node-fetch": "^3.3.2",
"p-memoize": "^7.1.1",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
"@bring-it/npm": "^0.5.2",
"@nice-move/cli": "^0.11.10",
"@nice-move/eslint-config-base": "^0.11.4",
"@nice-move/prettier-config": "^0.11.3",
"ava": "^6.1.2",
"@bring-it/npm": "^0.5.5",
"@nice-move/cli": "^0.11.13",
"@nice-move/eslint-config-base": "^0.11.10",
"@nice-move/prettier-config": "^0.12.4",
"ava": "^6.1.3",
"eslint": "^8.57.0",
"eslint-plugin-ava": "^14.0.0",
"garou": "^0.7.3",
"prettier": "^3.2.5",
"garou": "^0.7.6",
"prettier": "^3.3.2",
"remark": "^15.0.1",
"remark-mdx": "^3.0.1",
"unist-util-remove-position": "^5.0.0"
},
"packageManager": "pnpm@9.0.5",
"packageManager": "pnpm@9.4.0",
"engines": {
"node": ">=18.0.0 || ^16.13.0"
},
Expand Down
Loading

0 comments on commit 5d2f498

Please sign in to comment.