connect.go 634 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//go:build windows || darwin

package auth

import (
	"encoding/base64"
	"fmt"
	"net/url"
	"os"

	"github.com/ollama/ollama/auth"
)

// BuildConnectURL generates the connect URL with the public key and device name
func BuildConnectURL(baseURL string) (string, error) {
	pubKey, err := auth.GetPublicKey()
	if err != nil {
		return "", fmt.Errorf("failed to get public key: %w", err)
	}

	encodedKey := base64.RawURLEncoding.EncodeToString([]byte(pubKey))
	hostname, _ := os.Hostname()
	encodedDevice := url.QueryEscape(hostname)

	return fmt.Sprintf("%s/connect?name=%s&key=%s&launch=true", baseURL, encodedDevice, encodedKey), nil
}