Skip to content

Commit 815d420

Browse files
committed
fix: fix some endpoints checks
1 parent 74af095 commit 815d420

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ dist
126126
.yarn/install-state.gz
127127
.pnp.*
128128
**/tmp**
129+
src/mad_hatter/core_plugin/settings.json
129130
src/plugins/*
130131
src/assets/*
131132
data/*

src/routes/memory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export const memoryRoutes = new Elysia({
101101
const info = await cat.vectorMemory.db.getCollection(collection)
102102
infos.push({
103103
name: collection,
104-
size: info.vectors_count ?? 0,
104+
size: info.points_count ?? 0,
105105
})
106106
}
107107
return {

src/routes/plugins.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mkdir, readdir } from 'node:fs/promises'
22
import { tmpdir } from 'node:os'
3-
import { join } from 'node:path'
3+
import { basename, join } from 'node:path'
44
import { pluginInfo, pluginSettings, serverContext, swaggerTags } from '@/context'
55
import { Elysia, t } from 'elysia'
66
import { zodToJsonSchema } from 'zod-to-json-schema'
@@ -45,7 +45,7 @@ export const pluginsRoutes = new Elysia({
4545
const id = params.pluginId
4646
const p = mh.getPlugin(id)
4747
if (!p) throw HttpError.NotFound('Plugin not found')
48-
if (p.id === 'core_plugin') throw HttpError.InternalServer('Cannot delete core plugin')
48+
if (p.id === 'core_plugin') throw HttpError.InternalServer('Cannot delete core_plugin')
4949
try {
5050
await mh.removePlugin(id)
5151
}
@@ -74,6 +74,8 @@ export const pluginsRoutes = new Elysia({
7474
await mkdir(extractDir, { recursive: true })
7575
const tempFilePath = join(extractDir, file.name)
7676

77+
if (basename(tempFilePath) === 'core_plugin') throw HttpError.InternalServer('Cannot install a plugin with same id as core_plugin')
78+
7779
const decompressed = Bun.gunzipSync(await file.arrayBuffer())
7880
await Bun.write(tempFilePath, decompressed)
7981
const files = await readdir(tempFilePath)
@@ -112,6 +114,7 @@ export const pluginsRoutes = new Elysia({
112114
}).post('/upload/registry', async ({ body, log }) => {
113115
const { url } = body
114116
log.info(`Installing plugin from registry: ${url}`)
117+
// TODO: Add registry support
115118
return {
116119
info: 'Plugin is being installed asynchronously',
117120
}
@@ -132,6 +135,7 @@ export const pluginsRoutes = new Elysia({
132135
},
133136
}).patch('/toggle/:pluginId', async ({ body, params, mh, HttpError }) => {
134137
const id = params.pluginId
138+
if (id === 'core_plugin') throw HttpError.InternalServer('Cannot toggle core_plugin')
135139
const p = mh.getPlugin(id)
136140
if (!p) throw HttpError.NotFound('Plugin not found')
137141
const { active } = body

0 commit comments

Comments
 (0)