From 92f75a887187fc26c2d4a7544c3d74a4e3e71646 Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Mon, 19 Aug 2019 09:06:56 -0700 Subject: [PATCH] avoid generating excess access tokens this changes the import handler to use CreatePost instead of CreateOwnedPost which required generation of non expiring access tokens --- account_import.go | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/account_import.go b/account_import.go index 3fd434e..c9868ba 100644 --- a/account_import.go +++ b/account_import.go @@ -108,33 +108,34 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err ID: 0, } } + coll.hostName = app.cfg.App.Host submittedPost := SubmittedPost{ Title: &post.Title, Content: &post.Content, Font: "norm", } + rp, err := app.db.CreatePost(u.ID, coll.ID, &submittedPost) + if err != nil { + fileErrs = append(fileErrs, fmt.Errorf("failed to create post from %s", formFile.Filename)) + log.Error("import textfile: create db post: %v", err) + continue + } + + // create public post + if coll.ID != 0 && app.cfg.App.Federation { - token, err := app.db.GetAccessToken(u.ID) - if err != nil { - fileErrs = append(fileErrs, fmt.Errorf("failed to authenticate uploading: %s", formFile.Filename)) - log.Error("import textfile: get accesstoken: %+v", err) - continue - } - ownedPost, err := app.db.CreateOwnedPost(&submittedPost, token, coll.Alias, app.cfg.App.Host) - if err != nil { - fileErrs = append(fileErrs, fmt.Errorf("failed to create owned post for %s", formFile.Filename)) - log.Error("import textfile: create owned post: %v", err) - continue - } - go federatePost(app, ownedPost, coll.ID, false) - } else { - _, err = app.db.CreatePost(u.ID, coll.ID, &submittedPost) - if err != nil { - fileErrs = append(fileErrs, fmt.Errorf("failed to create post from %s", formFile.Filename)) - log.Error("import textfile: create db post: %v", err) - continue - } + go federatePost( + app, + &PublicPost{ + Post: rp, + Collection: &CollectionObj{ + Collection: *coll, + }, + }, + coll.ID, + false, + ) } filesImported++ }