linkzero 0.1.2 → 0.1.3
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/dist/cli.js +35 -3
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11,7 +11,10 @@ import { generateKeypair, LinkZeroClient, deriveWalletAddress } from "@linkzeroa
|
|
|
11
11
|
|
|
12
12
|
// src/provider.ts
|
|
13
13
|
import http from "http";
|
|
14
|
+
import fs from "fs";
|
|
15
|
+
import path from "path";
|
|
14
16
|
import { spawn } from "child_process";
|
|
17
|
+
var OUTPUT_DIR = path.join(process.cwd(), "lz-outputs");
|
|
15
18
|
async function dispatchEcho(payload) {
|
|
16
19
|
return {
|
|
17
20
|
output: {
|
|
@@ -23,12 +26,17 @@ async function dispatchEcho(payload) {
|
|
|
23
26
|
}
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
|
-
async function dispatchHandler(command, payload, timeout) {
|
|
29
|
+
async function dispatchHandler(command, payload, timeout, endpoint) {
|
|
27
30
|
return new Promise((resolve, reject) => {
|
|
28
31
|
const [cmd, ...args] = command.split(/\s+/);
|
|
29
32
|
const child = spawn(cmd, args, {
|
|
30
33
|
stdio: ["pipe", "pipe", "pipe"],
|
|
31
|
-
shell: true
|
|
34
|
+
shell: true,
|
|
35
|
+
env: {
|
|
36
|
+
...process.env,
|
|
37
|
+
LZ_ENDPOINT: endpoint || "",
|
|
38
|
+
LZ_OUTPUT_DIR: OUTPUT_DIR
|
|
39
|
+
}
|
|
32
40
|
});
|
|
33
41
|
const chunks = [];
|
|
34
42
|
let stderr = "";
|
|
@@ -99,10 +107,33 @@ function createProviderDaemon(options) {
|
|
|
99
107
|
let originalEndpoint = null;
|
|
100
108
|
let requestCount = 0;
|
|
101
109
|
const startTime = Date.now();
|
|
102
|
-
const dispatch = handler ? (payload) => dispatchHandler(handler, payload, handlerTimeout) : forward ? (payload) => dispatchForward(forward, payload, handlerTimeout) : dispatchEcho;
|
|
110
|
+
const dispatch = handler ? (payload) => dispatchHandler(handler, payload, handlerTimeout, options.endpoint) : forward ? (payload) => dispatchForward(forward, payload, handlerTimeout) : dispatchEcho;
|
|
103
111
|
const dispatchMode = handler ? "handler" : forward ? "forward" : "echo";
|
|
104
112
|
function createServer() {
|
|
105
113
|
return http.createServer(async (req, res) => {
|
|
114
|
+
if (req.method === "GET" && req.url?.startsWith("/files/")) {
|
|
115
|
+
const filename = path.basename(req.url.slice(7));
|
|
116
|
+
const filePath = path.join(OUTPUT_DIR, filename);
|
|
117
|
+
if (!fs.existsSync(filePath)) {
|
|
118
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
119
|
+
res.end(JSON.stringify({ error: "File not found" }));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const ext = path.extname(filename).toLowerCase();
|
|
123
|
+
const mimeTypes = {
|
|
124
|
+
".png": "image/png",
|
|
125
|
+
".jpg": "image/jpeg",
|
|
126
|
+
".jpeg": "image/jpeg",
|
|
127
|
+
".gif": "image/gif",
|
|
128
|
+
".webp": "image/webp",
|
|
129
|
+
".svg": "image/svg+xml",
|
|
130
|
+
".json": "application/json",
|
|
131
|
+
".txt": "text/plain"
|
|
132
|
+
};
|
|
133
|
+
res.writeHead(200, { "Content-Type": mimeTypes[ext] || "application/octet-stream" });
|
|
134
|
+
fs.createReadStream(filePath).pipe(res);
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
106
137
|
if (req.method === "GET" && req.url === "/health") {
|
|
107
138
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
108
139
|
res.end(JSON.stringify({
|
|
@@ -150,6 +181,7 @@ function createProviderDaemon(options) {
|
|
|
150
181
|
});
|
|
151
182
|
}
|
|
152
183
|
async function start() {
|
|
184
|
+
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
|
|
153
185
|
const { registrations } = await client.listBidderRegistrations();
|
|
154
186
|
if (registrations.length === 0) {
|
|
155
187
|
throw new Error(
|