Spaces:
Sleeping
Sleeping
fix(tools): fix tool validation in settings
Browse files
src/routes/settings/(nav)/+server.ts
CHANGED
@@ -31,12 +31,20 @@ export async function POST({ request, locals }) {
|
|
31 |
}
|
32 |
|
33 |
// make sure all tools exist
|
|
|
34 |
if (settings.tools) {
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
}
|
41 |
|
42 |
await collections.settings.updateOne(
|
|
|
31 |
}
|
32 |
|
33 |
// make sure all tools exist
|
34 |
+
// either in db or in config
|
35 |
if (settings.tools) {
|
36 |
+
const newTools = [
|
37 |
+
...(await collections.tools
|
38 |
+
.find({ _id: { $in: settings.tools.map((toolId) => new ObjectId(toolId)) } })
|
39 |
+
.project({ _id: 1 })
|
40 |
+
.toArray()
|
41 |
+
.then((tools) => tools.map((tool) => tool._id.toString()))),
|
42 |
+
...toolFromConfigs
|
43 |
+
.filter((el) => (settings?.tools ?? []).includes(el._id.toString()))
|
44 |
+
.map((el) => el._id.toString()),
|
45 |
+
];
|
46 |
+
|
47 |
+
settings.tools = newTools;
|
48 |
}
|
49 |
|
50 |
await collections.settings.updateOne(
|