@aigne/afs-explorer 1.1.0 → 1.11.0-beta.1
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/LICENSE.md +17 -84
- package/README.md +6 -4
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/index.cjs +18 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +14 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +18 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server.cjs +85 -0
- package/dist/server.d.cts +26 -0
- package/dist/server.d.cts.map +1 -0
- package/dist/server.d.mts +26 -0
- package/dist/server.d.mts.map +1 -0
- package/dist/server.mjs +82 -0
- package/dist/server.mjs.map +1 -0
- package/html/assets/index-C3YiCz2W.js +191 -0
- package/{dist → html}/index.html +1 -1
- package/package.json +31 -49
- package/CHANGELOG.md +0 -64
- package/dist/assets/index-viceiJOt.js +0 -271
- package/lib/cjs/index.d.ts +0 -10
- package/lib/cjs/index.js +0 -17
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/server.d.ts +0 -21
- package/lib/cjs/server.js +0 -95
- package/lib/dts/index.d.ts +0 -10
- package/lib/dts/server.d.ts +0 -21
- package/lib/esm/index.d.ts +0 -10
- package/lib/esm/index.js +0 -13
- package/lib/esm/package.json +0 -3
- package/lib/esm/server.d.ts +0 -21
- package/lib/esm/server.js +0 -88
package/LICENSE.md
CHANGED
|
@@ -1,93 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
# Proprietary License
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Copyright (c) 2024-2025 ArcBlock, Inc. All Rights Reserved.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This software and associated documentation files (the "Software") are proprietary
|
|
6
|
+
and confidential. Unauthorized copying, modification, distribution, or use of
|
|
7
|
+
this Software, via any medium, is strictly prohibited.
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
The Software is provided for internal use only within ArcBlock, Inc. and its
|
|
10
|
+
authorized affiliates.
|
|
8
11
|
|
|
9
|
-
##
|
|
12
|
+
## No License Granted
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
available, and prepare derivative works of the software, in each case subject to
|
|
14
|
-
the limitations and conditions below.
|
|
14
|
+
No license, express or implied, is granted to any party for any purpose.
|
|
15
|
+
All rights are reserved by ArcBlock, Inc.
|
|
15
16
|
|
|
16
|
-
##
|
|
17
|
+
## Public Artifact Distribution
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
Portions of this Software may be released publicly under separate open-source
|
|
20
|
+
licenses (such as MIT License) through designated public repositories. Such
|
|
21
|
+
public releases are governed by their respective licenses and do not affect
|
|
22
|
+
the proprietary nature of this repository.
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
in the software, and you may not remove or obscure any functionality in the
|
|
24
|
-
software that is protected by the license key.
|
|
24
|
+
## Contact
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
of the licensor in the software. Any use of the licensor’s trademarks is subject
|
|
28
|
-
to applicable law.
|
|
29
|
-
|
|
30
|
-
## Patents
|
|
31
|
-
|
|
32
|
-
The licensor grants you a license, under any patent claims the licensor can
|
|
33
|
-
license, or becomes able to license, to make, have made, use, sell, offer for
|
|
34
|
-
sale, import and have imported the software, in each case subject to the
|
|
35
|
-
limitations and conditions in this license. This license does not cover any
|
|
36
|
-
patent claims that you cause to be infringed by modifications or additions to
|
|
37
|
-
the software. If you or your company make any written claim that the software
|
|
38
|
-
infringes or contributes to infringement of any patent, your patent license for
|
|
39
|
-
the software granted under these terms ends immediately. If your company makes
|
|
40
|
-
such a claim, your patent license ends immediately for work on behalf of your
|
|
41
|
-
company.
|
|
42
|
-
|
|
43
|
-
## Notices
|
|
44
|
-
|
|
45
|
-
You must ensure that anyone who gets a copy of any part of the software from you
|
|
46
|
-
also gets a copy of these terms.
|
|
47
|
-
|
|
48
|
-
If you modify the software, you must include in any modified copies of the
|
|
49
|
-
software prominent notices stating that you have modified the software.
|
|
50
|
-
|
|
51
|
-
## No Other Rights
|
|
52
|
-
|
|
53
|
-
These terms do not imply any licenses other than those expressly granted in
|
|
54
|
-
these terms.
|
|
55
|
-
|
|
56
|
-
## Termination
|
|
57
|
-
|
|
58
|
-
If you use the software in violation of these terms, such use is not licensed,
|
|
59
|
-
and your licenses will automatically terminate. If the licensor provides you
|
|
60
|
-
with a notice of your violation, and you cease all violation of this license no
|
|
61
|
-
later than 30 days after you receive that notice, your licenses will be
|
|
62
|
-
reinstated retroactively. However, if you violate these terms after such
|
|
63
|
-
reinstatement, any additional violation of these terms will cause your licenses
|
|
64
|
-
to terminate automatically and permanently.
|
|
65
|
-
|
|
66
|
-
## No Liability
|
|
67
|
-
|
|
68
|
-
*As far as the law allows, the software comes as is, without any warranty or
|
|
69
|
-
condition, and the licensor will not be liable to you for any damages arising
|
|
70
|
-
out of these terms or the use or nature of the software, under any kind of
|
|
71
|
-
legal claim.*
|
|
72
|
-
|
|
73
|
-
## Definitions
|
|
74
|
-
|
|
75
|
-
The **licensor** is the entity offering these terms, and the **software** is the
|
|
76
|
-
software the licensor makes available under these terms, including any portion
|
|
77
|
-
of it.
|
|
78
|
-
|
|
79
|
-
**you** refers to the individual or entity agreeing to these terms.
|
|
80
|
-
|
|
81
|
-
**your company** is any legal entity, sole proprietorship, or other kind of
|
|
82
|
-
organization that you work for, plus all organizations that have control over,
|
|
83
|
-
are under the control of, or are under common control with that
|
|
84
|
-
organization. **control** means ownership of substantially all the assets of an
|
|
85
|
-
entity, or the power to direct its management and policies by vote, contract, or
|
|
86
|
-
otherwise. Control can be direct or indirect.
|
|
87
|
-
|
|
88
|
-
**your licenses** are all the licenses granted to you for the software under
|
|
89
|
-
these terms.
|
|
90
|
-
|
|
91
|
-
**use** means anything you do with the software requiring one of your licenses.
|
|
92
|
-
|
|
93
|
-
**trademark** means trademarks, service marks, and similar rights.
|
|
26
|
+
For licensing inquiries, contact: legal@arcblock.io
|
package/README.md
CHANGED
|
@@ -53,7 +53,10 @@ import path from "node:path";
|
|
|
53
53
|
|
|
54
54
|
// For production: specify the path to the built frontend
|
|
55
55
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
56
|
-
const distPath = path.resolve(
|
|
56
|
+
const distPath = path.resolve(
|
|
57
|
+
__dirname,
|
|
58
|
+
"node_modules/@aigne/afs-explorer/dist",
|
|
59
|
+
);
|
|
57
60
|
|
|
58
61
|
const server = new ExplorerServer(afs, {
|
|
59
62
|
port: 8080,
|
|
@@ -116,6 +119,7 @@ The explorer provides the following REST API endpoints:
|
|
|
116
119
|
### Backend
|
|
117
120
|
|
|
118
121
|
The backend is built with Express and provides:
|
|
122
|
+
|
|
119
123
|
- RESTful API for AFS operations
|
|
120
124
|
- Static file serving for the React frontend
|
|
121
125
|
- CORS support for development
|
|
@@ -123,11 +127,9 @@ The backend is built with Express and provides:
|
|
|
123
127
|
### Frontend
|
|
124
128
|
|
|
125
129
|
The frontend is a React application built with:
|
|
130
|
+
|
|
126
131
|
- **React 19** - Modern React with hooks
|
|
127
132
|
- **TypeScript** - Type-safe development
|
|
128
133
|
- **Material-UI (MUI)** - Professional UI components
|
|
129
134
|
- **Vite** - Fast build tool and dev server
|
|
130
135
|
|
|
131
|
-
## License
|
|
132
|
-
|
|
133
|
-
Elastic-2.0
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const require_server = require('./server.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Start the AFS Explorer web server
|
|
6
|
+
* @param afs - The AFS instance to explore
|
|
7
|
+
* @param options - Server options
|
|
8
|
+
* @returns The ExplorerServer instance
|
|
9
|
+
*/
|
|
10
|
+
async function startExplorer(afs, options = {}) {
|
|
11
|
+
const server = new require_server.ExplorerServer(afs, options);
|
|
12
|
+
await server.start();
|
|
13
|
+
return server;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.ExplorerServer = require_server.ExplorerServer;
|
|
18
|
+
exports.startExplorer = startExplorer;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ExplorerServer, ExplorerServerOptions } from "./server.cjs";
|
|
2
|
+
import { AFS } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Start the AFS Explorer web server
|
|
7
|
+
* @param afs - The AFS instance to explore
|
|
8
|
+
* @param options - Server options
|
|
9
|
+
* @returns The ExplorerServer instance
|
|
10
|
+
*/
|
|
11
|
+
declare function startExplorer(afs: AFS, options?: ExplorerServerOptions): Promise<ExplorerServer>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ExplorerServer, type ExplorerServerOptions, startExplorer };
|
|
14
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAWA;;;;;iBAAsB,aAAA,CAAA,GAAA,EACf,GAAA,EAAA,OAAA,GACI,qBAAA,GACR,OAAA,CAAQ,cAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ExplorerServer, ExplorerServerOptions } from "./server.mjs";
|
|
2
|
+
import { AFS } from "@aigne/afs";
|
|
3
|
+
|
|
4
|
+
//#region src/index.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Start the AFS Explorer web server
|
|
7
|
+
* @param afs - The AFS instance to explore
|
|
8
|
+
* @param options - Server options
|
|
9
|
+
* @returns The ExplorerServer instance
|
|
10
|
+
*/
|
|
11
|
+
declare function startExplorer(afs: AFS, options?: ExplorerServerOptions): Promise<ExplorerServer>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { ExplorerServer, type ExplorerServerOptions, startExplorer };
|
|
14
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;AAWA;;;;;iBAAsB,aAAA,CAAA,GAAA,EACf,GAAA,EAAA,OAAA,GACI,qBAAA,GACR,OAAA,CAAQ,cAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ExplorerServer } from "./server.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/index.ts
|
|
4
|
+
/**
|
|
5
|
+
* Start the AFS Explorer web server
|
|
6
|
+
* @param afs - The AFS instance to explore
|
|
7
|
+
* @param options - Server options
|
|
8
|
+
* @returns The ExplorerServer instance
|
|
9
|
+
*/
|
|
10
|
+
async function startExplorer(afs, options = {}) {
|
|
11
|
+
const server = new ExplorerServer(afs, options);
|
|
12
|
+
await server.start();
|
|
13
|
+
return server;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
export { ExplorerServer, startExplorer };
|
|
18
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import type { AFS } from \"@aigne/afs\";\nimport { ExplorerServer, type ExplorerServerOptions } from \"./server.js\";\n\nexport { ExplorerServer, type ExplorerServerOptions };\n\n/**\n * Start the AFS Explorer web server\n * @param afs - The AFS instance to explore\n * @param options - Server options\n * @returns The ExplorerServer instance\n */\nexport async function startExplorer(\n afs: AFS,\n options: ExplorerServerOptions = {},\n): Promise<ExplorerServer> {\n const server = new ExplorerServer(afs, options);\n await server.start();\n return server;\n}\n"],"mappings":";;;;;;;;;AAWA,eAAsB,cACpB,KACA,UAAiC,EAAE,EACV;CACzB,MAAM,SAAS,IAAI,eAAe,KAAK,QAAQ;AAC/C,OAAM,OAAO,OAAO;AACpB,QAAO"}
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
node_path = require_rolldown_runtime.__toESM(node_path);
|
|
4
|
+
let cors = require("cors");
|
|
5
|
+
cors = require_rolldown_runtime.__toESM(cors);
|
|
6
|
+
let express = require("express");
|
|
7
|
+
express = require_rolldown_runtime.__toESM(express);
|
|
8
|
+
|
|
9
|
+
//#region src/server.ts
|
|
10
|
+
var ExplorerServer = class {
|
|
11
|
+
app;
|
|
12
|
+
server;
|
|
13
|
+
constructor(afs, options = {}) {
|
|
14
|
+
this.afs = afs;
|
|
15
|
+
this.options = options;
|
|
16
|
+
this.app = (0, express.default)();
|
|
17
|
+
this.setupMiddleware();
|
|
18
|
+
this.setupRoutes();
|
|
19
|
+
}
|
|
20
|
+
setupMiddleware() {
|
|
21
|
+
this.app.use((0, cors.default)());
|
|
22
|
+
this.app.use(express.default.json());
|
|
23
|
+
}
|
|
24
|
+
setupRoutes() {
|
|
25
|
+
this.app.get("/api/list", async (req, res) => {
|
|
26
|
+
const path = req.query.path || "/";
|
|
27
|
+
const maxDepth = req.query.maxDepth ? Number.parseInt(req.query.maxDepth, 10) : 1;
|
|
28
|
+
const result = await this.afs.list(path, { maxDepth });
|
|
29
|
+
res.json(result);
|
|
30
|
+
});
|
|
31
|
+
this.app.get("/api/read", async (req, res) => {
|
|
32
|
+
const path = req.query.path;
|
|
33
|
+
if (!path) {
|
|
34
|
+
res.status(400).json({ error: "Path is required" });
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = await this.afs.read(path);
|
|
38
|
+
res.json(result);
|
|
39
|
+
});
|
|
40
|
+
this.app.get("/api/search", async (req, res) => {
|
|
41
|
+
const path = req.query.path || "/";
|
|
42
|
+
const query = req.query.query;
|
|
43
|
+
if (!query) {
|
|
44
|
+
res.status(400).json({ error: "Query is required" });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const result = await this.afs.search(path, query);
|
|
48
|
+
res.json(result);
|
|
49
|
+
});
|
|
50
|
+
if (this.options.distPath) {
|
|
51
|
+
const distPath = node_path.default.resolve(this.options.distPath);
|
|
52
|
+
this.app.use(express.default.static(distPath));
|
|
53
|
+
this.app.get("/{*splat}", (_req, res) => {
|
|
54
|
+
res.sendFile("index.html", { root: distPath });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
this.app.use((err, _req, res, _next) => {
|
|
58
|
+
res.status(500).json({ error: err.message || String(err) });
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async start() {
|
|
62
|
+
const port = this.options.port || 3e3;
|
|
63
|
+
const host = this.options.host || "localhost";
|
|
64
|
+
return new Promise((resolve) => {
|
|
65
|
+
this.server = this.app.listen(port, host, () => {
|
|
66
|
+
resolve();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async stop() {
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
if (this.server) this.server.close((err) => {
|
|
73
|
+
if (err && err.code !== "ERR_SERVER_NOT_RUNNING") reject(err);
|
|
74
|
+
else {
|
|
75
|
+
this.server = void 0;
|
|
76
|
+
resolve();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
else resolve();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
exports.ExplorerServer = ExplorerServer;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AFS } from "@aigne/afs";
|
|
2
|
+
|
|
3
|
+
//#region src/server.d.ts
|
|
4
|
+
interface ExplorerServerOptions {
|
|
5
|
+
port?: number;
|
|
6
|
+
host?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Path to the dist directory containing the built frontend.
|
|
9
|
+
* If not provided, static file serving will be disabled.
|
|
10
|
+
*/
|
|
11
|
+
distPath?: string;
|
|
12
|
+
}
|
|
13
|
+
declare class ExplorerServer {
|
|
14
|
+
private afs;
|
|
15
|
+
private options;
|
|
16
|
+
private app;
|
|
17
|
+
private server?;
|
|
18
|
+
constructor(afs: AFS, options?: ExplorerServerOptions);
|
|
19
|
+
private setupMiddleware;
|
|
20
|
+
private setupRoutes;
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
stop(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ExplorerServer, ExplorerServerOptions };
|
|
26
|
+
//# sourceMappingURL=server.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.cts","names":[],"sources":["../src/server.ts"],"mappings":";;;UAKiB,qBAAA;EAAA,IAAA;EAAA,IAAA;EAAA;AAUjB;;;EAViB,QAAA;AAAA;AAAA,cAUJ,cAAA;EAAA,QAAA,GAAA;EAAA,QAAA,OAAA;EAAA,QAAA,GAAA;EAAA,QAAA,MAAA;EAAA,YAAA,GAAA,EAKI,GAAA,EAAA,OAAA,GACI,qBAAA;EAAA,QAAA,eAAA;EAAA,QAAA,WAAA;EAAA,MAAA,GA2DJ,OAAA;EAAA,KAAA,GAWD,OAAA;AAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AFS } from "@aigne/afs";
|
|
2
|
+
|
|
3
|
+
//#region src/server.d.ts
|
|
4
|
+
interface ExplorerServerOptions {
|
|
5
|
+
port?: number;
|
|
6
|
+
host?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Path to the dist directory containing the built frontend.
|
|
9
|
+
* If not provided, static file serving will be disabled.
|
|
10
|
+
*/
|
|
11
|
+
distPath?: string;
|
|
12
|
+
}
|
|
13
|
+
declare class ExplorerServer {
|
|
14
|
+
private afs;
|
|
15
|
+
private options;
|
|
16
|
+
private app;
|
|
17
|
+
private server?;
|
|
18
|
+
constructor(afs: AFS, options?: ExplorerServerOptions);
|
|
19
|
+
private setupMiddleware;
|
|
20
|
+
private setupRoutes;
|
|
21
|
+
start(): Promise<void>;
|
|
22
|
+
stop(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ExplorerServer, ExplorerServerOptions };
|
|
26
|
+
//# sourceMappingURL=server.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.mts","names":[],"sources":["../src/server.ts"],"mappings":";;;UAKiB,qBAAA;EAAA,IAAA;EAAA,IAAA;EAAA;AAUjB;;;EAViB,QAAA;AAAA;AAAA,cAUJ,cAAA;EAAA,QAAA,GAAA;EAAA,QAAA,OAAA;EAAA,QAAA,GAAA;EAAA,QAAA,MAAA;EAAA,YAAA,GAAA,EAKI,GAAA,EAAA,OAAA,GACI,qBAAA;EAAA,QAAA,eAAA;EAAA,QAAA,WAAA;EAAA,MAAA,GA2DJ,OAAA;EAAA,KAAA,GAWD,OAAA;AAAA"}
|
package/dist/server.mjs
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import cors from "cors";
|
|
3
|
+
import express from "express";
|
|
4
|
+
|
|
5
|
+
//#region src/server.ts
|
|
6
|
+
var ExplorerServer = class {
|
|
7
|
+
app;
|
|
8
|
+
server;
|
|
9
|
+
constructor(afs, options = {}) {
|
|
10
|
+
this.afs = afs;
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.app = express();
|
|
13
|
+
this.setupMiddleware();
|
|
14
|
+
this.setupRoutes();
|
|
15
|
+
}
|
|
16
|
+
setupMiddleware() {
|
|
17
|
+
this.app.use(cors());
|
|
18
|
+
this.app.use(express.json());
|
|
19
|
+
}
|
|
20
|
+
setupRoutes() {
|
|
21
|
+
this.app.get("/api/list", async (req, res) => {
|
|
22
|
+
const path$1 = req.query.path || "/";
|
|
23
|
+
const maxDepth = req.query.maxDepth ? Number.parseInt(req.query.maxDepth, 10) : 1;
|
|
24
|
+
const result = await this.afs.list(path$1, { maxDepth });
|
|
25
|
+
res.json(result);
|
|
26
|
+
});
|
|
27
|
+
this.app.get("/api/read", async (req, res) => {
|
|
28
|
+
const path$1 = req.query.path;
|
|
29
|
+
if (!path$1) {
|
|
30
|
+
res.status(400).json({ error: "Path is required" });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const result = await this.afs.read(path$1);
|
|
34
|
+
res.json(result);
|
|
35
|
+
});
|
|
36
|
+
this.app.get("/api/search", async (req, res) => {
|
|
37
|
+
const path$1 = req.query.path || "/";
|
|
38
|
+
const query = req.query.query;
|
|
39
|
+
if (!query) {
|
|
40
|
+
res.status(400).json({ error: "Query is required" });
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const result = await this.afs.search(path$1, query);
|
|
44
|
+
res.json(result);
|
|
45
|
+
});
|
|
46
|
+
if (this.options.distPath) {
|
|
47
|
+
const distPath = path.resolve(this.options.distPath);
|
|
48
|
+
this.app.use(express.static(distPath));
|
|
49
|
+
this.app.get("/{*splat}", (_req, res) => {
|
|
50
|
+
res.sendFile("index.html", { root: distPath });
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.app.use((err, _req, res, _next) => {
|
|
54
|
+
res.status(500).json({ error: err.message || String(err) });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async start() {
|
|
58
|
+
const port = this.options.port || 3e3;
|
|
59
|
+
const host = this.options.host || "localhost";
|
|
60
|
+
return new Promise((resolve) => {
|
|
61
|
+
this.server = this.app.listen(port, host, () => {
|
|
62
|
+
resolve();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async stop() {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
if (this.server) this.server.close((err) => {
|
|
69
|
+
if (err && err.code !== "ERR_SERVER_NOT_RUNNING") reject(err);
|
|
70
|
+
else {
|
|
71
|
+
this.server = void 0;
|
|
72
|
+
resolve();
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
else resolve();
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { ExplorerServer };
|
|
82
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.mjs","names":["path"],"sources":["../src/server.ts"],"sourcesContent":["import path from \"node:path\";\nimport type { AFS } from \"@aigne/afs\";\nimport cors from \"cors\";\nimport express from \"express\";\n\nexport interface ExplorerServerOptions {\n port?: number;\n host?: string;\n /**\n * Path to the dist directory containing the built frontend.\n * If not provided, static file serving will be disabled.\n */\n distPath?: string;\n}\n\nexport class ExplorerServer {\n private app: express.Application;\n private server?: ReturnType<typeof this.app.listen>;\n\n constructor(\n private afs: AFS,\n private options: ExplorerServerOptions = {},\n ) {\n this.app = express();\n this.setupMiddleware();\n this.setupRoutes();\n }\n\n private setupMiddleware() {\n this.app.use(cors());\n this.app.use(express.json());\n }\n\n private setupRoutes() {\n // API Routes\n this.app.get(\"/api/list\", async (req, res) => {\n const path = (req.query.path as string) || \"/\";\n const maxDepth = req.query.maxDepth ? Number.parseInt(req.query.maxDepth as string, 10) : 1;\n const result = await this.afs.list(path, { maxDepth });\n res.json(result);\n });\n\n this.app.get(\"/api/read\", async (req, res) => {\n const path = req.query.path as string;\n if (!path) {\n res.status(400).json({ error: \"Path is required\" });\n return;\n }\n const result = await this.afs.read(path);\n res.json(result);\n });\n\n this.app.get(\"/api/search\", async (req, res) => {\n const path = (req.query.path as string) || \"/\";\n const query = req.query.query as string;\n if (!query) {\n res.status(400).json({ error: \"Query is required\" });\n return;\n }\n const result = await this.afs.search(path, query);\n res.json(result);\n });\n\n // Serve static files from the dist directory (if provided)\n if (this.options.distPath) {\n const distPath = path.resolve(this.options.distPath);\n this.app.use(express.static(distPath));\n this.app.get(\"/{*splat}\", (_req, res) => {\n res.sendFile(\"index.html\", { root: distPath });\n });\n }\n\n // Global error handler\n this.app.use(\n (err: Error, _req: express.Request, res: express.Response, _next: express.NextFunction) => {\n res.status(500).json({ error: err.message || String(err) });\n },\n );\n }\n\n async start(): Promise<void> {\n const port = this.options.port || 3000;\n const host = this.options.host || \"localhost\";\n\n return new Promise((resolve) => {\n this.server = this.app.listen(port, host, () => {\n resolve();\n });\n });\n }\n\n async stop(): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.server) {\n this.server.close((err) => {\n // Ignore ERR_SERVER_NOT_RUNNING error\n if (err && (err as NodeJS.ErrnoException).code !== \"ERR_SERVER_NOT_R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