Skip to content

Commit

Permalink
functions: convert all of them to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
myhro committed Mar 26, 2023
1 parent 3e667bc commit f0ce2e7
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion functions/dl/[[path]].js → functions/dl/[[path]].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export async function onRequestGet({ request }) {
import type { EventContext } from '@cloudflare/workers-types';

export async function onRequestGet({
request,
}: EventContext<unknown, string, unknown>) {
const url = new URL(request.url);
const path = url.pathname.replace(/^\/dl\//, '');
const target = `https://pub-5f2914f703904c419629da4d1ac2436f.r2.dev/${path}`;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion functions/heroku/index.js → functions/heroku/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { adjs } from './adjs';
import { nouns } from './nouns';

function randint(n) {
function randint(n: number) {
return Math.floor(Math.random() * n);
}

Expand Down
File renamed without changes.
6 changes: 5 additions & 1 deletion functions/ip/index.js → functions/ip/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export async function onRequestGet({ request }) {
import type { EventContext } from '@cloudflare/workers-types';

export async function onRequestGet({
request,
}: EventContext<unknown, string, unknown>) {
const country = request.headers.get('cf-ipcountry');
const ip = request.headers.get('cf-connecting-ip');
const ua = request.headers.get('user-agent');
Expand Down
6 changes: 5 additions & 1 deletion functions/u/[slug].js → functions/u/[slug].ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export async function onRequestGet({ params }) {
import type { EventContext } from '@cloudflare/workers-types';

export async function onRequestGet({
params,
}: EventContext<unknown, string, unknown>) {
const target = `https://pub-5f2914f703904c419629da4d1ac2436f.r2.dev/urls/${params.slug}.txt`;
const response = await fetch(target);
if (response.status === 404) {
Expand Down

0 comments on commit f0ce2e7

Please sign in to comment.