Skip to content

Commit

Permalink
fix: fix some endpoints checks
Browse files Browse the repository at this point in the history
  • Loading branch information
zAlweNy26 committed Oct 12, 2024
1 parent 74af095 commit 815d420
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ dist
.yarn/install-state.gz
.pnp.*
**/tmp**
src/mad_hatter/core_plugin/settings.json
src/plugins/*
src/assets/*
data/*
Expand Down
2 changes: 1 addition & 1 deletion src/routes/memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const memoryRoutes = new Elysia({
const info = await cat.vectorMemory.db.getCollection(collection)
infos.push({
name: collection,
size: info.vectors_count ?? 0,
size: info.points_count ?? 0,
})
}
return {
Expand Down
8 changes: 6 additions & 2 deletions src/routes/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mkdir, readdir } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { basename, join } from 'node:path'
import { pluginInfo, pluginSettings, serverContext, swaggerTags } from '@/context'
import { Elysia, t } from 'elysia'
import { zodToJsonSchema } from 'zod-to-json-schema'
Expand Down Expand Up @@ -45,7 +45,7 @@ export const pluginsRoutes = new Elysia({
const id = params.pluginId
const p = mh.getPlugin(id)
if (!p) throw HttpError.NotFound('Plugin not found')
if (p.id === 'core_plugin') throw HttpError.InternalServer('Cannot delete core plugin')
if (p.id === 'core_plugin') throw HttpError.InternalServer('Cannot delete core_plugin')
try {
await mh.removePlugin(id)
}
Expand Down Expand Up @@ -74,6 +74,8 @@ export const pluginsRoutes = new Elysia({
await mkdir(extractDir, { recursive: true })
const tempFilePath = join(extractDir, file.name)

if (basename(tempFilePath) === 'core_plugin') throw HttpError.InternalServer('Cannot install a plugin with same id as core_plugin')

const decompressed = Bun.gunzipSync(await file.arrayBuffer())
await Bun.write(tempFilePath, decompressed)
const files = await readdir(tempFilePath)
Expand Down Expand Up @@ -112,6 +114,7 @@ export const pluginsRoutes = new Elysia({
}).post('/upload/registry', async ({ body, log }) => {
const { url } = body
log.info(`Installing plugin from registry: ${url}`)
// TODO: Add registry support
return {
info: 'Plugin is being installed asynchronously',
}
Expand All @@ -132,6 +135,7 @@ export const pluginsRoutes = new Elysia({
},
}).patch('/toggle/:pluginId', async ({ body, params, mh, HttpError }) => {
const id = params.pluginId
if (id === 'core_plugin') throw HttpError.InternalServer('Cannot toggle core_plugin')
const p = mh.getPlugin(id)
if (!p) throw HttpError.NotFound('Plugin not found')
const { active } = body
Expand Down

0 comments on commit 815d420

Please sign in to comment.