Skip to content

Conversation

@xrehpicx
Copy link

Summary

  • Accept invite links from custom hosts (http(s):///#) instead of hard-coded invite.any.coop
  • Add persisted networkId (via existing ~/.anytype/config.json) and use it as the default for anytype space join when --network isn't provided
  • Document self-hosted usage in README
  • Add tests for invite parsing and networkId config

Problem

Self-hosted invites are rejected with: invalid invite link format, expected: https://invite.any.coop/{cid}#{key}

Fixes #6

Testing

  • /Users/raj/sdk/go1.24.6/bin/go test ./...

- Accept invite links from custom hosts (http(s)://<host>/<cid>#<key>)

- Add persisted config networkId and use it as default for space join

- Document self-hosted usage in README

Tests: go test ./...
@xrehpicx xrehpicx marked this pull request as ready for review December 15, 2025 17:47
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for self-hosted invite links, allowing users to accept invites from custom hosts instead of being restricted to the hard-coded invite.any.coop domain. The implementation includes configuration persistence, fallback behavior, comprehensive tests, and updated documentation.

  • Adds a persisted networkId field to the config.json file with getter/setter helper functions
  • Updates invite link parsing to accept any valid HTTP/HTTPS host instead of validating against a hard-coded domain
  • Implements network ID fallback logic: command flag → stored config → default Anytype network

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
core/config/config.go Adds NetworkId field to Config struct and SetNetworkId method to ConfigManager
core/config/config_helper.go Implements GetNetworkIdFromConfig and SetNetworkIdToConfig helper functions
core/config/config_test.go Adds test coverage for NetworkId field persistence
core/config/config_helper_test.go Adds comprehensive tests for NetworkId helpers and improves existing test assertions
cmd/space/join/join.go Refactors invite parsing to support custom hosts and implements networkId fallback logic
cmd/space/join/join_test.go Adds comprehensive tests for invite link parsing with various host patterns
cmd/config/set/set.go Adds networkId as a settable config key
cmd/config/get/get.go Adds networkId to config output display
README.md Documents self-hosted network usage patterns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return output.Error("invite link missing Cid")
if inviteCid == "" {
if parsedCid == "" {
return output.Error("invalid invite link: invite link missing Cid in path")
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message contains redundant text. The phrase "invalid invite link: invite link missing Cid in path" repeats "invite link" unnecessarily. Consider simplifying to "invalid invite link: missing Cid in path" for clarity and conciseness.

Suggested change
return output.Error("invalid invite link: invite link missing Cid in path")
return output.Error("invalid invite link: missing Cid in path")

Copilot uses AI. Check for mistakes.
if err != nil {
return output.Error("Failed to view invite: %w", err)
if parsedKey == "" {
return output.Error("invalid invite link: invite link missing key (should be after #)")
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message contains redundant text. The phrase "invalid invite link: invite link missing key" repeats "invite link" unnecessarily. Consider simplifying to "invalid invite link: missing key (should be after #)" for clarity and conciseness.

Suggested change
return output.Error("invalid invite link: invite link missing key (should be after #)")
return output.Error("invalid invite link: missing key (should be after #)")

Copilot uses AI. Check for mistakes.
Comment on lines 109 to 121
func parseInviteLink(input string) (string, string, error) {
cid, key, err := parseInviteLinkParts(input)
if err != nil {
return "", "", err
}
if cid == "" {
return "", "", fmt.Errorf("invite link missing Cid in path")
}
if key == "" {
return "", "", fmt.Errorf("invite link missing key (should be after #)")
}
return cid, key, nil
}
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function parseInviteLink appears to be defined solely for testing purposes but is not used in the main command logic. The actual command uses parseInviteLinkParts and performs validation inline. Consider either using parseInviteLink in the command logic (lines 41-57) to reduce code duplication and improve maintainability, or add a comment explaining that parseInviteLink is a convenience wrapper for testing.

Copilot uses AI. Check for mistakes.
Comment on lines +90 to +91
if u.Scheme != "https" && u.Scheme != "http" {
return "", "", fmt.Errorf("unsupported scheme %q (expected http or https)", u.Scheme)
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code allows both HTTP and HTTPS schemes for invite links, which could pose a security risk. Invite links may contain sensitive information (CID and key), and allowing HTTP means this data could be transmitted in plaintext over unencrypted connections. Consider adding a warning when HTTP is used, restricting HTTP to localhost/development environments only, or requiring HTTPS for production use to protect sensitive invite data.

Suggested change
if u.Scheme != "https" && u.Scheme != "http" {
return "", "", fmt.Errorf("unsupported scheme %q (expected http or https)", u.Scheme)
// Only allow https for invite links in general.
// Permit http only for localhost/loopback to support development environments.
if u.Scheme != "https" {
isLocalhost := u.Host == "localhost" || strings.HasPrefix(u.Host, "127.0.0.1") || u.Host == "[::1]"
if !(u.Scheme == "http" && isLocalhost) {
return "", "", fmt.Errorf("unsupported scheme %q (expected https, or http only for localhost)", u.Scheme)
}

Copilot uses AI. Check for mistakes.
@xrehpicx
Copy link
Author

Fixed the lint issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for self-hosted networks

2 participants