Skip to content

Commit 9b43375

Browse files
committed
Add unban cron
1 parent 1aa8b0a commit 9b43375

File tree

2 files changed

+30
-15
lines changed

2 files changed

+30
-15
lines changed

apps/crons/src/index.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Logger } from "@echo-webkom/logger";
33
import { Email } from "@echo-webkom/email";
44
import { Kroner } from "./kroner";
55
import { createSanity } from "./sanity";
6+
import { escapehtml } from "./utils";
67

78
type Bindings = {
89
RESEND_API_KEY: string;
@@ -71,17 +72,6 @@ kroner.at("0 0 1 7 *", async (c) => {
7172
Logger.info(`Reset ${result.length} users' years`);
7273
});
7374

74-
kroner.at("0 2 * * *", async (c) => {
75-
const response = await fetch("https://echo.uib.no/api/unban", {
76-
method: "POST",
77-
headers: {
78-
Authorization: `Bearer ${c.env.ADMIN_KEY}`,
79-
},
80-
});
81-
82-
Logger.info(`Ping to /api/unban: ${response.status}`);
83-
});
84-
8575
kroner.at("0 2 * * *", async (c) => {
8676
const happenings = await c.vars.sanity.fetch<Array<{ id: string }>>(
8777
`*[_type == "happening" && isPinned == true && defined(registrationEnd) && dateTime(registrationEnd) < dateTime(now())] {
@@ -132,10 +122,10 @@ kroner.at("0 16 * * *", async (c) => {
132122
...feedbacks.map(
133123
(feedback) => `<li>
134124
<div>
135-
<p><strong>${feedback.name ?? "Ukjent"}</strong> (${
136-
feedback.email ?? "Ingen e-post"
137-
})</p>
138-
<p>${feedback.message}</p>
125+
<p><strong>${escapehtml(
126+
feedback.name ?? "Ukjent"
127+
)}</strong> (${escapehtml(feedback.email ?? "Ingen e-post")})</p>
128+
<p>${escapehtml(feedback.message)}</p>
139129
</div>
140130
</li>`
141131
),
@@ -173,6 +163,17 @@ kroner.at("0 2 * * *", async () => {
173163
Logger.info(`Attempted to close bar. Got status, ${response.status}`);
174164
});
175165

166+
kroner.at("0 2 * * *", async () => {
167+
const response = await fetch("https://api.echo-webkom.no/strikes/unban", {
168+
method: "POST",
169+
headers: {
170+
Authorization: `Bearer ${process.env.ADMIN_KEY}`,
171+
},
172+
});
173+
174+
Logger.info(`Attempted to unban users. Got status, ${response.status}`);
175+
});
176+
176177
export default {
177178
fetch: () => {
178179
return new Response("OK", { status: 200 });

apps/crons/src/utils.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export const escapehtml = (str: string) => {
2+
const htmlEscapes = {
3+
"&": "&amp;",
4+
"<": "&lt;",
5+
">": "&gt;",
6+
'"': "&quot;",
7+
"'": "&#39;",
8+
};
9+
10+
return String(str).replace(
11+
/[&<>"']/g,
12+
(match) => htmlEscapes[match as keyof typeof htmlEscapes]
13+
);
14+
};

0 commit comments

Comments
 (0)