Skip to content

Commit 2cd5658

Browse files
Merge pull request #26 from depatchedmode/v0.8.2
v0.8.2
2 parents 0b0ec4e + 64e3893 commit 2cd5658

33 files changed

+135
-128
lines changed

.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"plugins": ["@typescript-eslint"],
4+
"env": {
5+
"node": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/recommended",
10+
"prettier"
11+
]
12+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ yarn-error.log*
1414
pnpm-debug.log*
1515
lerna-debug.log*
1616

17+
*.js
18+
1719
# sharp issue: https://sharp.pixelplumbing.com/install#cross-platform
1820
package-lock.json
1921

2022
node_modules
2123
dist
24+
built
2225
dist-ssr
2326
*.local
2427

api/frame.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

api/index.js renamed to api/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { getFrameMessage } from "frames.js"
2-
import landingPage from '../src/landing-page';
3-
import { parseRequest, objectToURLSearchParams } from '../modules/utils';
4-
import buildButtons from '../modules/buildButtons';
5-
import buildInputs from '../modules/buildInputs';
6-
import getTargetFrame from '../modules/getTargetFrame';
1+
import { getFrameMessage } from "frames.js";
2+
import landingPage from '../src/landing-page.js';
3+
import { parseRequest, objectToURLSearchParams } from '../modules/utils.js';
4+
import buildButtons from '../modules/buildButtons.js';
5+
import buildInputs from '../modules/buildInputs.js';
6+
import getTargetFrame from '../modules/getTargetFrame.js';
77

8-
export default async (req, context) => {
8+
export default async (req) => {
99
try {
1010
const requestURL = new URL(req.url);
1111
const payload = await parseRequest(req);
@@ -40,14 +40,15 @@ const respondWithRedirect = (redirectURL) => {
4040
{
4141
status: 302,
4242
headers: {
43-
'Location': internalRedirectURL,
43+
'Location': internalRedirectURL.toString(),
4444
},
4545
}
4646
);
4747
}
4848

4949
const respondWithFrame = async (targetFrame, frameMessage) => {
5050
const searchParams = {
51+
t: new Date().valueOf(),
5152
targetFrameName: targetFrame.name,
5253
frameMessage
5354
}

api/og-image.js renamed to api/og-image.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import satori from "satori";
22
import sharp from "sharp";
33
import { html } from "satori-html";
4-
import fonts from "../src/fonts";
5-
import frames from "../src/frames";
6-
import { URLSearchParamsToObject } from '../modules/utils';
4+
import fonts from "../src/fonts.js";
5+
import frames from "../src/frames/index.js";
6+
import { URLSearchParamsToObject } from '../modules/utils.js';
77

8-
export default async (req, context) => {
8+
export default async (req) => {
99
const url = new URL(req.url);
1010
const params = URLSearchParamsToObject(url.searchParams);
11-
const targetFrame = frames[params.targetFrameName];
12-
const markup = await targetFrame.build(params.frameMessage);
11+
const targetFrame = frames[params['targetFrameName']];
12+
const markup = await targetFrame.build(params['frameMessage']);
1313

1414
const svg = await satori(
1515
html(markup),
1616
{
1717
width: 1200,
1818
height: 630,
19-
fonts
19+
fonts: fonts,
2020
}
2121
);
2222
const svgBuffer = Buffer.from(svg);
File renamed without changes.

modules/antitheft.js renamed to modules/antitheft.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { getStore } from '@netlify/blobs';
2-
import frame from '../api/frame';
32

43
// Utility functions to abstract the fetching and setting operations
54
const fetchData = async (key) => {
65
const store = getStore('antiTheft');
7-
let data = await store.get(key, 'json') || [];
6+
let data = await store.get(key, { type: 'json' } ) || [];
87
if (!data.length) {
98
data = process.env[key] ? JSON.parse(process.env[key]) : [];
109
}
@@ -25,15 +24,15 @@ const setBoundCasts = (castHashes) => setData('BOUND_CAST_HASHES', castHashes);
2524

2625
// Modified functions to use the updated getters and setters
2726
const addToList = async (getter, setter, item) => {
28-
let list = await getter();
27+
const list = await getter();
2928
if (!list.includes(item)) {
3029
list.push(item);
3130
await setter(list);
3231
}
3332
};
3433

3534
const removeFromList = async (getter, setter, item) => {
36-
let list = await getter();
35+
const list = await getter();
3736
const index = list.indexOf(item);
3837
if (index > -1) {
3938
list.splice(index, 1);
@@ -52,10 +51,8 @@ const removeBoundCast = (castHash) => removeFromList(getBoundCasts, setBoundCast
5251
// 2. The castHash is in boundCasts.
5352
// 3. Both boundCasts & boundAccounts are empty.
5453
const isFrameStolen = async (frameMessage) => {
55-
console.log('isFrameStolen', frameMessage);
5654
const { castId, requestURL } = frameMessage;
5755
if (!castId || !requestURL) {
58-
console.log('isFrameStolen:quickExit', castId, requestURL);
5956
return false;
6057
}
6158

@@ -67,11 +64,23 @@ const isFrameStolen = async (frameMessage) => {
6764
const isCastAllowed = boundCasts.includes(castHash) || boundCasts.length === 0;
6865
const isFirstParty = requestURL ? requestURL.indexOf(process.env.URL) > -1 : true;
6966

70-
console.log('isAuthorAllowed', isAuthorAllowed, castAuthorID, boundAccounts);
71-
console.log('isCastAllowed', isCastAllowed, castHash, boundCasts);
72-
console.log('isFirstParty', isFirstParty);
67+
const isStolen = !isFirstParty || !isAuthorAllowed || !isCastAllowed;
7368

74-
return !isFirstParty || !isAuthorAllowed || !isCastAllowed;
69+
// record the theft
70+
if (isStolen) {
71+
const store = getStore('stolenFrames');
72+
const stolenFrame = await store.get(castHash, { type: 'json' }) || {
73+
castHash,
74+
castAuthorID,
75+
views: 0,
76+
firstView: new Date().toUTCString(),
77+
};
78+
stolenFrame.view++;
79+
stolenFrame.lastView = new Date().toUTCString();
80+
store.setJSON(castHash, stolenFrame);
81+
}
82+
83+
return isStolen;
7584
};
7685

7786
export {
File renamed without changes.

modules/buildInputs.js renamed to modules/buildInputs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import buildTextInput from "./buildTextInput";
1+
import buildTextInput from "./buildTextInput.js";
22

33
export default (inputs) => {
44
return inputs
5-
.map((input, index) => {
5+
.map((input) => {
66
switch (input.type) {
77
case 'text':
88
return buildTextInput(input);
File renamed without changes.

0 commit comments

Comments
 (0)