-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add gnodev make rule Signed-off-by: Norman Meier <[email protected]> * feat: gno cockpit init Signed-off-by: Norman Meier <[email protected]> * chore: reduce func complexity Signed-off-by: Norman Meier <[email protected]> * chore: use profile constant Signed-off-by: Norman Meier <[email protected]> * feat: add bio Signed-off-by: Norman Meier <[email protected]> * tmp: improve Signed-off-by: Norman Meier <[email protected]> * tmp: improve Signed-off-by: Norman Meier <[email protected]> * chore: bio placeholder Signed-off-by: Norman Meier <[email protected]> * fix: support gnobro Signed-off-by: Norman Meier <[email protected]> * chore: address last and compact Signed-off-by: Norman Meier <[email protected]> * feat: dynamic examples Signed-off-by: Norman Meier <[email protected]> --------- Signed-off-by: Norman Meier <[email protected]>
- Loading branch information
Showing
3 changed files
with
99 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module gno.land/r/teritori/cockpit | ||
|
||
require ( | ||
gno.land/p/demo/mux v0.0.0-latest | ||
gno.land/p/demo/users v0.0.0-latest | ||
gno.land/r/demo/profile v0.0.0-latest | ||
gno.land/r/demo/users v0.0.0-latest | ||
gno.land/r/gnoland/ghverify v0.0.0-latest | ||
) |
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package cockpit | ||
|
||
import ( | ||
"std" | ||
|
||
"gno.land/p/demo/mux" | ||
"gno.land/p/demo/users" | ||
"gno.land/r/demo/profile" | ||
rusers "gno.land/r/demo/users" | ||
"gno.land/r/gnoland/ghverify" | ||
) | ||
|
||
const ( | ||
chainId = "test4" | ||
pkgPath = "r/teritori/cockpit" | ||
userSlug = "u" | ||
usersRealm = "r/demo/users" | ||
ghLinkHint = "r/gnoland/ghverify?help&__func=RequestVerification" | ||
ghProfileHint = "/r/demo/profile:u/" | ||
) | ||
|
||
func Render(reqPath string) string { | ||
router := mux.NewRouter() | ||
|
||
router.HandleFunc("", renderHome) | ||
router.HandleFunc(userSlug+"/{aon}", renderUser) | ||
|
||
return router.Render(reqPath) | ||
} | ||
|
||
func renderHome(res *mux.ResponseWriter, req *mux.Request) { | ||
res.Write("# Cockpit\n\n") | ||
res.Write("See `:" + userSlug + "/{addressOrName}`\n\n") | ||
res.Write("Examples:\n") | ||
elems := rusers.ListUsersByPrefix("", 20) | ||
for _, elem := range elems { | ||
res.Write("- [ " + elem + " ](./" + pkgPath + ":" + userSlug + "/@" + elem + ")\n") | ||
} | ||
} | ||
|
||
func renderUser(res *mux.ResponseWriter, req *mux.Request) { | ||
addr, username, ok := resolveUserBasics(req.GetVar("aon")) | ||
if !ok { | ||
res.Write("404") | ||
return | ||
} | ||
|
||
// FIXME: markdown injection, spam | ||
res.Write("# " + profile.GetStringField(addr, profile.DisplayName, "Anon") + "\n") | ||
|
||
if username != "" { | ||
res.Write("- Username: [" + username + "](/" + usersRealm + ":" + username + ")\n") | ||
} else { | ||
res.Write("- Username: [Not registered](/" + usersRealm + "?help&__func=Register)\n") | ||
} | ||
|
||
handle := ghverify.GetHandleByAddress(addr.String()) | ||
if handle != "" { | ||
res.Write("- GitHub: [" + handle + "](https://github.com/" + handle + ")\n") | ||
} else { | ||
res.Write("- GitHub: [Not linked](/" + ghLinkHint + ")\n") | ||
} | ||
|
||
res.Write("- Address: [" + addr.String() + "](https://gnoscan.io/accounts/" + addr.String() + "?chainId=" + chainId + ")\n\n") | ||
|
||
// FIXME: markdown injection, spam | ||
res.Write("```\n" + profile.GetStringField(addr, profile.Bio, "No bio") + "\n```\n[Full profile / edit](" + ghProfileHint + addr.String() + ")\n") | ||
} | ||
|
||
func resolveUserBasics(aon string) (std.Address, string, bool) { | ||
user := rusers.GetUserByAddressOrName(users.AddressOrName(aon)) | ||
if user != nil { | ||
return user.Address, user.Name, true | ||
} | ||
|
||
addr := std.Address(aon) | ||
if addr.IsValid() { | ||
return addr, "", true | ||
} | ||
|
||
return addr, "", false | ||
} |