aboutsummaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorr <r@freesoftwareextremist.com>2019-12-17 20:17:25 +0000
committerr <r@freesoftwareextremist.com>2019-12-17 20:17:25 +0000
commit59aad78f66cf58be7f88f2c0675f94a858163560 (patch)
tree95f00d18a8c847cdf4ee587e412de26960770a28 /service
parent3b50f40c081c499c2ecb8913b54186c622561d76 (diff)
downloadbloat-59aad78f66cf58be7f88f2c0675f94a858163560.tar.gz
bloat-59aad78f66cf58be7f88f2c0675f94a858163560.zip
Use filesystem based kv store instead of sqlite
Diffstat (limited to 'service')
-rw-r--r--service/auth.go4
-rw-r--r--service/service.go24
2 files changed, 16 insertions, 12 deletions
diff --git a/service/auth.go b/service/auth.go
index e9bec38..38c0a43 100644
--- a/service/auth.go
+++ b/service/auth.go
@@ -40,12 +40,12 @@ func (s *authService) getClient(ctx context.Context) (c *mastodon.Client, err er
if err != nil {
return nil, ErrInvalidSession
}
- client, err := s.appRepo.Get(session.InstanceURL)
+ client, err := s.appRepo.Get(session.InstanceDomain)
if err != nil {
return
}
c = mastodon.NewClient(&mastodon.Config{
- Server: session.InstanceURL,
+ Server: client.InstanceURL,
ClientID: client.ClientID,
ClientSecret: client.ClientSecret,
AccessToken: session.AccessToken,
diff --git a/service/service.go b/service/service.go
index 5181475..bb03c26 100644
--- a/service/service.go
+++ b/service/service.go
@@ -9,7 +9,6 @@ import (
"mime/multipart"
"net/http"
"net/url"
- "path"
"strings"
"mastodon"
@@ -64,14 +63,18 @@ func NewService(clientName string, clientScope string, clientWebsite string,
func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
redirectUrl string, sessionID string, err error) {
- if !strings.HasPrefix(instance, "https://") {
- instance = "https://" + instance
+ var instanceURL string
+ if strings.HasPrefix(instance, "https://") {
+ instanceURL = instance
+ instance = strings.TrimPrefix(instance, "https://")
+ } else {
+ instanceURL = "https://" + instance
}
sessionID = util.NewSessionId()
err = svc.sessionRepo.Add(model.Session{
- ID: sessionID,
- InstanceURL: instance,
+ ID: sessionID,
+ InstanceDomain: instance,
})
if err != nil {
return
@@ -85,7 +88,7 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
var mastoApp *mastodon.Application
mastoApp, err = mastodon.RegisterApp(ctx, &mastodon.AppConfig{
- Server: instance,
+ Server: instanceURL,
ClientName: svc.clientName,
Scopes: svc.clientScope,
Website: svc.clientWebsite,
@@ -96,9 +99,10 @@ func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
}
app = model.App{
- InstanceURL: instance,
- ClientID: mastoApp.ClientID,
- ClientSecret: mastoApp.ClientSecret,
+ InstanceDomain: instance,
+ InstanceURL: instanceURL,
+ ClientID: mastoApp.ClientID,
+ ClientSecret: mastoApp.ClientSecret,
}
err = svc.appRepo.Add(app)
@@ -136,7 +140,7 @@ func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *masto
return
}
- app, err := svc.appRepo.Get(session.InstanceURL)
+ app, err := svc.appRepo.Get(session.InstanceDomain)
if err != nil {
return
}