Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions cmd/rmtool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,30 @@ func setupClient(s settings) (*api.Client, error) {
return client, nil
}

func promptUserForRegCode() (string, error) {
fmt.Print("Enter one-time code (go to https://my.remarkable.com/device/connect/desktop): ")
var code string

// Taking input from user
_, err := fmt.Scanln(&code)
if err != nil {
return "", err
}

if len(code) != 8 {
fmt.Printf("Code has the wrong length, it should be 8, but got %d '%s'\n", len(code), code)
return promptUserForRegCode()
}

return code, nil
}

func register(s settings, client *api.Client) error {
fmt.Printf("Register rmtool with remarkable\n")
// TODO: prompt user
code := ""

code, err := promptUserForRegCode()
if err != nil {
return err
}
token, err := client.Register(code)
if err != nil {
return err
Expand All @@ -173,6 +193,8 @@ func readToken(s settings) (string, error) {
}

func saveToken(s settings, token string) {
// ignoring error b/c we have error handling for the case of unable to write the token
_ = os.MkdirAll(s.dataDir, 0755)
tokenfile := filepath.Join(s.dataDir, "device-token")
f, err := os.Create(tokenfile)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (

// Default URLs
const (
AuthURL = "https://my.remarkable.com"
//
AuthURL = "https://webapp-production-dot-remarkable-production.appspot.com"
StorageDiscoveryURL = "https://service-manager-production-dot-remarkable-production.appspot.com/service/json/1/document-storage?environment=production&group=auth0%7C5a68dc51cb30df3877a1d7c4&apiVer=2"
NotificationsDiscoveryURL = "https://service-manager-production-dot-remarkable-production.appspot.com/service/json/1/notifications?environment=production&group=auth0%7C5a68dc51cb30df3877a1d7c4&apiVer=1"
)
Expand Down Expand Up @@ -538,6 +539,10 @@ func (c *Client) Register(code string) (string, error) {
return "", err
}

_, err = parseTokenExpiration(token)
if err != nil {
return "", fmt.Errorf("unable to parse provided token - %w", err)
}
c.deviceToken = token
c.userToken = ""

Expand Down
1 change: 1 addition & 0 deletions pkg/api/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/akeil/rmtool/internal/logging"
)

// Implements the Repository interface
type repo struct {
client *Client
dataDir string
Expand Down
3 changes: 2 additions & 1 deletion pkg/fs/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"time"

"github.com/akeil/rmtool"
fsx "github.com/akeil/rmtool/internal/errors"
"github.com/akeil/rmtool/internal/errors"
fsx "github.com/akeil/rmtool/internal/fs"
"github.com/akeil/rmtool/internal/logging"
)

// Implements the Repository interface
type repo struct {
base string
}
Expand Down