first retrieved webmention
This commit is contained in:
parent
df5215d943
commit
723a6000bf
|
@ -109,7 +109,7 @@ func (s *WebmentionService) GetExistingWebmention(entryId string, source string,
|
||||||
}
|
}
|
||||||
for _, interaction := range inters {
|
for _, interaction := range inters {
|
||||||
if webm, ok := interaction.(*interactions.Webmention); ok {
|
if webm, ok := interaction.(*interactions.Webmention); ok {
|
||||||
m := webm.MetaData().(interactions.WebmentionMetaData)
|
m := webm.MetaData().(*interactions.WebmentionMetaData)
|
||||||
if m.Source == source && m.Target == target {
|
if m.Source == source && m.Target == target {
|
||||||
return webm, nil
|
return webm, nil
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ func (s *WebmentionService) ProcessWebmention(source string, target string) erro
|
||||||
Target: target,
|
Target: target,
|
||||||
Title: hEntry.Title,
|
Title: hEntry.Title,
|
||||||
}
|
}
|
||||||
webmention.SetMetaData(data)
|
webmention.SetMetaData(&data)
|
||||||
webmention.SetEntryID(entryId)
|
webmention.SetEntryID(entryId)
|
||||||
webmention.SetCreatedAt(time.Now())
|
webmention.SetCreatedAt(time.Now())
|
||||||
err = s.InteractionRepository.Update(webmention)
|
err = s.InteractionRepository.Update(webmention)
|
||||||
|
|
|
@ -64,7 +64,7 @@ func App(db infra.Database) *web.WebApp {
|
||||||
return web.NewWebApp(
|
return web.NewWebApp(
|
||||||
entryService, entryRegister, binaryService,
|
entryService, entryRegister, binaryService,
|
||||||
authorService, siteConfigRepo, configRegister,
|
authorService, siteConfigRepo, configRegister,
|
||||||
webmentionService,
|
webmentionService, interactionRepo,
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -103,13 +103,38 @@ func (repo *DefaultInteractionRepo) FindAll(entryId string) ([]model.Interaction
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindById implements repository.InteractionRepository.
|
// FindById implements repository.InteractionRepository.
|
||||||
func (*DefaultInteractionRepo) FindById(id string) (model.Interaction, error) {
|
func (repo *DefaultInteractionRepo) FindById(id string) (model.Interaction, error) {
|
||||||
panic("unimplemented")
|
data := sqlInteraction{}
|
||||||
|
err := repo.db.Get(&data, "SELECT * FROM interactions WHERE id = ?", id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if data.Id == "" {
|
||||||
|
return nil, errors.New("interaction not found")
|
||||||
|
}
|
||||||
|
return repo.sqlInteractionToInteraction(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update implements repository.InteractionRepository.
|
// Update implements repository.InteractionRepository.
|
||||||
func (*DefaultInteractionRepo) Update(interaction model.Interaction) error {
|
func (repo *DefaultInteractionRepo) Update(interaction model.Interaction) error {
|
||||||
panic("unimplemented")
|
exInter, _ := repo.FindById(interaction.ID())
|
||||||
|
if exInter == nil {
|
||||||
|
return errors.New("interaction not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := repo.typeRegistry.TypeName(interaction)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("interaction type not registered")
|
||||||
|
}
|
||||||
|
|
||||||
|
var metaDataJson []byte
|
||||||
|
if interaction.MetaData() != nil {
|
||||||
|
metaDataJson, _ = json.Marshal(interaction.MetaData())
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = repo.db.Exec("UPDATE interactions SET entry_id = ?, meta_data = ? WHERE id = ?", interaction.EntryID(), metaDataJson, interaction.ID())
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *DefaultInteractionRepo) sqlInteractionToInteraction(interaction sqlInteraction) (model.Interaction, error) {
|
func (repo *DefaultInteractionRepo) sqlInteractionToInteraction(interaction sqlInteraction) (model.Interaction, error) {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package interactions
|
package interactions
|
||||||
|
|
||||||
import "owl-blogs/domain/model"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"owl-blogs/domain/model"
|
||||||
|
"owl-blogs/render"
|
||||||
|
)
|
||||||
|
|
||||||
type Webmention struct {
|
type Webmention struct {
|
||||||
model.InteractionBase
|
model.InteractionBase
|
||||||
|
@ -14,7 +18,11 @@ type WebmentionMetaData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Webmention) Content() model.InteractionContent {
|
func (i *Webmention) Content() model.InteractionContent {
|
||||||
return model.InteractionContent(i.meta.Source)
|
str, err := render.RenderTemplateToString("interaction/Webmention", i)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
return model.InteractionContent(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Webmention) MetaData() interface{} {
|
func (i *Webmention) MetaData() interface{} {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<title>{{template "title" .Data}} - {{ .SiteConfig.Title }}</title>
|
<title>{{template "title" .Data}} - {{ .SiteConfig.Title }}</title>
|
||||||
<meta property="og:title" content="{{template "title" .Data}}" />
|
<meta property="og:title" content="{{template "title" .Data}}" />
|
||||||
|
<link rel="webmention" href="/webmention/" />
|
||||||
|
|
||||||
<link rel='stylesheet' href='/static/pico.min.css'>
|
<link rel='stylesheet' href='/static/pico.min.css'>
|
||||||
<style>
|
<style>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<a href="{{.MetaData.Source}}">
|
||||||
|
{{if .MetaData.Title}}
|
||||||
|
{{.MetaData.Title}}
|
||||||
|
{{else}}
|
||||||
|
{{.MetaData.Source}}
|
||||||
|
{{end}}
|
||||||
|
</a>
|
|
@ -39,6 +39,25 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{if .Interactions}}
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<hr>
|
||||||
|
<h4>
|
||||||
|
Interactions
|
||||||
|
</h4>
|
||||||
|
<ul>
|
||||||
|
{{range .Interactions}}
|
||||||
|
<li>
|
||||||
|
{{ .Content }}
|
||||||
|
</li>
|
||||||
|
{{end}}
|
||||||
|
</ul>
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{{ if .LoggedIn }}
|
{{ if .LoggedIn }}
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -35,13 +35,14 @@ func NewWebApp(
|
||||||
configRepo repository.ConfigRepository,
|
configRepo repository.ConfigRepository,
|
||||||
configRegister *app.ConfigRegister,
|
configRegister *app.ConfigRegister,
|
||||||
webmentionService *app.WebmentionService,
|
webmentionService *app.WebmentionService,
|
||||||
|
interactionRepo repository.InteractionRepository,
|
||||||
) *WebApp {
|
) *WebApp {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
app.Use(middleware.NewUserMiddleware(authorService).Handle)
|
app.Use(middleware.NewUserMiddleware(authorService).Handle)
|
||||||
|
|
||||||
indexHandler := NewIndexHandler(entryService, configRepo)
|
indexHandler := NewIndexHandler(entryService, configRepo)
|
||||||
listHandler := NewListHandler(entryService, configRepo)
|
listHandler := NewListHandler(entryService, configRepo)
|
||||||
entryHandler := NewEntryHandler(entryService, typeRegistry, authorService, configRepo)
|
entryHandler := NewEntryHandler(entryService, typeRegistry, authorService, configRepo, interactionRepo)
|
||||||
mediaHandler := NewMediaHandler(binService)
|
mediaHandler := NewMediaHandler(binService)
|
||||||
rssHandler := NewRSSHandler(entryService, configRepo)
|
rssHandler := NewRSSHandler(entryService, configRepo)
|
||||||
loginHandler := NewLoginHandler(authorService, configRepo)
|
loginHandler := NewLoginHandler(authorService, configRepo)
|
||||||
|
|
|
@ -10,16 +10,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type EntryHandler struct {
|
type EntryHandler struct {
|
||||||
configRepo repository.ConfigRepository
|
configRepo repository.ConfigRepository
|
||||||
entrySvc *app.EntryService
|
entrySvc *app.EntryService
|
||||||
authorSvc *app.AuthorService
|
authorSvc *app.AuthorService
|
||||||
registry *app.EntryTypeRegistry
|
registry *app.EntryTypeRegistry
|
||||||
|
interactionRepo repository.InteractionRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
type entryData struct {
|
type entryData struct {
|
||||||
Entry model.Entry
|
Entry model.Entry
|
||||||
Author *model.Author
|
Author *model.Author
|
||||||
LoggedIn bool
|
LoggedIn bool
|
||||||
|
Interactions []model.Interaction
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewEntryHandler(
|
func NewEntryHandler(
|
||||||
|
@ -27,12 +29,14 @@ func NewEntryHandler(
|
||||||
registry *app.EntryTypeRegistry,
|
registry *app.EntryTypeRegistry,
|
||||||
authorService *app.AuthorService,
|
authorService *app.AuthorService,
|
||||||
configRepo repository.ConfigRepository,
|
configRepo repository.ConfigRepository,
|
||||||
|
interactionRepo repository.InteractionRepository,
|
||||||
) *EntryHandler {
|
) *EntryHandler {
|
||||||
return &EntryHandler{
|
return &EntryHandler{
|
||||||
entrySvc: entryService,
|
entrySvc: entryService,
|
||||||
authorSvc: authorService,
|
authorSvc: authorService,
|
||||||
registry: registry,
|
registry: registry,
|
||||||
configRepo: configRepo,
|
configRepo: configRepo,
|
||||||
|
interactionRepo: interactionRepo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,14 +62,17 @@ func (h *EntryHandler) Handle(c *fiber.Ctx) error {
|
||||||
author = &model.Author{}
|
author = &model.Author{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inters, _ := h.interactionRepo.FindAll(entry.ID())
|
||||||
|
|
||||||
return render.RenderTemplateWithBase(
|
return render.RenderTemplateWithBase(
|
||||||
c,
|
c,
|
||||||
getSiteConfig(h.configRepo),
|
getSiteConfig(h.configRepo),
|
||||||
"views/entry",
|
"views/entry",
|
||||||
entryData{
|
entryData{
|
||||||
Entry: entry,
|
Entry: entry,
|
||||||
Author: author,
|
Author: author,
|
||||||
LoggedIn: loggedIn,
|
LoggedIn: loggedIn,
|
||||||
|
Interactions: inters,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ func (h *WebmentionHandler) Handle(c *fiber.Ctx) error {
|
||||||
target := c.FormValue("target")
|
target := c.FormValue("target")
|
||||||
source := c.FormValue("source")
|
source := c.FormValue("source")
|
||||||
|
|
||||||
|
println("target", target)
|
||||||
|
println("source", source)
|
||||||
|
|
||||||
if target == "" {
|
if target == "" {
|
||||||
return c.Status(400).SendString("target is required")
|
return c.Status(400).SendString("target is required")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue