MCPcopy Create free account
hub / github.com/R44VC0RP/opencode.cafe / AdminImportPage

Function AdminImportPage

app/admin/import/page.tsx:42–450  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

40}
41
42export default function AdminImportPage() {
43 const isAdmin = useQuery(api.admin.isAdmin)
44 const bulkImport = useMutation(api.admin.bulkImport)
45
46 const [jsonInput, setJsonInput] = useState("")
47 const [parseError, setParseError] = useState<string | null>(null)
48 const [parsedExtensions, setParsedExtensions] = useState<ExtensionInput[]>([])
49 const [isImporting, setIsImporting] = useState(false)
50 const [importResult, setImportResult] = useState<BulkImportResponse | null>(null)
51 const fileInputRef = useRef<HTMLInputElement>(null)
52
53 const parseJson = (jsonString: string): boolean => {
54 setParseError(null)
55 setParsedExtensions([])
56 setImportResult(null)
57
58 if (!jsonString.trim()) {
59 setParseError("Please enter JSON data")
60 return false
61 }
62
63 try {
64 const parsed = JSON.parse(jsonString)
65
66 // Handle both array and single object
67 const items = Array.isArray(parsed) ? parsed : [parsed]
68
69 if (items.length === 0) {
70 setParseError("No extensions found in JSON")
71 return false
72 }
73
74 // Validate each extension
75 const validated: ExtensionInput[] = []
76 const errors: string[] = []
77
78 for (let i = 0; i < items.length; i++) {
79 const item = items[i]
80 const prefix = items.length > 1 ? `Item ${i + 1}: ` : ""
81
82 // Required fields
83 if (!item.productId) {
84 errors.push(`${prefix}Missing productId`)
85 continue
86 }
87 if (!item.type) {
88 errors.push(`${prefix}Missing type`)
89 continue
90 }
91 if (!VALID_TYPES.includes(item.type)) {
92 errors.push(`${prefix}Invalid type "${item.type}"`)
93 continue
94 }
95 if (!item.displayName) {
96 errors.push(`${prefix}Missing displayName`)
97 continue
98 }
99 if (!item.description) {

Callers

nothing calls this directly

Calls 1

parseJsonFunction · 0.85

Tested by

no test coverage detected