mirror of https://github.com/perkeep/perkeep.git
importer/feed: Add date fields to imported items
This also changed a few of the magic strings in the SetAttrs call to use the nodeattr constants. One thing I'm unsure about is if "link" should be changed to nodeattr.URL, but that's left out of this initial revision. This also sneaks in a change to devimport that was blocking the testing of the feed service, as it doesn't use authentication. Fixes #1148 Change-Id: Ic3cf85dc30c446954f3780683cba99f118b46fb6
This commit is contained in:
parent
a9db75c56d
commit
276137d656
|
@ -80,9 +80,13 @@ func newImporterHost(server string, importerType string) (*importer.Host, error)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
clientID, clientSecret, err := getCredentials(cl, importerType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
var clientID, clientSecret string
|
||||
|
||||
if importer.All()[importerType].Properties().NeedsAPIKey {
|
||||
clientID, clientSecret, err = getCredentials(cl, importerType)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
hc := importer.HostConfig{
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"perkeep.org/pkg/blob"
|
||||
"perkeep.org/pkg/importer"
|
||||
"perkeep.org/pkg/schema"
|
||||
"perkeep.org/pkg/schema/nodeattr"
|
||||
|
||||
"go4.org/ctxutil"
|
||||
"golang.org/x/net/html"
|
||||
|
@ -154,16 +155,34 @@ func (r *run) importItem(parent *importer.Object, item *item) error {
|
|||
return err
|
||||
}
|
||||
if err := itemNode.SetAttrs(
|
||||
"feedItemId", item.ID,
|
||||
"camliNodeType", "feed:item",
|
||||
"title", item.Title,
|
||||
nodeattr.Type, "feed:item",
|
||||
nodeattr.Title, item.Title,
|
||||
nodeattr.CamliContent, fileRef.String(),
|
||||
"link", item.Link,
|
||||
"feedItemId", item.ID,
|
||||
"author", item.Author,
|
||||
"camliContent", fileRef.String(),
|
||||
"feedMediaContentURL", item.MediaContent,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !item.Updated.IsZero() {
|
||||
if err := itemNode.SetAttr(nodeattr.DateModified, schema.RFC3339FromTime(item.Updated)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !item.Published.IsZero() {
|
||||
if err := itemNode.SetAttr(nodeattr.DatePublished, schema.RFC3339FromTime(item.Published)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !item.Created.IsZero() {
|
||||
if err := itemNode.SetAttr(nodeattr.DateCreated, schema.RFC3339FromTime(item.Created)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue