ai fix-02
This commit is contained in:
39
src/app.js
39
src/app.js
@@ -8,12 +8,41 @@ const { pingMongo } = require("./db/client");
|
||||
const { router: apiRouter } = require("./routes/api");
|
||||
const { openApiDocument } = require("./swagger/openapi");
|
||||
|
||||
const publicDir = path.join(__dirname, "..", "public");
|
||||
const skillFilePaths = [
|
||||
path.join(publicDir, "SKILL.md"),
|
||||
path.join(__dirname, "SKILL.md"),
|
||||
path.join(__dirname, "..", ".idea", "SKILL.md"),
|
||||
path.join(__dirname, "..", ".ai", "SKILL.md"),
|
||||
];
|
||||
|
||||
const fallbackSkillMarkdown = `# Dune API Skill For OpenClaw Agents
|
||||
|
||||
Use https://dune.api.coppnic.cc as the API base URL.
|
||||
|
||||
Prefer detailed singular datasets for OpenClaw:
|
||||
|
||||
- GET /api/item/{id}
|
||||
- GET /api/skill/{id}
|
||||
- GET /api/recipe/{id}
|
||||
- GET /api/placeable/{id}
|
||||
- GET /api/npc/{id}
|
||||
|
||||
Examples:
|
||||
|
||||
- GET /api/item/LongRifle_Unique_Poison_03?language=en
|
||||
- GET /api/skill/skills_ability_poisonmine?language=en
|
||||
- GET /api/recipe/Bloodsack_2_Recipe?language=en
|
||||
- GET /api/placeable/Atre_Banner_Placeable?language=en
|
||||
- GET /api/npc/bs43q?language=en
|
||||
|
||||
Search example:
|
||||
|
||||
- GET /api/search?q=poison&datasets=item,skill,recipe&language=en
|
||||
|
||||
Supported languages: en, de.
|
||||
`;
|
||||
|
||||
function getSkillFilePath() {
|
||||
return skillFilePaths.find((filePath) => fs.existsSync(filePath));
|
||||
}
|
||||
@@ -24,6 +53,7 @@ function createApp() {
|
||||
app.set("trust proxy", true);
|
||||
app.use(cors());
|
||||
app.use(express.json({ limit: "2mb" }));
|
||||
app.use(express.static(publicDir));
|
||||
app.use((request, response, next) => {
|
||||
const forwardedProto = request.get("x-forwarded-proto");
|
||||
const isSecure = request.secure || forwardedProto === "https";
|
||||
@@ -64,13 +94,14 @@ function createApp() {
|
||||
|
||||
app.get(["/SKILL.md", "/skill.md"], (request, response) => {
|
||||
const skillFilePath = getSkillFilePath();
|
||||
if (!skillFilePath) {
|
||||
response.status(404).json({ error: "SKILL.md not found" });
|
||||
response.type("text/markdown");
|
||||
|
||||
if (skillFilePath) {
|
||||
response.send(fs.readFileSync(skillFilePath, "utf8"));
|
||||
return;
|
||||
}
|
||||
|
||||
response.type("text/markdown");
|
||||
response.sendFile(skillFilePath);
|
||||
response.send(fallbackSkillMarkdown);
|
||||
});
|
||||
|
||||
app.use("/docs", swaggerUi.serve, swaggerUi.setup(openApiDocument));
|
||||
|
||||
Reference in New Issue
Block a user