rechrome 1.6.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/rech.js +452 -111
- package/rech.ts +452 -111
- package/serve.js +11 -6
- package/serve.ts +11 -6
package/serve.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { file } from "bun";
|
|
2
2
|
import { createHash, X509Certificate } from "crypto";
|
|
3
|
-
import { mkdirSync, unlinkSync } from "fs";
|
|
3
|
+
import { mkdirSync, unlinkSync, accessSync, constants as fsConstants } from "fs";
|
|
4
4
|
import { join, resolve, relative, isAbsolute } from "path";
|
|
5
5
|
import {
|
|
6
6
|
log,
|
|
@@ -72,8 +72,9 @@ export async function serve() {
|
|
|
72
72
|
mkdirSync(workDir, { recursive: true });
|
|
73
73
|
|
|
74
74
|
const listenHost = process.env.RECH_HOST || "127.0.0.1";
|
|
75
|
-
const
|
|
76
|
-
const
|
|
75
|
+
const canRead = (p?: string) => { try { accessSync(p!, fsConstants.R_OK); return true; } catch { return false; } };
|
|
76
|
+
const certPath = canRead(process.env.RECH_TLS_CERT) ? process.env.RECH_TLS_CERT : undefined;
|
|
77
|
+
const keyPath = canRead(process.env.RECH_TLS_KEY) ? process.env.RECH_TLS_KEY : undefined;
|
|
77
78
|
if (certPath && keyPath) {
|
|
78
79
|
const renewed = await renewCertIfNeeded(certPath, keyPath);
|
|
79
80
|
if (renewed) { log("Restarting to load renewed TLS cert..."); process.exit(0); }
|
|
@@ -87,6 +88,10 @@ export async function serve() {
|
|
|
87
88
|
hostname: listenHost,
|
|
88
89
|
port,
|
|
89
90
|
tls,
|
|
91
|
+
error(err) {
|
|
92
|
+
log(`unhandled error: ${err.message}`);
|
|
93
|
+
return Response.json({ status: 1, stdout: "", stderr: err.message }, { status: 500 });
|
|
94
|
+
},
|
|
90
95
|
async fetch(req) {
|
|
91
96
|
const reqUrl = new URL(req.url);
|
|
92
97
|
|
|
@@ -114,7 +119,7 @@ export async function serve() {
|
|
|
114
119
|
if (Array.isArray(body)) {
|
|
115
120
|
args = body;
|
|
116
121
|
const clientAddr = `${req.headers.get("x-forwarded-for") || server.requestIP(req)?.address || "unknown"}`;
|
|
117
|
-
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0,
|
|
122
|
+
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0, 8);
|
|
118
123
|
clientName = clientAddr;
|
|
119
124
|
log(`session from client IP: ${clientAddr} -> ${sessionId}`);
|
|
120
125
|
} else {
|
|
@@ -125,12 +130,12 @@ export async function serve() {
|
|
|
125
130
|
const baseId = id?.gitUrl || (id?.hostname && id?.cwd ? `${id.hostname}:${id.cwd}` : null);
|
|
126
131
|
const raw = baseId && id?.profile ? `${baseId}@${id.profile}` : baseId;
|
|
127
132
|
if (raw) {
|
|
128
|
-
sessionId = createHash("sha256").update(raw).digest("hex").slice(0,
|
|
133
|
+
sessionId = createHash("sha256").update(raw).digest("hex").slice(0, 8);
|
|
129
134
|
clientName = raw;
|
|
130
135
|
log(`session from identity: ${raw} -> ${sessionId}`);
|
|
131
136
|
} else {
|
|
132
137
|
const clientAddr = `${req.headers.get("x-forwarded-for") || server.requestIP(req)?.address || "unknown"}`;
|
|
133
|
-
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0,
|
|
138
|
+
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0, 8);
|
|
134
139
|
clientName = clientAddr;
|
|
135
140
|
log(`session from client IP fallback: ${clientAddr} -> ${sessionId}`);
|
|
136
141
|
}
|
package/serve.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { file } from "bun";
|
|
2
2
|
import { createHash, X509Certificate } from "crypto";
|
|
3
|
-
import { mkdirSync, unlinkSync } from "fs";
|
|
3
|
+
import { mkdirSync, unlinkSync, accessSync, constants as fsConstants } from "fs";
|
|
4
4
|
import { join, resolve, relative, isAbsolute } from "path";
|
|
5
5
|
import {
|
|
6
6
|
log,
|
|
@@ -72,8 +72,9 @@ export async function serve() {
|
|
|
72
72
|
mkdirSync(workDir, { recursive: true });
|
|
73
73
|
|
|
74
74
|
const listenHost = process.env.RECH_HOST || "127.0.0.1";
|
|
75
|
-
const
|
|
76
|
-
const
|
|
75
|
+
const canRead = (p?: string) => { try { accessSync(p!, fsConstants.R_OK); return true; } catch { return false; } };
|
|
76
|
+
const certPath = canRead(process.env.RECH_TLS_CERT) ? process.env.RECH_TLS_CERT : undefined;
|
|
77
|
+
const keyPath = canRead(process.env.RECH_TLS_KEY) ? process.env.RECH_TLS_KEY : undefined;
|
|
77
78
|
if (certPath && keyPath) {
|
|
78
79
|
const renewed = await renewCertIfNeeded(certPath, keyPath);
|
|
79
80
|
if (renewed) { log("Restarting to load renewed TLS cert..."); process.exit(0); }
|
|
@@ -87,6 +88,10 @@ export async function serve() {
|
|
|
87
88
|
hostname: listenHost,
|
|
88
89
|
port,
|
|
89
90
|
tls,
|
|
91
|
+
error(err) {
|
|
92
|
+
log(`unhandled error: ${err.message}`);
|
|
93
|
+
return Response.json({ status: 1, stdout: "", stderr: err.message }, { status: 500 });
|
|
94
|
+
},
|
|
90
95
|
async fetch(req) {
|
|
91
96
|
const reqUrl = new URL(req.url);
|
|
92
97
|
|
|
@@ -114,7 +119,7 @@ export async function serve() {
|
|
|
114
119
|
if (Array.isArray(body)) {
|
|
115
120
|
args = body;
|
|
116
121
|
const clientAddr = `${req.headers.get("x-forwarded-for") || server.requestIP(req)?.address || "unknown"}`;
|
|
117
|
-
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0,
|
|
122
|
+
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0, 8);
|
|
118
123
|
clientName = clientAddr;
|
|
119
124
|
log(`session from client IP: ${clientAddr} -> ${sessionId}`);
|
|
120
125
|
} else {
|
|
@@ -125,12 +130,12 @@ export async function serve() {
|
|
|
125
130
|
const baseId = id?.gitUrl || (id?.hostname && id?.cwd ? `${id.hostname}:${id.cwd}` : null);
|
|
126
131
|
const raw = baseId && id?.profile ? `${baseId}@${id.profile}` : baseId;
|
|
127
132
|
if (raw) {
|
|
128
|
-
sessionId = createHash("sha256").update(raw).digest("hex").slice(0,
|
|
133
|
+
sessionId = createHash("sha256").update(raw).digest("hex").slice(0, 8);
|
|
129
134
|
clientName = raw;
|
|
130
135
|
log(`session from identity: ${raw} -> ${sessionId}`);
|
|
131
136
|
} else {
|
|
132
137
|
const clientAddr = `${req.headers.get("x-forwarded-for") || server.requestIP(req)?.address || "unknown"}`;
|
|
133
|
-
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0,
|
|
138
|
+
sessionId = createHash("sha256").update(clientAddr).digest("hex").slice(0, 8);
|
|
134
139
|
clientName = clientAddr;
|
|
135
140
|
log(`session from client IP fallback: ${clientAddr} -> ${sessionId}`);
|
|
136
141
|
}
|