Skip to content

Commit

Permalink
add types to server and load functions
Browse files Browse the repository at this point in the history
  • Loading branch information
secondl1ght committed Dec 23, 2023
1 parent fc35d85 commit b98475c
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
9 changes: 5 additions & 4 deletions src/routes/add-location/endpoint/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import crypto from 'crypto';
import type { RequestHandler } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

const used: string[] = [];
// @ts-expect-error
export async function POST({ request }) {

export const POST: RequestHandler = async ({ request }) => {
const headers = {
Authorization: `Bearer ${GITHUB_API_KEY}`,
Accept: 'application/vnd.github+json'
Expand Down Expand Up @@ -44,7 +45,7 @@ export async function POST({ request }) {

// if honey field has value return
if (honey) {
return;
error(418);
}

// verify that captcha is correct
Expand Down Expand Up @@ -129,4 +130,4 @@ If you are a new contributor please read our Tagging Instructions [here](https:/
});

return new Response(JSON.stringify(github));
}
};
8 changes: 4 additions & 4 deletions src/routes/boost/invoice/generate/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { LNBITS_API_KEY, LNBITS_URL } from '$env/static/private';
import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import type { RequestHandler } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

// generate and return invoice
// @ts-expect-error
export async function GET({ url }) {
export const GET: RequestHandler = async ({ url }) => {
const amount = url.searchParams.get('amount');
const name = url.searchParams.get('name');
const time = url.searchParams.get('time');
Expand All @@ -23,7 +23,7 @@ export async function GET({ url }) {
{
out: false,
amount: `${amount}`,
memo: `BTC Map boost ${name} for ${time} month${time > 1 ? 's' : ''}`,
memo: `BTC Map boost ${name} for ${time} month${Number(time) > 1 ? 's' : ''}`,
unit: 'sat'
},
{ headers }
Expand All @@ -37,4 +37,4 @@ export async function GET({ url }) {
});

return new Response(JSON.stringify(invoice));
}
};
6 changes: 3 additions & 3 deletions src/routes/boost/invoice/status/+server.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { LNBITS_API_KEY, LNBITS_URL } from '$env/static/private';
import { error } from '@sveltejs/kit';
import axios from 'axios';
import type { RequestHandler } from './$types';

// check the status of an invoice
// @ts-expect-error
export async function GET({ url }) {
export const GET: RequestHandler = async ({ url }) => {
const hash = url.searchParams.get('hash');

const headers = {
Expand All @@ -23,4 +23,4 @@ export async function GET({ url }) {
});

return new Response(JSON.stringify(status));
}
};
10 changes: 5 additions & 5 deletions src/routes/boost/post/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { BTCMAP_KEY } from '$env/static/private';
import { error, json } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import type { RequestHandler } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

const used: string[] = [];

// @ts-expect-error
export async function POST({ request }) {
export const POST: RequestHandler = async ({ request }) => {
const headers = {
Authorization: `Bearer ${BTCMAP_KEY}`
};
Expand All @@ -18,12 +18,12 @@ export async function POST({ request }) {
// check that time is valid
const validTimes = [1, 3, 12];
if (!validTimes.includes(time)) {
return;
error(418);
}

// verify that the invoice has been paid
if (used.includes(hash)) {
return;
error(418);
}

const boost = await axios
Expand Down Expand Up @@ -76,4 +76,4 @@ export async function POST({ request }) {
});

return json({ status: boost });
}
};
8 changes: 4 additions & 4 deletions src/routes/communities/add/endpoint/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import crypto from 'crypto';
import type { RequestHandler } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

const used: string[] = [];

// @ts-expect-error
export async function POST({ request }) {
export const POST: RequestHandler = async ({ request }) => {
const headers = {
Authorization: `Bearer ${GITHUB_API_KEY}`,
Accept: 'application/vnd.github+json'
Expand All @@ -30,7 +30,7 @@ export async function POST({ request }) {

// if honey field has value return
if (honey) {
return;
error(418);
}

// verify that captcha is correct
Expand Down Expand Up @@ -80,4 +80,4 @@ Created at: ${new Date(Date.now()).toISOString()}`,
});

return new Response(JSON.stringify(github));
}
};
6 changes: 3 additions & 3 deletions src/routes/community/[area]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { GITHUB_API_KEY } from '$env/static/private';
import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import type { PageServerLoad } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

// @ts-expect-error
export async function load({ params }) {
export const load: PageServerLoad = async ({ params }) => {
const { area } = params;
try {
const response = await axios.get(`https://api.btcmap.org/v2/areas/${area}`);
Expand Down Expand Up @@ -39,4 +39,4 @@ export async function load({ params }) {
} catch (err) {
error(404, 'Community Not Found');
}
}
};
7 changes: 3 additions & 4 deletions src/routes/map/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { redirect } from '@sveltejs/kit';
import type { LayoutServerLoad } from './$types';

/** @type {import('./$types').LayoutServerLoad} */
// @ts-expect-error
export function load({ url }) {
export const load: LayoutServerLoad = ({ url }) => {
// redirect to communities map if params match
const community = url.searchParams.get('community');
const organization = url.searchParams.get('organization');
Expand All @@ -27,4 +26,4 @@ export function load({ url }) {
redirect(301, '/communities/map');
break;
}
}
};
6 changes: 3 additions & 3 deletions src/routes/merchant/[id]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import type { PageLoad } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

// @ts-expect-error
export async function load({ params }) {
export const load: PageLoad = async ({ params }) => {
const { id } = params;
try {
const response = await axios.get(`https://api.btcmap.org/v2/elements/${id}`);
Expand All @@ -21,4 +21,4 @@ export async function load({ params }) {
} catch (err) {
error(404, 'Merchant Not Found');
}
}
};
6 changes: 3 additions & 3 deletions src/routes/tagger/[id]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import type { PageLoad } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

// @ts-expect-error
export async function load({ params }) {
export const load: PageLoad = async ({ params }) => {
const { id } = params;
try {
const response = await axios.get(`https://api.btcmap.org/v2/users/${id}`);
Expand All @@ -18,4 +18,4 @@ export async function load({ params }) {
} catch (err) {
error(404, 'User Not Found');
}
}
};
8 changes: 4 additions & 4 deletions src/routes/verify-location/endpoint/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { error } from '@sveltejs/kit';
import axios from 'axios';
import axiosRetry from 'axios-retry';
import crypto from 'crypto';
import type { RequestHandler } from './$types';

axiosRetry(axios, { retries: 3, retryDelay: axiosRetry.exponentialDelay });

const used: string[] = [];

// @ts-expect-error
export async function POST({ request }) {
export const POST: RequestHandler = async ({ request }) => {
const headers = {
Authorization: `Bearer ${GITHUB_API_KEY}`,
Accept: 'application/vnd.github+json'
Expand All @@ -36,7 +36,7 @@ export async function POST({ request }) {

// if honey field has value return
if (honey) {
return;
error(418);
}

// verify that captcha is correct
Expand Down Expand Up @@ -105,4 +105,4 @@ If you are a new contributor please read our Tagging Instructions [here](https:/
});

return new Response(JSON.stringify(github));
}
};

0 comments on commit b98475c

Please sign in to comment.