Files
folio/server/middleware/curl.ts
T

132 lines
4.6 KiB
TypeScript
Raw Normal View History

2026-06-14 17:29:58 -05:00
import chalk from 'chalk';
2026-06-15 23:41:53 -05:00
function box(def: {
title: string;
text: string;
footer?: [string, string];
padding?: [number, number];
}) {
const [LINE_WIDTH_PADDING, LINE_HEIGHT_PADDING] = def.padding ?? [0, 0];
const lineHeight = def.text.split('\n').length;
const lineWidth = def.text
.split('\n')
.reduce((agg, cur) => Math.max(agg, cur.length), 0);
let rendered =
chalk.dim(`${GLYPHS.BOX.ROUND.TOP_LEFT}${GLYPHS.BOX.ROUND.XEDGE}`) +
chalk.reset(` ${def.title} `) +
chalk.dim(
`${GLYPHS.BOX.ROUND.XEDGE.repeat(lineWidth - def.title.length - 3 + LINE_WIDTH_PADDING * 2)}${GLYPHS.BOX.ROUND.TOP_RIGHT}\n`,
);
rendered += (
chalk.dim(GLYPHS.BOX.ROUND.YEDGE) +
`${' '.repeat(LINE_WIDTH_PADDING)}${' '.repeat(lineWidth)}${' '.repeat(LINE_WIDTH_PADDING)}` +
chalk.dim(GLYPHS.BOX.ROUND.YEDGE) +
'\n'
).repeat(LINE_HEIGHT_PADDING);
for (const line of def.text.split('\n')) {
const padding = lineWidth - line.length;
rendered +=
chalk.dim(GLYPHS.BOX.ROUND.YEDGE) +
`${' '.repeat(LINE_WIDTH_PADDING)}${line}${' '.repeat(padding)}${' '.repeat(LINE_WIDTH_PADDING)}` +
chalk.dim(GLYPHS.BOX.ROUND.YEDGE) +
'\n';
}
rendered += (
chalk.dim(GLYPHS.BOX.ROUND.YEDGE) +
`${' '.repeat(LINE_WIDTH_PADDING)}${' '.repeat(lineWidth)}${' '.repeat(LINE_WIDTH_PADDING)}` +
chalk.dim(GLYPHS.BOX.ROUND.YEDGE) +
'\n'
).repeat(LINE_HEIGHT_PADDING);
rendered += chalk.dim(
`${GLYPHS.BOX.ROUND.BOTTOM_LEFT}${GLYPHS.BOX.ROUND.XEDGE.repeat(lineWidth + LINE_WIDTH_PADDING * 2)}${GLYPHS.BOX.ROUND.BOTTOM_RIGHT}`,
);
if (def.footer) {
rendered += '\n\n';
const [left, right] = def.footer;
const padding = lineWidth - left.length - right.length;
rendered += chalk.dim(
`${' '.repeat(LINE_WIDTH_PADDING)} ${left}${' '.repeat(padding)}${right} ${' '.repeat(LINE_WIDTH_PADDING)}`,
);
}
return rendered;
}
2026-06-14 17:29:58 -05:00
export default defineEventHandler(async (event) => {
const userAgent = getRequestHeader(event, 'user-agent') || '';
if (userAgent.startsWith('curl/')) {
const path = event.path;
if (path === '/') {
setResponseHeader(
event,
'content-type',
'text/plain; charset=utf-8',
);
2026-06-15 23:41:53 -05:00
let res = '\n';
res += `\
░█░█░█▀▀░█░░░█░░░█▀█░░░░░░░▀█▀░▀░█▄█░░░▀▀█░█▀█░█▀▄░█▀█░█▀█
░█▀█░█▀▀░█░░░█░░░█░█░░░░░░░░█░░░░█░█░░░░░█░█▀█░█▀▄░█░█░█░█
░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀▀▀░▄▀░░░░▀▀▀░░░▀░▀░░░▀▀░░▀░▀░▀░▀░▀▀▀░▀░▀\n`;
res += '\n';
res += box({
title: 'About',
text: `\
2026-08-20 19:46:10 -05:00
I left school, my job, and moved to Austin in 2022 to write code full time.
2026-08-20 19:37:10 -05:00
That was definitely one of the best and most life changing decisions I've ever made.
I've learned a lot since then and still have much more to learn.
2026-06-15 23:41:53 -05:00
2026-08-20 19:37:10 -05:00
These days I build things because I find joy in making something someone else really enjoys using.
I get excited about reaching a level of polish that users don't even notice.
2026-08-21 09:00:52 -05:00
In a time where code is cheap I pride myself in taste and execution.
2026-08-20 19:37:10 -05:00
The best sticking point — in my limited opinion so far — is the way using your product feels.
So I want everything I make to simply feel the best to use.
2026-06-15 23:41:53 -05:00
If you want to build something cool or connect hit me up
2026-06-22 01:03:47 -05:00
we'll grab a coffee or beer in you're in Austin! 🤠🦇
Also check out some of my work at https://jaron.sh`,
2026-08-20 19:37:10 -05:00
2026-06-15 23:41:53 -05:00
footer: ['Austin, TX', 'yo@jp.wtf'],
padding: [2, 1],
});
const padding = chalk.reset(' ');
2026-06-14 17:29:58 -05:00
return (
2026-06-15 23:41:53 -05:00
res
.split('\n')
.map((l) => padding + l)
.join('\n') + '\n'
2026-06-14 17:29:58 -05:00
);
}
}
});
2026-06-15 23:41:53 -05:00
const GLYPHS = {
BOX: {
DEFAULT: {
TOP_LEFT: '┌',
TOP_RIGHT: '┐',
BOTTOM_LEFT: '└',
BOTTOM_RIGHT: '┘',
XEDGE: '─',
YEDGE: '│',
},
ROUND: {
TOP_LEFT: '╭',
TOP_RIGHT: '╮',
BOTTOM_LEFT: '╰',
BOTTOM_RIGHT: '╯',
XEDGE: '─',
YEDGE: '│',
},
},
};