avoid generating excess access tokens

this changes the import handler to use CreatePost instead of
CreateOwnedPost which required generation of non expiring access tokens
This commit is contained in:
Rob Loranger 2019-08-19 09:06:56 -07:00
parent 6c5d89ac86
commit 92f75a8871
No known key found for this signature in database
GPG Key ID: D6F1633A4F0903B8
1 changed files with 21 additions and 20 deletions

View File

@ -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++
}