diff --git a/README.md b/README.md index 69b4b44..2487f2e 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ -# VixBluesky 🛠️ (Inspired by [FixTweet](https://github.com/FixTweet/FixTweet)) +# girlcockbsky Fork of VixBluesky 🛠️ (Inspired by [FixTweet](https://github.com/FixTweet/FixTweet)) > [!IMPORTANT] -> This is a fork of [FixBluesky](https://github.com/ThornbushHQ/FixBluesky) by [@ItsRauf](https://www.github.com/ItsRauf). +> This is a fork of VixBluesky which is a fork of [FixBluesky](https://github.com/ThornbushHQ/FixBluesky) by [@ItsRauf](https://www.github.com/ItsRauf). > All credits go to them for the original idea and implementation. +Converted to nodejs cause serverless design's proprietary-ness annoys me and i wanted to make a funny joke after seeing girlcockx for twitter. + Embed Bluesky links in Discord. ## How To Use? -#### Simply append `x` at the end of `bsky.app`. +#### Simply append `girlcock` at the front of `bsky.app`. ## Direct Links @@ -18,4 +20,4 @@ You want to link to a media directly? You can prepend `r.` to the URL to get a d ## Authors - [@ItsRauf](https://www.github.com/ItsRauf) - Original author -- [@Lexedia](https://www.github.com/Rapougnac) +- [@Lexedia](https://www.github.com/Rapougnac) - Also Original author diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..4e067f0 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,28 @@ +services: + api: + build: + context: ./pkgs/api/. + dockerfile: Dockerfile + ports: + - "2598:3000" + environment: + - NODE_ENV=production + - PORT=3000 + - EMPTY_REDIR=https://bsky.app/profile/juni.pet/post/3l3e53fzazy2n + restart: unless-stopped + app: + build: + context: ./pkgs/app/. + dockerfile: Dockerfile + ports: + - "2599:3000" + environment: + - BSKY_SERVICE_URL=https://bsky.social + - VIXBLUESKY_APP_DOMAIN=girlcockbsky.app + - VIXBLUESKY_API_URL=http://localhost:2598/ + - BSKY_AUTH_USERNAME=YOUR_OWN_USERNAME + - BSKY_AUTH_PASSWORD=YOUR_APP_PASSWORD_SHOULD_COME_FROM_ENV + - PORT=3000 + - EMPTY_REDIR=https://bsky.app/profile/juni.pet/post/3l3e53fzazy2n + restart: unless-stopped + diff --git a/pkgs/app/package.json b/pkgs/app/package.json index 51591d2..7261b52 100644 --- a/pkgs/app/package.json +++ b/pkgs/app/package.json @@ -6,7 +6,8 @@ "@atcute/bluesky": "^1.0.7", "@atcute/client": "^2.0.3", "hono": "^4.5.1", - "@hono/node-server": "^1.13.2" + "@hono/node-server": "^1.13.2", + "node-cache": "^5.1.2" }, "devDependencies": { "@cloudflare/workers-types": "^4.20230628.0", diff --git a/pkgs/app/src/index.ts b/pkgs/app/src/index.ts index 9bc4bff..5d2cdff 100644 --- a/pkgs/app/src/index.ts +++ b/pkgs/app/src/index.ts @@ -8,19 +8,36 @@ import { getOEmbed } from './routes/getOEmbed'; import { getProfileData } from './routes/getProfileData'; import { getProfile } from './routes/getProfile'; import { HTTPException } from 'hono/http-exception'; +const NodeCache = require( "node-cache" ); const app = new Hono(); -const bskyxC: any = {}; +const myCache = new NodeCache(); app.use('*', async (c, next) => { - const creds = new CredentialManager({service: process.env.BSKY_SERVICE_URL}); + const creds = new CredentialManager({ + service: process.env.BSKY_SERVICE_URL, + onRefresh(session) { + return myCache.set('session', JSON.stringify(session)); + }, + onExpired(session) { + return myCache.del('session'); + }, + onSessionUpdate(session) { + return myCache.set('session', JSON.stringify(session)); + }, + }); const agent = new XRPC({ handler: creds }); try { - await creds.login({ - identifier: process.env.BSKY_AUTH_USERNAME, - password: process.env.BSKY_AUTH_PASSWORD, - }); - console.log(creds.session); + const rawSession = myCache.get('session'); + if(rawSession) { + const session = JSON.parse(rawSession) as AtpSessionData; + await creds.resume(session); + } else { + await creds.login({ + identifier: process.env.BSKY_AUTH_USERNAME, + password: process.env.BSKY_AUTH_PASSWORD, + }); + } c.set('Agent', agent); } catch (error) { const err = new Error('Failed to login to Bluesky!', { diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 29b1faa..0000000 --- a/shell.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs ? import {} }: - -pkgs.mkShell { - buildInputs = [ - pkgs.nodejs - pkgs.python3 - pkgs.python3Packages.pip - pkgs.python3Packages.virtualenv - pkgs.sqlite - pkgs.gcc - pkgs.gnumake - pkgs.pnpm - pkgs.wrangler - ]; -}