mirror of
https://github.com/hzrd149/nsite-gateway.git
synced 2025-06-23 03:55:02 +00:00
remove node sea
add CACHE_TIME variable
This commit is contained in:
parent
80aab93bb7
commit
c3778507d4
@ -1,5 +0,0 @@
|
||||
---
|
||||
"nsite-gateway": minor
|
||||
---
|
||||
|
||||
Change build folder
|
@ -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
|
||||
|
||||
|
56
.github/workflows/node-sea.yml
vendored
56
.github/workflows/node-sea.yml
vendored
@ -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
2
.gitignore
vendored
@ -4,4 +4,4 @@ build
|
||||
data
|
||||
.netrc
|
||||
screenshots
|
||||
dist
|
||||
|
||||
|
@ -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": {
|
||||
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"main": "build/bundle.mjs",
|
||||
"output": "build/nsite-gateway.blob",
|
||||
"assets": []
|
||||
}
|
35
src/cache.ts
35
src/cache.ts
@ -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,
|
||||
});
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -3,7 +3,7 @@
|
||||
"module": "NodeNext",
|
||||
"target": "es2020",
|
||||
"moduleResolution": "NodeNext",
|
||||
"outDir": "dist",
|
||||
"outDir": "build",
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"sourceMap": true
|
||||
|
Loading…
x
Reference in New Issue
Block a user