remove node sea

add CACHE_TIME variable
This commit is contained in:
hzrd149 2025-03-25 08:26:53 +00:00
parent 80aab93bb7
commit c3778507d4
9 changed files with 28 additions and 91 deletions

View File

@ -1,5 +0,0 @@
---
"nsite-gateway": minor
---
Change build folder

View File

@ -2,6 +2,9 @@
# can be in-memory, redis:// or sqlite://
CACHE_PATH="in-memory"
# How long to keep a pubkeys relays and blossom servers in cache (in seconds)
CACHE_TIME=3600
# A list of relays to find users relay lists (10002) and blossom servers (10063)
LOOKUP_RELAYS=wss://user.kindpag.es,wss://purplepag.es

View File

@ -1,56 +0,0 @@
name: Build SEA
on:
push:
branches:
- master
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
sea-action:
name: Build SEA
strategy:
matrix:
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- name: Install Dependencies
run: pnpm install
- name: Build and bundle
run: pnpm build && pnpm bundle
- name: Find Node
id: find-node
run: echo "node=$(node -e 'console.log(process.argv[0]);')" >>
$env:GITHUB_OUTPUT
- name: SEA
id: sea
uses: bryopsida/node-sea-action@v1
with:
working-dir: .
output-dir: build/release
executable-name: nsite-gateway
sea-config-path: sea-config.json
node-path: ${{ steps.find-node.outputs.node }}
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-sea
path: build/release
if-no-files-found: error

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ build
data
.netrc
screenshots
dist

View File

@ -2,21 +2,20 @@
"name": "nsite-gateway",
"version": "0.7.0",
"description": "A blossom server implementation written in Typescript",
"main": "dist/index.js",
"main": "build/index.js",
"type": "module",
"author": "hzrd149",
"license": "MIT",
"scripts": {
"start": "node dist/index.js",
"start": "node build/index.js",
"prepack": "tsc",
"build": "tsc",
"dev": "nodemon -i '**/data/**' --exec 'node' --loader @swc-node/register/esm src/index.ts",
"bundle": "esbuild --bundle dist/index.js --format=esm --platform=node --outfile=build/bundle.mjs",
"format": "prettier -w ."
},
"bin": "dist/index.js",
"bin": "build/index.js",
"files": [
"dist",
"build",
"public"
],
"dependencies": {

View File

@ -1,5 +0,0 @@
{
"main": "build/bundle.mjs",
"output": "build/nsite-gateway.blob",
"assets": []
}

View File

@ -1,10 +1,5 @@
import Keyv from "keyv";
import pfs from "fs/promises";
import { CACHE_PATH } from "./env.js";
try {
await pfs.mkdir("data");
} catch (error) {}
import { CACHE_PATH, CACHE_TIME } from "./env.js";
async function createStore() {
if (!CACHE_PATH || CACHE_PATH === "in-memory") return undefined;
@ -26,26 +21,30 @@ store?.on("error", (err) => {
const opts = store ? { store } : {};
/** domain -> pubkey */
export const userDomains = new Keyv({
/** A cache that maps a domain to a pubkey ( domain -> pubkey ) */
export const userDomains = new Keyv<string | undefined>({
...opts,
namespace: "domains",
// cache domains for an hour
ttl: 60 * 60 * 1000,
ttl: CACHE_TIME * 1000,
});
/** pubkey -> blossom servers */
export const userServers = new Keyv({
/** A cache that maps a pubkey to a set of blossom servers ( pubkey -> servers ) */
export const userServers = new Keyv<string[] | undefined>({
...opts,
namespace: "servers",
// cache servers for an hour
ttl: 60 * 60 * 1000,
ttl: CACHE_TIME * 1000,
});
/** pubkey -> relays */
export const userRelays = new Keyv({
/** A cache that maps a pubkey to a set of relays ( pubkey -> relays ) */
export const userRelays = new Keyv<string[] | undefined>({
...opts,
namespace: "relays",
// cache relays for an hour
ttl: 60 * 60 * 1000,
ttl: CACHE_TIME * 1000,
});
/** A cache that maps a pubkey + path to blossom servers that had the blob ( pubkey/path -> servers ) */
export const pathServers = new Keyv<string[] | undefined>({
...opts,
namespace: "paths",
ttl: CACHE_TIME * 1000,
});

View File

@ -18,6 +18,7 @@ const MAX_FILE_SIZE = process.env.MAX_FILE_SIZE ? xbytes.parseSize(process.env.M
const NGINX_CACHE_DIR = process.env.NGINX_CACHE_DIR;
const CACHE_PATH = process.env.CACHE_PATH;
const CACHE_TIME = process.env.CACHE_TIME ? parseInt(process.env.CACHE_TIME) : 60 * 60;
const PAC_PROXY = process.env.PAC_PROXY;
const TOR_PROXY = process.env.TOR_PROXY;
@ -50,4 +51,5 @@ export {
ENABLE_SCREENSHOTS,
SCREENSHOTS_DIR,
ONION_HOST,
CACHE_TIME,
};

View File

@ -3,7 +3,7 @@
"module": "NodeNext",
"target": "es2020",
"moduleResolution": "NodeNext",
"outDir": "dist",
"outDir": "build",
"skipLibCheck": true,
"strict": true,
"sourceMap": true