Skip to content

Commit

Permalink
feat: migrate metadata worker to next api
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Nov 17, 2023
1 parent 33f636e commit 20a2708
Show file tree
Hide file tree
Showing 34 changed files with 1,018 additions and 1,391 deletions.
36 changes: 0 additions & 36 deletions .github/workflows/deploy-workers.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ yarn-error.log*
# typescript
*.tsbuildinfo

# cloudflare workers
.wrangler
.dev.vars

# JetBrains IDE
.idea

Expand Down
1 change: 1 addition & 0 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ LENS_IPFS_AUTH_KEY=""
IPAPI_KEY=""
GOOGLE_API_KEY=""
PROPOSAL_CREATOR_PRIVATE_KEY=""
IRYS_PRIVATE_KEY=""
IMAGEKIT_URL=""
1 change: 1 addition & 0 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@hey/data": "workspace:*",
"@hey/lens": "workspace:*",
"@hey/lib": "workspace:*",
"@irys/sdk": "^0.0.4",
"@supabase/supabase-js": "^2.38.4",
"axios": "^1.6.2",
"fast-xml-parser": "^4.3.2",
Expand Down
35 changes: 35 additions & 0 deletions apps/api/pages/api/metadata/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Errors } from '@hey/data/errors';
import { NodeIrys } from '@irys/sdk';
import type { NextApiRequest, NextApiResponse } from 'next';
import allowCors from 'utils/allowCors';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const { body } = req;

if (!body) {
return res.status(400).json({ success: false, error: Errors.NoBody });
}

try {
const url = 'https://node2.irys.xyz';
const token = 'matic';
const client = new NodeIrys({
url,
token,
key: process.env.IRYS_PRIVATE_KEY
});

const receipt = await client.upload(JSON.stringify(body), {
tags: [
{ name: 'content-type', value: 'application/json' },
{ name: 'App-Name', value: 'Hey.xyz' }
]
});

return res.status(200).json({ success: true, id: receipt.id });
} catch (error) {
throw error;
}
};

export default allowCors(handler);
4 changes: 2 additions & 2 deletions apps/web/src/lib/uploadToArweave.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { METADATA_WORKER_URL } from '@hey/data/constants';
import { HEY_API_URL } from '@hey/data/constants';
import { Errors } from '@hey/data/errors';
import axios from 'axios';
import toast from 'react-hot-toast';
Expand All @@ -12,7 +12,7 @@ import toast from 'react-hot-toast';
*/
const uploadToArweave = async (data: any): Promise<string> => {
try {
const upload = await axios.post(METADATA_WORKER_URL, { ...data });
const upload = await axios.post(`${HEY_API_URL}/metadata`, { ...data });
const { id }: { id: string } = upload?.data;

return id;
Expand Down
4 changes: 0 additions & 4 deletions docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ The environment is a set of key-value pairs that are available to the applicatio
## Environment Variables

The environment variables are defined in the `.env` file. The `.env` file is located in the root of the project. The `.env` file is not tracked by git.

## Workers Environment Variables

The Workers environment variables are defined in the `.dev.vars` file. The `.dev.vars` file is located in all workers projects in the `packages/workers` folder. The `.dev.vars` file is not tracked by git.
10 changes: 5 additions & 5 deletions docs/ports.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

The following ports are exposed by the repository

| Port | Description | Local endpoint | Production endpoint |
| ---- | --------------- | --------------------- | ------------------------- |
| 4783 | Web app | http://localhost:4783 | https://hey.xyz |
| 4784 | Prerender app | http://localhost:4784 | https://prerender.hey.xyz |
| 8083 | Metadata worker | http://localhost:8083 | https://metadata.hey.xyz |
| Port | Description | Local endpoint | Production endpoint |
| ---- | ------------- | --------------------- | ------------------------- |
| 4783 | Web app | http://localhost:4783 | https://hey.xyz |
| 4784 | Prerender app | http://localhost:4784 | https://prerender.hey.xyz |
| 4785 | API | http://localhost:4785 | https://api.hey.xyz |
7 changes: 3 additions & 4 deletions docs/tech-stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

## Backend

- [Cloudflare Workers](https://workers.cloudflare.com/) - Serverless platform
- [Next API](https://nextjs.org/docs/api-routes/introduction) - API routes
- [Node.js](https://nodejs.org/en/) - JavaScript runtime

## Telemetry

- [Leafwatch](../packages/workers/leafwatch/README.md) - Telemetry tracking built in-house by Hey
- [Google BigQuery](https://cloud.google.com/bigquery) - Data warehouse to store telemetry data
- [Hex Dashboards](https://hex.tech) - Hex dashboards to visualize telemetry data from BigQuery
- [Clickhouse](https://clickhouse.tech/) - Database for storing telemetry data
- [Metabase](https://www.metabase.com/) - Data visualization tool

## Others

Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"test:dev": "turbo run test:dev",
"test:e2e": "start-server-and-test start '4785' test:dev",
"typecheck": "turbo run typecheck --parallel",
"typecheck:affected": "turbo run typecheck --parallel --filter=[origin/main]",
"workers:deploy": "turbo run worker:deploy --parallel"
"typecheck:affected": "turbo run typecheck --parallel --filter=[origin/main]"
},
"eslintConfig": {
"root": true
Expand Down
5 changes: 0 additions & 5 deletions packages/data/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ export const EVER_API = 'https://endpoint.4everland.co';
export const DEFAULT_OG = `${STATIC_IMAGES_URL}/og/logo.jpeg`;
export const PLACEHOLDER_IMAGE = `${STATIC_IMAGES_URL}/placeholder.webp`;

// Workers (Cloudflare)
export const METADATA_WORKER_URL = IS_PRODUCTION
? 'https://metadata.hey.xyz'
: 'http://localhost:8083';

// Tokens / Keys
export const OPENSEA_KEY = '8b95f9e6d52b42fe8c19ddea847c0f5d';
export const WALLETCONNECT_PROJECT_ID = 'cd542acc70c2b548030f9901a52e70c8';
Expand Down
7 changes: 0 additions & 7 deletions packages/irys/.eslintrc.js

This file was deleted.

64 changes: 0 additions & 64 deletions packages/irys/deephash.ts

This file was deleted.

Loading

0 comments on commit 20a2708

Please sign in to comment.