Skip to content

Commit

Permalink
chore: add pages worker
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei0x309 committed Sep 19, 2024
1 parent 45a54be commit 58af889
Show file tree
Hide file tree
Showing 12 changed files with 1,184 additions and 167 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ yarn-error.log*
.turbo
**/dist/**
**/node_modules/**

# cloudflare
.wrangler
64 changes: 24 additions & 40 deletions apps/yup-live-mobile/src/views/CrossPostModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div
class="glassCard rounded-lg p-4 flex flex-col md:ml-auto w-full mt-4 relative shadow-md"
>
<template v-if="modalContent == 'posting'">
<div v-show="modalContent == 'posting'">
<div v-if="intialPlatforms?.length > 1" class="block my-4">
<ion-checkbox
v-for="platfrom of userPlatforms"
Expand Down Expand Up @@ -245,8 +245,8 @@
/>Send
</button>
</div>
</template>
<template v-else-if="modalContent == 'scheduling'">
</div>
<template v-if="modalContent == 'scheduling'">
<h2 class="text-lg mb-1 font-medium title-font">Schedule Post</h2>
<p>
<DateIcon /> Maximum allowed date:
Expand All @@ -272,39 +272,10 @@
picker-format="MMM DD, YYYY HH:mm"
/>
</section>
<button
:v-if="intialPlatforms?.length > 1 && showFcChannel"
class="w-1/3 ml-1 bg-stone-600 border-0 py-2 px-6 focus:outline-none hover:bg-stone-700 rounded text-lg"
@click="
() => {
if (farcasterChannel) {
farcasterChannel = undefined;
} else {
modalContent = 'selectFatscasterChannel';
}
}
"
>
<img
v-if="farcasterChannel"
:src="
typeof farcasterChannel === 'object'
? farcasterChannel.image_url
: undefined
"
class="w-5 inline mr-2"
/>
<ProfileFarcasterIcon v-else class="w-5 inline mr-2" />
{{
farcasterChannel
? "Remove farcaster channel"
: "Add farcaster channel"
}}
</button>
<div class="flex justify-between">
<button
:disabled="isSheduling"
class="text-[0.9rem] w-1/2 mr-1 bg-stone-600 border-0 py-2 px-6 focus:outline-none hover:bg-stone-700 rounded text-lg"
class="text-[0.9rem] w-1/2 mr-1 bg-stone-600 border-0 py-2 px-2 focus:outline-none hover:bg-stone-700 rounded text-lg"
@click="modalContent = 'posting'"
>
<BtnSpinner v-if="isSheduling" class="inline mr-2" /><GoToIcon
Expand All @@ -328,15 +299,27 @@
Select Farcaster Channel
</h2>
<p>Search</p>
<input
id="farcasterChannelSearch"
type="text"
placeholder="channel name"
class="mb-4 rounded p-2 text-[#e0e0e0] bg-stone-800 border-purple-800 border-2 w-full"
@input="(e) => {
<div class="flex justify-between">
<input
id="farcasterChannelSearch"
type="text"
placeholder="channel name"
class="mb-4 rounded p-2 text-[#e0e0e0] bg-stone-800 border-purple-800 border-2 w-full"
@input="(e) => {
searchChannels((e?.target as any)?.value)
}"
/>
/>
<button
class="w-1/3 ml-1 bg-stone-600 border-0 py-0 px-6 focus:outline-none hover:bg-stone-700 rounded text-lg h-[2.9rem]"
@click="modalContent = 'posting'"
>
<BtnSpinner
v-if="isChannelSearching"
class="inline mr-2"
/><GoToIcon class="w-3 inline mr-2 rotate-180" />Cancel
</button>
</div>

<div v-if="channels?.length === 0">
<p>No channels found</p>
</div>
Expand Down Expand Up @@ -1012,6 +995,7 @@ export default defineComponent({
mentionsCoords,
mentions,
insertMention,
isChannelSearching,
};
},
});
Expand Down
3 changes: 2 additions & 1 deletion apps/yup-live/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ module.exports = {
'vue/multi-word-component-names': 'off',
'vue/no-v-html': 'off',
'vue/attribute-hyphenation': 'off',
'vue/no-setup-props-destructure': 'off'
'vue/no-setup-props-destructure': 'off',
'no-explicit-any': 'off'
},
ignorePatterns: ['**/node_modules/**', 'dist/**', 'public/**']
}
7 changes: 6 additions & 1 deletion apps/yup-live/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
"lint": "eslint --ext .ts,.vue --ignore-path .gitignore --fix src&&prettier . -w -u",
"build-no-ssg": "vite build",
"build-ssg": "vite-ssg build",
"build-worker": "npx wrangler deploy worker/worker.ts --dry-run --outdir dist --name worker --compatibility-date 2024-09-19 --node-compat true",
"move-worker": "bun run worker/bun-move-worker.ts",
"encrypt": "node ./scripts/build-encrypt.mjs --env-file=.env",
"preview": "vite preview",
"build": "yarn build-ssg"
"build": "yarn build-ssg && yarn build-worker && yarn move-worker"
},
"husky": {
"hooks": {
Expand All @@ -22,6 +24,7 @@
"*": "prettier -w -u"
},
"dependencies": {
"@airstack/frames": "^1.2.0",
"@ethersproject/abstract-signer": "^5.7.0",
"@noble/hashes": "^1.3.0",
"@oruga-ui/oruga-next": "^0.7.0",
Expand All @@ -46,6 +49,7 @@
"vue-router": "^4.2.5"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240909.0",
"@types/d3": "^7.4.0",
"@types/node": "^18.19.6",
"@types/video.js": "^7.3.56",
Expand All @@ -56,6 +60,7 @@
"@vue/eslint-config-prettier": "^7.1.0",
"@vue/eslint-config-typescript": "^11.0.3",
"autoprefixer": "^10.4.16",
"dotenv": "^16.4.5",
"eslint": "^8.56.0",
"eslint-config-mourner": "^3.0.0",
"eslint-config-prettier": "^8.10.0",
Expand Down
30 changes: 20 additions & 10 deletions apps/yup-live/src/components/content/post/crossPost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -307,15 +307,25 @@
Select Farcaster Channel
</h2>
<p>Search</p>
<input
id="farcasterChannelSearch"
type="text"
placeholder="channel name"
class="mb-4 rounded p-2 text-[#e0e0e0] bg-stone-800 border-purple-800 border-2"
@input="(e) => {
<div class="flex justify-between">
<input
id="farcasterChannelSearch"
type="text"
placeholder="channel name"
class="mb-4 rounded p-2 text-[#e0e0e0] bg-stone-800 border-purple-800 border-2 w-full"
@input="(e) => {
searchChannels((e?.target as any)?.value)
}"
/>
/>
<button
class="w-1/3 ml-1 bg-stone-600 border-0 py-0 px-6 focus:outline-none hover:bg-stone-700 rounded text-lg h-[2.9rem]"
@click="modalContent = 'posting'"
>
<BtnSpinner v-if="isChannelSearching" class="inline mr-2" /><GoToIcon
class="w-3 inline mr-2 rotate-180"
/>Cancel
</button>
</div>
<div v-if="channels?.length === 0">
<p>No channels found</p>
</div>
Expand Down Expand Up @@ -520,7 +530,7 @@ export default defineComponent({
let searchTerm = "";
do {
searchTerm = searchString;
result = await searchChannel(searchString);
result = (await searchChannel(searchString)) as TChannel[];
} while (searchTerm !== searchString);
channels.value = result;
isChannelSearching.value = false;
Expand Down Expand Up @@ -588,7 +598,7 @@ export default defineComponent({
if (!imageFile) return;
isFileUploading.value = true;
const imageBase64 = await fileToBase64(imageFile);
const upload = await mediaUpload(store, postPlatforms.value, imageFile);
const upload = (await mediaUpload(store, postPlatforms.value, imageFile)) as any;
if (upload?.errors) {
const platforms = [] as TPlatform[];
Expand Down Expand Up @@ -637,7 +647,7 @@ export default defineComponent({
);
postPlatforms.value = postPlatforms.value.filter((p) => p !== "bsky");
}
const upload = await mediaUpload(store, postPlatforms.value, videoFile);
const upload = (await mediaUpload(store, postPlatforms.value, videoFile)) as any;
if (upload?.errors) {
const platforms = [] as TPlatform[];
for (const error of upload.errors) {
Expand Down
4 changes: 3 additions & 1 deletion apps/yup-live/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"types": ["@cloudflare/workers-types/2023-07-01"]
},
"include": [
"./src/**/*.js",
Expand All @@ -24,6 +25,7 @@
"./src/**/*.tsx",
"./src/**/*.vue",
"./src/**/*.vue",
"./worker/**/*.ts",
"../../packages/icons/src/**/*.vue",
"../../packages/shared/src/**/*.*",
"../../packages/components/**/*.vue"
Expand Down
6 changes: 6 additions & 0 deletions apps/yup-live/worker/bun-move-worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

import { unlinkSync } from "node:fs";
const path = "dist/worker.js";
const file = Bun.file(path);
await Bun.write("dist/_worker.js", file);
unlinkSync(path);
19 changes: 19 additions & 0 deletions apps/yup-live/worker/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface T_FRAME_API_BODY {
untrustedData: {
fid: number
url: string
messageHash: string
timestamp: number
network: number
buttonIndex: number
inputText: string
castId: {
fid: number
hash: string
}
state: string
}
trustedData: {
messageBytes: string
}
}
18 changes: 18 additions & 0 deletions apps/yup-live/worker/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
validateFramesMessage as verifyMessageWithAirstack,
ValidateFramesMessageInput,
init
} from '@airstack/frames'

import type { T_FRAME_API_BODY } from './types'


export const verifyMessage = async (body: T_FRAME_API_BODY, AIRSTACK_KEY: string): Promise<{ valid: boolean }> => {
try {
init(AIRSTACK_KEY)
const verify = await verifyMessageWithAirstack(body as ValidateFramesMessageInput)
return { valid: verify.isValid }
} catch (e) {
return { valid: false }
}
}
44 changes: 44 additions & 0 deletions apps/yup-live/worker/worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable no-undef */
import type { T_FRAME_API_BODY } from './types'


interface Env {
ASSETS: Fetcher;
AIRSTACK_KEY: string;
}

export default {
async fetch (request, env): Promise<Response> {
const url = new URL(request.url);
if (url.pathname.startsWith('/api/miniapp')) {
// get url from query
const url = new URL(request.url);
const query = url.searchParams;
const urlToFetch = query.get('url');

// check if method is POST
if (request.method === 'POST') {
const body = await request.json() as T_FRAME_API_BODY;
const { verifyMessage } = await import('./utils')

verifyMessage(body, env.AIRSTACK_KEY)
}

const jsonToSend = {
"type": "form",
"title": "Yup Link",
"url": urlToFetch,
}

return new Response(JSON.stringify(jsonToSend), {
headers: {
'Content-Type': 'application/json',
},
});

}
// Otherwise, serve the static assets.
// Without this, the Worker will error and no assets will be served.
return env.ASSETS.fetch(request);
},
} satisfies ExportedHandler<Env>;
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
},
"engines": {
"node": ">=16.0.0"
},
"dependencies": {
"wrangler": "^3.78.5"
}
}
Loading

0 comments on commit 58af889

Please sign in to comment.