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

Function GetTaskPluginIcon

controller/task_plugin.go:479–505  ·  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

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

Calls 6

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