Skip to content

Commit e18595a

Browse files
Merge pull request #15 from depatchedmode/v0.6.0
feat: text input #14
2 parents c3f7dbe + abfcc1f commit e18595a

File tree

10 files changed

+70
-735
lines changed

10 files changed

+70
-735
lines changed

api/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import landingPage from '../src/landing-page';
22
import frames from '../src/frames';
33
import { parseRequest, objectToURLSearchParams } from '../modules/utils';
44
import buildButtons from '../modules/buildButtons';
5+
import buildInputs from '../modules/buildInputs';
56
import getTargetFrame from '../modules/getTargetFrame';
67
import { validateMessage } from '../src/data/message';
78

@@ -16,6 +17,7 @@ export default async (req, context) => {
1617
from = requestURL.searchParams.get('frame');
1718
buttonId = payload.untrustedData?.buttonIndex;
1819
isOriginal = isOriginalCast(payload.untrustedData.castId.hash);
20+
payload.referringFrame = from;
1921
payload.validData = await validateMessage(payload.trustedData.messageBytes);
2022
}
2123

@@ -58,7 +60,8 @@ const respondWithFrame = async (frameName, frameSrc, payload) => {
5860

5961
const frameContent = {
6062
image: ``,
61-
buttons: buildButtons(frameSrc.buttons),
63+
buttons: frameSrc.buttons ? buildButtons(frameSrc.buttons) : [],
64+
inputs: frameSrc.inputs ? buildInputs(frameSrc.inputs) : [],
6265
postURL: `${host}?frame=${frameName}`
6366
}
6467

modules/buildButtons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export default (buttons) => {
22
return buttons
33
.map((button, index) => {
4-
let buttonMarkup = `<meta property="fc:frame:button:${index + 1}" content="${button.label}" />`;
4+
let buttonMarkup = `<meta name="fc:frame:button:${index + 1}" content="${button.label}" />`;
55
if (button.url) {
6-
buttonMarkup += `\n<meta property="fc:frame:button:${index + 1}:action" content="post_redirect" />`
6+
buttonMarkup += `\n<meta name="fc:frame:button:${index + 1}:action" content="post_redirect" />`
77
}
88
return buttonMarkup;
99
})

modules/buildInputs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import buildTextInput from "./buildTextInput";
2+
3+
export default (inputs) => {
4+
return inputs
5+
.map((input, index) => {
6+
switch (input.type) {
7+
case 'text':
8+
return buildTextInput(input);
9+
}
10+
})
11+
.join('\n');
12+
}

modules/buildTextInput.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default (input) => {
2+
return `<meta name="fc:frame:input:text" content="${input.content}" />`;
3+
}

modules/safeDecode.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { JSDOM } from 'jsdom';
2+
import DOMPurify from 'dompurify';
3+
4+
export default (inputText) => {
5+
try {
6+
const decodedInputText = atob(inputText);
7+
const window = new JSDOM('').window;
8+
const purify = DOMPurify(window);
9+
return purify.sanitize(decodedInputText);
10+
} catch {
11+
throw new Error(`That ain't no encoded string mfr`)
12+
}
13+
}

0 commit comments

Comments
 (0)