mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add comprehensive JSONC support for opencode.jsonc files
- Store raw JSONC content in database, parse on-the-fly for validation - Return rawContent field in API response for editing with comments preserved - Update frontend to use rawContent for config editing - Accept string or object content in create/update requests - Download configs as .jsonc when they contain comments - Add strip-json-comments dependency for JSONC parsing - Add .jsonc MIME type support in backend file service This preserves comments in opencode.jsonc files when editing through the UI
This commit is contained in:
1 parent
7a647cb316
commit
4eec4e5c27
12 files changed
+138
-66
No files matched your search
@@ -4,12 +4,13 @@ import { Label } from '@/components/ui/label'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import type { OpenCodeConfig } from '@/api/types/settings'
|
||||
import stripJsonComments from 'strip-json-comments'
|
||||
|
||||
interface OpenCodeConfigEditorProps {
|
||||
config: OpenCodeConfig | null
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onUpdate: (content: Record<string, unknown>) => Promise<void>
|
||||
onUpdate: (content: string) => Promise<void>
|
||||
isUpdating: boolean
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ export function OpenCodeConfigEditor({
|
||||
|
||||
useEffect(() => {
|
||||
if (config && isOpen) {
|
||||
setEditConfigContent(JSON.stringify(config.content, null, 2))
|
||||
setEditConfigContent(config.rawContent || JSON.stringify(config.content, null, 2))
|
||||
setEditError('')
|
||||
setEditErrorLine(null)
|
||||
}
|
||||
@@ -43,7 +44,7 @@ export function OpenCodeConfigEditor({
|
||||
if (!config) return
|
||||
|
||||
try {
|
||||
const parsedContent = JSON.parse(editConfigContent)
|
||||
const parsedContent = JSON.parse(stripJsonComments(editConfigContent))
|
||||
|
||||
const forbiddenFields = ['id', 'createdAt', 'updatedAt']
|
||||
const foundForbidden = forbiddenFields.filter(field => field in parsedContent)
|
||||
@@ -51,14 +52,14 @@ export function OpenCodeConfigEditor({
|
||||
throw new Error(`Invalid fields found: ${foundForbidden.join(', ')}. These fields are managed automatically.`)
|
||||
}
|
||||
|
||||
await onUpdate(parsedContent)
|
||||
await onUpdate(editConfigContent)
|
||||
onClose()
|
||||
} catch (error) {
|
||||
if (error instanceof SyntaxError) {
|
||||
const match = error.message.match(/line (\d+)/i)
|
||||
const line = match ? parseInt(match[1]) : null
|
||||
setEditErrorLine(line)
|
||||
setEditError('Invalid JSON format')
|
||||
setEditError('Invalid JSON/JSONC format')
|
||||
} else {
|
||||
setEditError(error instanceof Error ? error.message : 'Failed to update config')
|
||||
}
|
||||
@@ -93,7 +94,7 @@ export function OpenCodeConfigEditor({
|
||||
<div className="flex-1 p-6 overflow-hidden">
|
||||
<div className="h-full flex flex-col">
|
||||
<Label htmlFor="edit-config-content" className="mb-2">
|
||||
Config Content (JSON)
|
||||
Config Content (JSON/JSONC)
|
||||
</Label>
|
||||
<Textarea
|
||||
id="edit-config-content"
|
||||
|
||||
Reference in new issue
Block a user