Skip to content

Commit

Permalink
Update function
Browse files Browse the repository at this point in the history
  • Loading branch information
qwtel committed Sep 7, 2024
1 parent d32bd39 commit 8b73b03
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ nbproject

# Folders to ignore
node_modules
package*.json
package-lock.json
vendor
.sass-cache
.jekyll-metadata
Expand Down
7 changes: 4 additions & 3 deletions functions/api/ping.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference types="@cloudflare/workers-types/2023-07-01" />

import qs from 'qs';

const SellerID = 'MzsHym72gcntzEb5BQygpQ==';
const ProductId = 'nuOluY';

Expand All @@ -21,8 +23,7 @@ export const onRequestPost: PagesFunction<Env> = async (context) => {
console.error("Invalid content-type", request.headers.get('content-type'));
return new Response(null, { status: 400 });
}
const formData = await request.formData();
const payload = Object.fromEntries(formData);
const payload = qs.parse(await request.text())
console.debug("payload", payload);

if (payload.seller_id !== SellerID) {
Expand All @@ -39,7 +40,7 @@ export const onRequestPost: PagesFunction<Env> = async (context) => {
}
console.debug("payload.custom_fields", payload.custom_fields);

const customFields = payload.custom_fields && JSON.parse(payload.custom_fields as string) as Record<string, string>|undefined|null;
const customFields = payload.custom_fields as Record<string, string>|null;
const githubHandle = customFields && Object.entries(customFields).find(([k]) => k.trim().toLowerCase().startsWith('github'))?.[1];
console.debug("githubHandle", githubHandle);

Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"dependencies": {
"qs": "^6.13.0",
"re-template-tag": "^2.0.1"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240903.0",
"@types/qs": "^6.9.15"
}
}

0 comments on commit 8b73b03

Please sign in to comment.