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:
parent
6c5d89ac86
commit
92f75a8871
|
@ -108,33 +108,34 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err
|
||||||
ID: 0,
|
ID: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
coll.hostName = app.cfg.App.Host
|
||||||
|
|
||||||
submittedPost := SubmittedPost{
|
submittedPost := SubmittedPost{
|
||||||
Title: &post.Title,
|
Title: &post.Title,
|
||||||
Content: &post.Content,
|
Content: &post.Content,
|
||||||
Font: "norm",
|
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 {
|
if coll.ID != 0 && app.cfg.App.Federation {
|
||||||
token, err := app.db.GetAccessToken(u.ID)
|
go federatePost(
|
||||||
if err != nil {
|
app,
|
||||||
fileErrs = append(fileErrs, fmt.Errorf("failed to authenticate uploading: %s", formFile.Filename))
|
&PublicPost{
|
||||||
log.Error("import textfile: get accesstoken: %+v", err)
|
Post: rp,
|
||||||
continue
|
Collection: &CollectionObj{
|
||||||
}
|
Collection: *coll,
|
||||||
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))
|
coll.ID,
|
||||||
log.Error("import textfile: create owned post: %v", err)
|
false,
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
filesImported++
|
filesImported++
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue