summaryrefslogtreecommitdiff
path: root/internal/api/nodeinfo
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-02-04 16:52:42 +0100
committerLibravatar GitHub <noreply@github.com>2025-02-04 16:52:42 +0100
commit07d27709957248008c61d6b8d553e3d2eb14d154 (patch)
treed054e92729708e275886100492a458d633fbaa59 /internal/api/nodeinfo
parentadds support for build specifically without wasm ffmpeg (#3732) (diff)
downloadgotosocial-07d27709957248008c61d6b8d553e3d2eb14d154.tar.xz
[feature] Change `instance-stats-randomize` to `instance-stats-mode` with multiple options; implement nodeinfo 2.1 (#3734)
* [feature] Change `instance-stats-randomize` to `instance-stats-mode` with multiple options; implement nodeinfo 2.1 * swaggalaggadingdong
Diffstat (limited to 'internal/api/nodeinfo')
-rw-r--r--internal/api/nodeinfo/nodeinfo.go11
-rw-r--r--internal/api/nodeinfo/nodeinfoget.go32
2 files changed, 36 insertions, 7 deletions
diff --git a/internal/api/nodeinfo/nodeinfo.go b/internal/api/nodeinfo/nodeinfo.go
index bf334b5e2..96adbc956 100644
--- a/internal/api/nodeinfo/nodeinfo.go
+++ b/internal/api/nodeinfo/nodeinfo.go
@@ -25,9 +25,12 @@ import (
)
const (
- NodeInfo2Version = "2.0"
- NodeInfo2Path = "/" + NodeInfo2Version
- NodeInfo2ContentType = "application/json; profile=\"http://nodeinfo.diaspora.software/ns/schema/" + NodeInfo2Version + "#\""
+ NodeInfo20 = "2.0"
+ NodeInfo20ContentType = "application/json; profile=\"http://nodeinfo.diaspora.software/ns/schema/" + NodeInfo20 + "#\""
+ NodeInfo21 = "2.1"
+ NodeInfo21ContentType = "application/json; profile=\"http://nodeinfo.diaspora.software/ns/schema/" + NodeInfo21 + "#\""
+ NodeInfoSchema = "schema"
+ NodeInfoPath = "/:" + NodeInfoSchema
)
type Module struct {
@@ -41,5 +44,5 @@ func New(processor *processing.Processor) *Module {
}
func (m *Module) Route(attachHandler func(method string, path string, f ...gin.HandlerFunc) gin.IRoutes) {
- attachHandler(http.MethodGet, NodeInfo2Path, m.NodeInfo2GETHandler)
+ attachHandler(http.MethodGet, NodeInfoPath, m.NodeInfo2GETHandler)
}
diff --git a/internal/api/nodeinfo/nodeinfoget.go b/internal/api/nodeinfo/nodeinfoget.go
index 368a5503d..28a60cff9 100644
--- a/internal/api/nodeinfo/nodeinfoget.go
+++ b/internal/api/nodeinfo/nodeinfoget.go
@@ -18,6 +18,7 @@
package nodeinfo
import (
+ "errors"
"net/http"
"github.com/gin-gonic/gin"
@@ -25,7 +26,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
-// NodeInfo2GETHandler swagger:operation GET /nodeinfo/2.0 nodeInfoGet
+// NodeInfo2GETHandler swagger:operation GET /nodeinfo/{schema_version} nodeInfoGet
//
// Returns a compliant nodeinfo response to node info queries.
//
@@ -35,8 +36,17 @@ import (
// tags:
// - nodeinfo
//
+// parameters:
+// -
+// name: schema_version
+// type: string
+// description: Schema version of nodeinfo to request. 2.0 and 2.1 are currently supported.
+// in: path
+// required: true
+//
// produces:
// - application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.0#"
+// - application/json; profile="http://nodeinfo.diaspora.software/ns/schema/2.1#"
//
// responses:
// '200':
@@ -48,7 +58,23 @@ func (m *Module) NodeInfo2GETHandler(c *gin.Context) {
return
}
- nodeInfo, errWithCode := m.processor.Fedi().NodeInfoGet(c.Request.Context())
+ var (
+ contentType string
+ schemaVersion = c.Param(NodeInfoSchema)
+ )
+
+ switch schemaVersion {
+ case NodeInfo20:
+ contentType = NodeInfo20ContentType
+ case NodeInfo21:
+ contentType = NodeInfo21ContentType
+ default:
+ const errText = "only nodeinfo 2.0 and 2.1 are supported"
+ apiutil.ErrorHandler(c, gtserror.NewErrorNotFound(errors.New(errText), errText), m.processor.InstanceGetV1)
+ return
+ }
+
+ nodeInfo, errWithCode := m.processor.Fedi().NodeInfoGet(c.Request.Context(), schemaVersion)
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
@@ -59,7 +85,7 @@ func (m *Module) NodeInfo2GETHandler(c *gin.Context) {
c.Writer,
c.Request,
http.StatusOK,
- NodeInfo2ContentType,
+ contentType,
nodeInfo,
)
}