From a653c0af42025ad0b3ab86bd2a4ad044ba4ad1d4 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 24 Dec 2017 13:51:56 -0600 Subject: [PATCH] fix ID import --- app/main.go | 31 ++++++++++++++++--------------- app/migrator/disqus.go | 8 +++++++- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/main.go b/app/main.go index b254cc66..4c6252c9 100644 --- a/app/main.go +++ b/app/main.go @@ -17,21 +17,22 @@ import ( ) var opts struct { - DBFile string `long:"db" env:"BOLTDB_FILE" default:"/tmp/remark.db" description:"bolt file name"` - - SessionStore string `long:"session" env:"SESSION_STORE" default:"/tmp" description:"path to session store directory"` - StoreKey string `long:"store-key" env:"STORE_KEY" default:"secure-store-key" description:"store key"` - - GoogleCID string `long:"google-cid" env:"REMARK_GOOGLE_CID" description:"Google OAuth client ID"` - GoogleCSEC string `long:"google-csec" env:"REMARK_GOOGLE_CSEC" description:"Google OAuth client secret"` - GithubCID string `long:"github-cid" env:"REMARK_GITHUB_CID" description:"Github OAuth client ID"` - GithubCSEC string `long:"github-csec" env:"REMARK_GITHUB_CSEC" description:"Github OAuth client secret"` - + DBFile string `long:"db" env:"BOLTDB_FILE" default:"/tmp/remark.db" description:"bolt file name"` SiteURL string `long:"site-url" env:"REMARK_URL" default:"http://remark.umputun.com:8080" description:"url to remark site"` Admins []string `long:"admin" env:"ADMIN" default:"umputun@gmail.com" description:"admin(s) names" env-delim:","` DevMode bool `long:"dev" env:"DEV" description:"development mode, no auth enforced"` Dbg bool `long:"dbg" env:"DEBUG" description:"debug mode"` + ServerCommand struct { + SessionStore string `long:"session" env:"SESSION_STORE" default:"/tmp" description:"path to session store directory"` + StoreKey string `long:"store-key" env:"STORE_KEY" default:"secure-store-key" description:"store key"` + + GoogleCID string `long:"google-cid" env:"REMARK_GOOGLE_CID" description:"Google OAuth client ID"` + GoogleCSEC string `long:"google-csec" env:"REMARK_GOOGLE_CSEC" description:"Google OAuth client secret"` + GithubCID string `long:"github-cid" env:"REMARK_GITHUB_CID" description:"Github OAuth client ID"` + GithubCSEC string `long:"github-csec" env:"REMARK_GITHUB_CSEC" description:"Github OAuth client secret"` + } `command:"server" description:"run server"` + ImportCommand struct { Provider string `long:"provider" default:"disqus" description:"provider type"` SiteID string `long:"site" default:"site" description:"site ID"` @@ -63,7 +64,7 @@ func main() { return } - sessionStore := sessions.NewFilesystemStore(opts.SessionStore, []byte(opts.StoreKey)) + sessionStore := sessions.NewFilesystemStore(opts.ServerCommand.SessionStore, []byte(opts.ServerCommand.StoreKey)) srv := rest.Server{ Version: revision, @@ -72,14 +73,14 @@ func main() { Admins: opts.Admins, DevMode: opts.DevMode, AuthGoogle: auth.NewGoogle(auth.Params{ - Cid: opts.GoogleCID, - Csecret: opts.GoogleCSEC, + Cid: opts.ServerCommand.GoogleCID, + Csecret: opts.ServerCommand.GoogleCSEC, SessionStore: sessionStore, SiteURL: opts.SiteURL, }), AuthGithub: auth.NewGithub(auth.Params{ - Cid: opts.GithubCID, - Csecret: opts.GithubCSEC, + Cid: opts.ServerCommand.GithubCID, + Csecret: opts.ServerCommand.GithubCSEC, SessionStore: sessionStore, SiteURL: opts.SiteURL, }), diff --git a/app/migrator/disqus.go b/app/migrator/disqus.go index 4225a639..ce068d9f 100644 --- a/app/migrator/disqus.go +++ b/app/migrator/disqus.go @@ -103,13 +103,19 @@ func (d *Disqus) convert(r io.Reader, siteID string) (ch chan store.Comment) { continue } c := store.Comment{ - ID: comment.ID, + ID: comment.UID, Locator: store.Locator{URL: postsMap[comment.Tid.Val], SiteID: siteID}, User: store.User{ID: comment.AuthorUserName, Name: comment.AuthorName, IP: comment.IP}, Text: d.cleanText(comment.Message), Timestamp: comment.CreatedAt, ParentID: comment.Pid.Val, } + if c.User.ID == "" { + c.User.ID = "import_" + c.User.Name + } + if c.ID == "" { + c.ID = comment.ID + } commentsCh <- c commentsCount++ if commentsCount%1000 == 0 {