-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,137 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/EmissarySocial/emissary/server" | ||
"github.com/benpate/derp" | ||
"github.com/benpate/domain" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
// GetNodeInfo returns public webfinger information for a designated user | ||
func GetNodeInfo(factory *server.Factory) echo.HandlerFunc { | ||
// GetNodeInfo returns the discovery links for nodeInfo endpoints | ||
// http://nodeinfo.diaspora.software/protocol.html | ||
// http://nodeinfo.diaspora.software/schema.html | ||
func GetNodeInfo(serverFactory *server.Factory) echo.HandlerFunc { | ||
|
||
return func(ctx echo.Context) error { | ||
|
||
return nil | ||
host := ctx.Request().Host | ||
server := domain.AddProtocol(host) | ||
|
||
result := map[string]any{ | ||
"links": []map[string]any{ | ||
{ | ||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0", | ||
"href": server + "/.well-known/nodeinfo/2.0", | ||
}, | ||
{ | ||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.1", | ||
"href": server + "/.well-known/nodeinfo/2.1", | ||
}, | ||
}, | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, result) | ||
} | ||
} | ||
|
||
// GetNodeInfo20 returns the nodeInfo 2.0 document for this server | ||
// http://nodeinfo.diaspora.software/ns/schema/2.0 | ||
// http://nodeinfo.diaspora.software/docson/index.html#/ns/schema/2.0#$$expand | ||
func GetNodeInfo20(serverFactory *server.Factory) echo.HandlerFunc { | ||
|
||
return func(ctx echo.Context) error { | ||
|
||
factory, err := serverFactory.ByContext(ctx) | ||
|
||
if err != nil { | ||
return derp.Wrap(err, "handler.GetNodeInfo20", "Error loading server factory") | ||
} | ||
|
||
// Get the Domain | ||
domainService := factory.Domain() | ||
domain, err := domainService.LoadDomain() | ||
|
||
if err != nil { | ||
return derp.Wrap(err, "handler.GetNodeInfo20", "Error loading domain") | ||
} | ||
|
||
result := map[string]any{ | ||
"version": "2.0", | ||
"software": map[string]any{ | ||
"name": "Emissary", | ||
"version": serverFactory.Version(), | ||
}, | ||
"protocols": []string{"activitypub"}, | ||
"services": map[string]any{ | ||
"inbound": []string{"atom1.0", "rss2.0"}, | ||
"outbound": []string{"atom1.0", "rss2.0"}, | ||
}, | ||
"openRegistrations": domain.SignupForm.Active, | ||
"usage": map[string]any{ | ||
"users": map[string]any{ | ||
"total": 0, | ||
"activeHalfYear": 0, | ||
"activeMonth": 0, | ||
}, | ||
"localPosts": 0, | ||
"localComments": 0, | ||
}, | ||
"metadata": map[string]any{}, | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, result) | ||
} | ||
} | ||
|
||
// GetNodeInfo21 returns the nodeInfo 2.1 document for this server | ||
// http://nodeinfo.diaspora.software/ns/schema/2.1 | ||
// http://nodeinfo.diaspora.software/docson/index.html#/ns/schema/2.1#$$expand | ||
func GetNodeInfo21(serverFactory *server.Factory) echo.HandlerFunc { | ||
|
||
return func(ctx echo.Context) error { | ||
|
||
factory, err := serverFactory.ByContext(ctx) | ||
|
||
if err != nil { | ||
return derp.Wrap(err, "handler.GetNodeInfo20", "Error loading server factory") | ||
} | ||
|
||
// Get the Domain | ||
domainService := factory.Domain() | ||
domain, err := domainService.LoadDomain() | ||
|
||
if err != nil { | ||
return derp.Wrap(err, "handler.GetNodeInfo20", "Error loading domain") | ||
} | ||
|
||
result := map[string]any{ | ||
"version": "2.1", | ||
"software": map[string]any{ | ||
"name": "Emissary", | ||
"version": serverFactory.Version(), | ||
"repository": "https://github.com/EmissarySocial/emissary", | ||
"homepage": "https://emissary.social", | ||
}, | ||
"protocols": []string{"activitypub"}, | ||
"services": map[string]any{ | ||
"inbound": []string{"atom1.0", "rss2.0"}, | ||
"outbound": []string{"atom1.0", "rss2.0"}, | ||
}, | ||
"openRegistrations": domain.SignupForm.Active, | ||
"usage": map[string]any{ | ||
"users": map[string]any{ | ||
"total": 0, | ||
"activeHalfYear": 0, | ||
"activeMonth": 0, | ||
}, | ||
"localPosts": 0, | ||
"localComments": 0, | ||
}, | ||
"metadata": map[string]any{}, | ||
} | ||
|
||
return ctx.JSON(http.StatusOK, result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters