MCPcopy Create free account
hub / github.com/QuantumNous/new-api / GetTaskPluginIcon

Function GetTaskPluginIcon

controller/task_plugin.go:480–506  ·  view source on GitHub ↗

GetTaskPluginIcon serves a plugin logo as an image. The active override wins (or the requested ?version=), then the factory sidecar. Data icons are only ever drawn through , and the nosniff header keeps a browser from treating an SVG response as a document.

(c *gin.Context)

Source from the content-addressed store, hash-verified

478// ever drawn through <img>, and the nosniff header keeps a browser from
479// treating an SVG response as a document.
480func GetTaskPluginIcon(c *gin.Context) {
481 key := c.Param("key")
482 icon := ""
483 plugin, err := model.GetTaskPluginVersion(key, c.Query("version"))
484 if err == nil {
485 icon = string(plugin.Icon)
486 } else if !errors.Is(err, gorm.ErrRecordNotFound) {
487 common.ApiError(c, err)
488 return
489 }
490 if icon == "" && c.Query("version") == "" {
491 icon = plugins.IconDataURI(key)
492 }
493 if icon == "" {
494 c.AbortWithStatus(http.StatusNotFound)
495 return
496 }
497 mediaType, data, err := jsplugin.DecodeIconDataURI(icon)
498 if err != nil {
499 c.AbortWithStatus(http.StatusNotFound)
500 return
501 }
502 c.Header("Cache-Control", "private, max-age=3600")
503 c.Header("X-Content-Type-Options", "nosniff")
504 c.Header("Content-Security-Policy", "default-src 'none'; style-src 'unsafe-inline'; sandbox")
505 c.Data(http.StatusOK, mediaType, data)
506}
507
508func GetTaskPlugin(c *gin.Context) {
509 key := c.Param("key")

Calls 5

GetTaskPluginVersionFunction · 0.92
ApiErrorFunction · 0.92
IconDataURIFunction · 0.92
QueryMethod · 0.80
HeaderMethod · 0.45