mirror of
https://github.com/hzrd149/nsite-gateway.git
synced 2025-06-23 12:05:01 +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://
|
# can be in-memory, redis:// or sqlite://
|
||||||
CACHE_PATH="in-memory"
|
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)
|
# A list of relays to find users relay lists (10002) and blossom servers (10063)
|
||||||
LOOKUP_RELAYS=wss://user.kindpag.es,wss://purplepag.es
|
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
|
data
|
||||||
.netrc
|
.netrc
|
||||||
screenshots
|
screenshots
|
||||||
dist
|
|
||||||
|
@ -2,21 +2,20 @@
|
|||||||
"name": "nsite-gateway",
|
"name": "nsite-gateway",
|
||||||
"version": "0.7.0",
|
"version": "0.7.0",
|
||||||
"description": "A blossom server implementation written in Typescript",
|
"description": "A blossom server implementation written in Typescript",
|
||||||
"main": "dist/index.js",
|
"main": "build/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "hzrd149",
|
"author": "hzrd149",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node dist/index.js",
|
"start": "node build/index.js",
|
||||||
"prepack": "tsc",
|
"prepack": "tsc",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
"dev": "nodemon -i '**/data/**' --exec 'node' --loader @swc-node/register/esm src/index.ts",
|
"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 ."
|
"format": "prettier -w ."
|
||||||
},
|
},
|
||||||
"bin": "dist/index.js",
|
"bin": "build/index.js",
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"build",
|
||||||
"public"
|
"public"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"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 Keyv from "keyv";
|
||||||
import pfs from "fs/promises";
|
import { CACHE_PATH, CACHE_TIME } from "./env.js";
|
||||||
import { CACHE_PATH } from "./env.js";
|
|
||||||
|
|
||||||
try {
|
|
||||||
await pfs.mkdir("data");
|
|
||||||
} catch (error) {}
|
|
||||||
|
|
||||||
async function createStore() {
|
async function createStore() {
|
||||||
if (!CACHE_PATH || CACHE_PATH === "in-memory") return undefined;
|
if (!CACHE_PATH || CACHE_PATH === "in-memory") return undefined;
|
||||||
@ -26,26 +21,30 @@ store?.on("error", (err) => {
|
|||||||
|
|
||||||
const opts = store ? { store } : {};
|
const opts = store ? { store } : {};
|
||||||
|
|
||||||
/** domain -> pubkey */
|
/** A cache that maps a domain to a pubkey ( domain -> pubkey ) */
|
||||||
export const userDomains = new Keyv({
|
export const userDomains = new Keyv<string | undefined>({
|
||||||
...opts,
|
...opts,
|
||||||
namespace: "domains",
|
namespace: "domains",
|
||||||
// cache domains for an hour
|
ttl: CACHE_TIME * 1000,
|
||||||
ttl: 60 * 60 * 1000,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/** pubkey -> blossom servers */
|
/** A cache that maps a pubkey to a set of blossom servers ( pubkey -> servers ) */
|
||||||
export const userServers = new Keyv({
|
export const userServers = new Keyv<string[] | undefined>({
|
||||||
...opts,
|
...opts,
|
||||||
namespace: "servers",
|
namespace: "servers",
|
||||||
// cache servers for an hour
|
ttl: CACHE_TIME * 1000,
|
||||||
ttl: 60 * 60 * 1000,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/** pubkey -> relays */
|
/** A cache that maps a pubkey to a set of relays ( pubkey -> relays ) */
|
||||||
export const userRelays = new Keyv({
|
export const userRelays = new Keyv<string[] | undefined>({
|
||||||
...opts,
|
...opts,
|
||||||
namespace: "relays",
|
namespace: "relays",
|
||||||
// cache relays for an hour
|
ttl: CACHE_TIME * 1000,
|
||||||
ttl: 60 * 60 * 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 NGINX_CACHE_DIR = process.env.NGINX_CACHE_DIR;
|
||||||
const CACHE_PATH = process.env.CACHE_PATH;
|
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 PAC_PROXY = process.env.PAC_PROXY;
|
||||||
const TOR_PROXY = process.env.TOR_PROXY;
|
const TOR_PROXY = process.env.TOR_PROXY;
|
||||||
@ -50,4 +51,5 @@ export {
|
|||||||
ENABLE_SCREENSHOTS,
|
ENABLE_SCREENSHOTS,
|
||||||
SCREENSHOTS_DIR,
|
SCREENSHOTS_DIR,
|
||||||
ONION_HOST,
|
ONION_HOST,
|
||||||
|
CACHE_TIME,
|
||||||
};
|
};
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"module": "NodeNext",
|
"module": "NodeNext",
|
||||||
"target": "es2020",
|
"target": "es2020",
|
||||||
"moduleResolution": "NodeNext",
|
"moduleResolution": "NodeNext",
|
||||||
"outDir": "dist",
|
"outDir": "build",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"sourceMap": true
|
"sourceMap": true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user