mirror of
https://github.com/vbalien/voca.git
synced 2025-12-06 11:26:21 +09:00
add index.html
This commit is contained in:
51
index.html
Normal file
51
index.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
<head>
|
||||
<title>Voca</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/generate">
|
||||
<fieldset>
|
||||
<legend>시험 난이도</legend>
|
||||
<div>
|
||||
<input type="checkbox" id="10" name="level" value="10">
|
||||
<label for="10">전체 난이도</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="6" name="level" value="6" checked>
|
||||
<label for="6">입문반(550+), 기본반(650+)</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="7" name="level" value="7" checked>
|
||||
<label for="7">중급반(750+)</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="8" name="level" value="8">
|
||||
<label for="8">정규반(850+)</label>
|
||||
</div>
|
||||
<div>
|
||||
<input type="checkbox" id="9" name="level" value="9">
|
||||
<label for="9">실전반(900+)</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div>
|
||||
<label for="day">범위<label>
|
||||
<select id="day" name="day">
|
||||
<script>
|
||||
for (let i=1;i<=30;++i)
|
||||
document.write(`<option value="${i}">${i}</option>`);
|
||||
</script>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<button type="submit">PDF 다운</button>
|
||||
</div>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
78
main.ts
78
main.ts
@@ -11,16 +11,18 @@ type Result = {
|
||||
answer: string;
|
||||
};
|
||||
|
||||
async function generateVoca(level: number, day: number) {
|
||||
async function generateVoca(levels: number[], day: number) {
|
||||
const re =
|
||||
/<p class="word">(?<id>\d+?)\. (?<word>.+?)<\/p>.*?<span class="af_answer">(?<answer>.+?)<\/span>/gis;
|
||||
const res = await fetch(
|
||||
`https://www.hackers.co.kr/?c=s_toeic/new_voca_toeic_testpaper/toeic_study/new_paper&mode=new_view&level=${level}&level_type=&lang_text=2&question=1000&day3=${day}&day4=${day}&day_auto=N&index=1`,
|
||||
`https://www.hackers.co.kr/?c=s_toeic/new_voca_toeic_testpaper/toeic_study/new_paper&mode=new_view&level=${
|
||||
levels.join(",")
|
||||
}&level_type=&lang_text=2&question=1000&day3=${day}&day4=${day}&day_auto=N&index=1`,
|
||||
);
|
||||
|
||||
const body = (await res.text());
|
||||
const body = await res.text();
|
||||
const matches = [...body.matchAll(re)].map((m) => ({
|
||||
...m.groups as unknown as Result,
|
||||
...(m.groups as unknown as Result),
|
||||
id: Number.parseInt(m.groups?.id as string),
|
||||
}));
|
||||
|
||||
@@ -52,15 +54,15 @@ async function generateVoca(level: number, day: number) {
|
||||
yCursor = 1;
|
||||
}
|
||||
page.drawText(`${data.id}. ${data.word}`, {
|
||||
x: margin + (page.getWidth() / 2 * col),
|
||||
y: page.getHeight() - (fontSize + margin) * (yCursor),
|
||||
x: margin + (page.getWidth() / 2) * col,
|
||||
y: page.getHeight() - (fontSize + margin) * yCursor,
|
||||
size: fontSize,
|
||||
font: customFont,
|
||||
color: rgb(0, 0, 0),
|
||||
});
|
||||
page.drawText("_________________", {
|
||||
x: margin + (page.getWidth() / 2 * col) + 140,
|
||||
y: page.getHeight() - (fontSize + margin) * (yCursor) - 3,
|
||||
x: margin + (page.getWidth() / 2) * col + 140,
|
||||
y: page.getHeight() - (fontSize + margin) * yCursor - 3,
|
||||
size: fontSize,
|
||||
font: customFont,
|
||||
color: rgb(0, 0, 0),
|
||||
@@ -81,23 +83,23 @@ async function generateVoca(level: number, day: number) {
|
||||
yCursor = 1;
|
||||
}
|
||||
page.drawText(`${data.id}. ${data.word}`, {
|
||||
x: margin + (page.getWidth() / 2 * col),
|
||||
y: page.getHeight() - (fontSize + margin) * (yCursor),
|
||||
x: margin + (page.getWidth() / 2) * col,
|
||||
y: page.getHeight() - (fontSize + margin) * yCursor,
|
||||
size: fontSize,
|
||||
font: customFont,
|
||||
color: rgb(0, 0, 0),
|
||||
});
|
||||
page.drawText("_________________", {
|
||||
x: margin + (page.getWidth() / 2 * col) + 140,
|
||||
y: page.getHeight() - (fontSize + margin) * (yCursor) - 3,
|
||||
x: margin + (page.getWidth() / 2) * col + 140,
|
||||
y: page.getHeight() - (fontSize + margin) * yCursor - 3,
|
||||
size: fontSize,
|
||||
font: customFont,
|
||||
color: rgb(0, 0, 0),
|
||||
});
|
||||
page.drawText(data.answer, {
|
||||
x: margin + (page.getWidth() / 2 * col) + 140,
|
||||
y: page.getHeight() - (fontSize + margin) * (yCursor),
|
||||
size: fontSize,
|
||||
x: margin + (page.getWidth() / 2) * col + 140,
|
||||
y: page.getHeight() - (fontSize + margin) * yCursor,
|
||||
size: 8,
|
||||
font: customFont,
|
||||
color: rgb(1, 0, 0),
|
||||
});
|
||||
@@ -121,25 +123,41 @@ for await (const conn of server) {
|
||||
async function serveHttp(conn: Deno.Conn) {
|
||||
const httpConn = Deno.serveHttp(conn);
|
||||
for await (const requestEvent of httpConn) {
|
||||
const url = new URL(requestEvent.request.url);
|
||||
const { searchParams, pathname } = new URL(requestEvent.request.url);
|
||||
|
||||
if (pathname.startsWith("/generate")) {
|
||||
if (!searchParams.has("level") || !searchParams.has("day")) {
|
||||
requestEvent.respondWith(
|
||||
new Response("Not Found", {
|
||||
status: 404,
|
||||
}),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
const levels = searchParams.getAll("level").map((l) =>
|
||||
Number.parseInt(l)
|
||||
);
|
||||
const day = Number.parseInt(searchParams.get("day")!) ?? 1;
|
||||
const data = await generateVoca(levels, day);
|
||||
|
||||
if (!url.searchParams.has("level") || !url.searchParams.has("day")) {
|
||||
requestEvent.respondWith(
|
||||
new Response("Not Found", {
|
||||
status: 404,
|
||||
new Response(data, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Disposition": 'attachment; filename="voca.pdf"',
|
||||
},
|
||||
}),
|
||||
);
|
||||
} else if (pathname.startsWith("/") || pathname.startsWith("/index.html")) {
|
||||
const file = await Deno.readFile("./index.html");
|
||||
requestEvent.respondWith(
|
||||
new Response(file, {
|
||||
headers: {
|
||||
"content-type": "text/html",
|
||||
},
|
||||
}),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const level = Number.parseInt(url.searchParams.get("level")!) ?? 7;
|
||||
const day = Number.parseInt(url.searchParams.get("day")!) ?? 1;
|
||||
const data = await generateVoca(level, day);
|
||||
|
||||
requestEvent.respondWith(
|
||||
new Response(data, {
|
||||
status: 200,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user