@@ -91,6 +91,24 @@ function validateInputName(name, type = "input") {
91
91
return { valid : true , value : cleaned } ;
92
92
}
93
93
94
+ /**
95
+ * Extracts content from various formats with fallback
96
+ */
97
+ function extractContent ( content , fallback = "" ) {
98
+ if ( typeof content === "object" && content !== null ) {
99
+ if ( content . text !== undefined && content . text !== null ) {
100
+ return content . text ;
101
+ } else if ( content . blob !== undefined && content . blob !== null ) {
102
+ return content . blob ;
103
+ } else if ( content . content !== undefined && content . content !== null ) {
104
+ return content . content ;
105
+ } else {
106
+ return JSON . stringify ( content , null , 2 ) ;
107
+ }
108
+ }
109
+ return String ( content || fallback ) ;
110
+ }
111
+
94
112
/**
95
113
* SECURITY: Validate URL inputs
96
114
*/
@@ -1527,10 +1545,18 @@ async function viewResource(resourceUri) {
1527
1545
const contentPre = document . createElement ( "pre" ) ;
1528
1546
contentPre . className =
1529
1547
"mt-1 bg-gray-100 p-2 rounded overflow-auto max-h-80 dark:bg-gray-800 dark:text-gray-100" ;
1530
- contentPre . textContent =
1531
- typeof content === "object"
1532
- ? JSON . stringify ( content , null , 2 )
1533
- : String ( content ) ; // Safe text content
1548
+
1549
+ // Handle content display - extract actual content from object if needed
1550
+ let contentStr = extractContent (
1551
+ content ,
1552
+ resource . description || "No content available" ,
1553
+ ) ;
1554
+
1555
+ if ( ! contentStr . trim ( ) ) {
1556
+ contentStr = resource . description || "No content available" ;
1557
+ }
1558
+
1559
+ contentPre . textContent = contentStr ;
1534
1560
contentDiv . appendChild ( contentPre ) ;
1535
1561
container . appendChild ( contentDiv ) ;
1536
1562
@@ -1621,7 +1647,6 @@ async function editResource(resourceUri) {
1621
1647
const data = await response . json ( ) ;
1622
1648
const resource = data . resource ;
1623
1649
const content = data . content ;
1624
-
1625
1650
const isInactiveCheckedBool = isInactiveChecked ( "resources" ) ;
1626
1651
let hiddenField = safeGetElement ( "edit-resource-show-inactive" ) ;
1627
1652
if ( ! hiddenField ) {
@@ -1665,19 +1690,29 @@ async function editResource(resourceUri) {
1665
1690
mimeField . value = resource . mimeType || "" ;
1666
1691
}
1667
1692
if ( contentField ) {
1668
- const contentStr =
1669
- typeof content === "object"
1670
- ? JSON . stringify ( content , null , 2 )
1671
- : String ( content ) ;
1693
+ let contentStr = extractContent (
1694
+ content ,
1695
+ resource . description || "No content available" ,
1696
+ ) ;
1697
+
1698
+ if ( ! contentStr . trim ( ) ) {
1699
+ contentStr = resource . description || "No content available" ;
1700
+ }
1701
+
1672
1702
contentField . value = contentStr ;
1673
1703
}
1674
1704
1675
1705
// Update CodeMirror editor if it exists
1676
1706
if ( window . editResourceContentEditor ) {
1677
- const contentStr =
1678
- typeof content === "object"
1679
- ? JSON . stringify ( content , null , 2 )
1680
- : String ( content ) ;
1707
+ let contentStr = extractContent (
1708
+ content ,
1709
+ resource . description || "No content available" ,
1710
+ ) ;
1711
+
1712
+ if ( ! contentStr . trim ( ) ) {
1713
+ contentStr = resource . description || "No content available" ;
1714
+ }
1715
+
1681
1716
window . editResourceContentEditor . setValue ( contentStr ) ;
1682
1717
window . editResourceContentEditor . refresh ( ) ;
1683
1718
}
0 commit comments