1
1
import { mkdir , readdir } from 'node:fs/promises'
2
2
import { tmpdir } from 'node:os'
3
- import { join } from 'node:path'
3
+ import { basename , join } from 'node:path'
4
4
import { pluginInfo , pluginSettings , serverContext , swaggerTags } from '@/context'
5
5
import { Elysia , t } from 'elysia'
6
6
import { zodToJsonSchema } from 'zod-to-json-schema'
@@ -45,7 +45,7 @@ export const pluginsRoutes = new Elysia({
45
45
const id = params . pluginId
46
46
const p = mh . getPlugin ( id )
47
47
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 ' )
49
49
try {
50
50
await mh . removePlugin ( id )
51
51
}
@@ -74,6 +74,8 @@ export const pluginsRoutes = new Elysia({
74
74
await mkdir ( extractDir , { recursive : true } )
75
75
const tempFilePath = join ( extractDir , file . name )
76
76
77
+ if ( basename ( tempFilePath ) === 'core_plugin' ) throw HttpError . InternalServer ( 'Cannot install a plugin with same id as core_plugin' )
78
+
77
79
const decompressed = Bun . gunzipSync ( await file . arrayBuffer ( ) )
78
80
await Bun . write ( tempFilePath , decompressed )
79
81
const files = await readdir ( tempFilePath )
@@ -112,6 +114,7 @@ export const pluginsRoutes = new Elysia({
112
114
} ) . post ( '/upload/registry' , async ( { body, log } ) => {
113
115
const { url } = body
114
116
log . info ( `Installing plugin from registry: ${ url } ` )
117
+ // TODO: Add registry support
115
118
return {
116
119
info : 'Plugin is being installed asynchronously' ,
117
120
}
@@ -132,6 +135,7 @@ export const pluginsRoutes = new Elysia({
132
135
} ,
133
136
} ) . patch ( '/toggle/:pluginId' , async ( { body, params, mh, HttpError } ) => {
134
137
const id = params . pluginId
138
+ if ( id === 'core_plugin' ) throw HttpError . InternalServer ( 'Cannot toggle core_plugin' )
135
139
const p = mh . getPlugin ( id )
136
140
if ( ! p ) throw HttpError . NotFound ( 'Plugin not found' )
137
141
const { active } = body
0 commit comments