From 59aad78f66cf58be7f88f2c0675f94a858163560 Mon Sep 17 00:00:00 2001 From: r Date: Tue, 17 Dec 2019 20:17:25 +0000 Subject: Use filesystem based kv store instead of sqlite --- service/service.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'service/service.go') 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 } -- cgit v1.2.3