mirror of https://github.com/writeas/writefreely
commit
e1afb69a6a
@ -0,0 +1,49 @@ |
|||||||
|
/* |
||||||
|
* Copyright © 2024 Musing Studio LLC. |
||||||
|
* |
||||||
|
* This file is part of WriteFreely. |
||||||
|
* |
||||||
|
* WriteFreely is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU Affero General Public License, included |
||||||
|
* in the LICENSE file in this source code package. |
||||||
|
*/ |
||||||
|
|
||||||
|
package writefreely |
||||||
|
|
||||||
|
import ( |
||||||
|
"database/sql" |
||||||
|
"fmt" |
||||||
|
"github.com/writeas/web-core/activitystreams" |
||||||
|
"github.com/writeas/web-core/log" |
||||||
|
) |
||||||
|
|
||||||
|
func apAddRemoteUser(app *App, t *sql.Tx, fullActor *activitystreams.Person) (int64, error) { |
||||||
|
// Add remote user locally, since it wasn't found before
|
||||||
|
res, err := t.Exec("INSERT INTO remoteusers (actor_id, inbox, shared_inbox, url) VALUES (?, ?, ?, ?)", fullActor.ID, fullActor.Inbox, fullActor.Endpoints.SharedInbox, fullActor.URL) |
||||||
|
if err != nil { |
||||||
|
t.Rollback() |
||||||
|
return -1, fmt.Errorf("couldn't add new remoteuser in DB: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
remoteUserID, err := res.LastInsertId() |
||||||
|
if err != nil { |
||||||
|
t.Rollback() |
||||||
|
return -1, fmt.Errorf("no lastinsertid for followers, rolling back: %v", err) |
||||||
|
} |
||||||
|
|
||||||
|
// Add in key
|
||||||
|
_, err = t.Exec("INSERT INTO remoteuserkeys (id, remote_user_id, public_key) VALUES (?, ?, ?)", fullActor.PublicKey.ID, remoteUserID, fullActor.PublicKey.PublicKeyPEM) |
||||||
|
if err != nil { |
||||||
|
if !app.db.isDuplicateKeyErr(err) { |
||||||
|
t.Rollback() |
||||||
|
log.Error("Couldn't add follower keys in DB: %v\n", err) |
||||||
|
return -1, fmt.Errorf("couldn't add follower keys in DB: %v", err) |
||||||
|
} else { |
||||||
|
t.Rollback() |
||||||
|
log.Error("Couldn't add follower keys in DB: %v\n", err) |
||||||
|
return -1, fmt.Errorf("couldn't add follower keys in DB: %v", err) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return remoteUserID, nil |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* Copyright © 2024 Musing Studio LLC. |
||||||
|
* |
||||||
|
* This file is part of WriteFreely. |
||||||
|
* |
||||||
|
* WriteFreely is free software: you can redistribute it and/or modify |
||||||
|
* it under the terms of the GNU Affero General Public License, included |
||||||
|
* in the LICENSE file in this source code package. |
||||||
|
*/ |
||||||
|
|
||||||
|
package migrations |
||||||
|
|
||||||
|
func supportRemoteLikes(db *datastore) error { |
||||||
|
t, err := db.Begin() |
||||||
|
if err != nil { |
||||||
|
t.Rollback() |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
_, err = t.Exec(`CREATE TABLE remote_likes ( |
||||||
|
post_id ` + db.typeChar(16) + ` NOT NULL, |
||||||
|
remote_user_id ` + db.typeInt() + ` NOT NULL, |
||||||
|
created ` + db.typeDateTime() + ` NOT NULL, |
||||||
|
PRIMARY KEY (post_id,remote_user_id) |
||||||
|
)`) |
||||||
|
if err != nil { |
||||||
|
t.Rollback() |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
err = t.Commit() |
||||||
|
if err != nil { |
||||||
|
t.Rollback() |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
return nil |
||||||
|
} |
@ -0,0 +1,118 @@ |
|||||||
|
{{define "collection"}}<!DOCTYPE HTML> |
||||||
|
<html> |
||||||
|
<head prefix="og: http://ogp.me/ns# article: http://ogp.me/ns/article#"> |
||||||
|
<meta charset="utf-8"> |
||||||
|
|
||||||
|
<title>Archive — {{.Collection.DisplayTitle}}</title> |
||||||
|
|
||||||
|
<link rel="stylesheet" type="text/css" href="/css/write.css" /> |
||||||
|
{{if .CustomCSS}}<link rel="stylesheet" type="text/css" href="/local/custom.css" />{{end}} |
||||||
|
<link rel="shortcut icon" href="/favicon.ico" /> |
||||||
|
<link rel="canonical" href="{{.CanonicalURL}}"> |
||||||
|
{{if gt .CurrentPage 1}}<link rel="prev" href="{{.PrevPageURL .Prefix .NavSuffix .CurrentPage .IsTopLevel}}">{{end}} |
||||||
|
{{if lt .CurrentPage .TotalPages}}<link rel="next" href="{{.NextPageURL .Prefix .NavSuffix .CurrentPage .IsTopLevel}}">{{end}} |
||||||
|
{{if not .IsPrivate}}<link rel="alternate" type="application/rss+xml" title="{{.DisplayTitle}} » Feed" href="{{.CanonicalURL}}feed/" />{{end}} |
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
||||||
|
|
||||||
|
<meta name="generator" content="WriteFreely"> |
||||||
|
<meta name="description" content="{{.PlainDescription}}"> |
||||||
|
<meta itemprop="name" content="{{.DisplayTitle}}"> |
||||||
|
<meta itemprop="description" content="{{.PlainDescription}}"> |
||||||
|
<meta name="twitter:card" content="summary"> |
||||||
|
<meta name="twitter:title" content="{{.DisplayTitle}}"> |
||||||
|
<meta name="twitter:image" content="{{.AvatarURL}}"> |
||||||
|
<meta name="twitter:description" content="{{.PlainDescription}}"> |
||||||
|
<meta property="og:title" content="{{.DisplayTitle}}" /> |
||||||
|
<meta property="og:site_name" content="{{.DisplayTitle}}" /> |
||||||
|
<meta property="og:type" content="article" /> |
||||||
|
<meta property="og:url" content="{{.CanonicalURL}}" /> |
||||||
|
<meta property="og:description" content="{{.PlainDescription}}" /> |
||||||
|
<meta property="og:image" content="{{.AvatarURL}}"> |
||||||
|
{{template "collection-meta" .}} |
||||||
|
{{if .StyleSheet}}<style type="text/css">{{.StyleSheetDisplay}}</style>{{end}} |
||||||
|
|
||||||
|
</head> |
||||||
|
<body id="subpage"> |
||||||
|
|
||||||
|
<div id="overlay"></div> |
||||||
|
|
||||||
|
<header> |
||||||
|
<h1 dir="{{.Direction}}" id="blog-title"><a href="{{if .IsTopLevel}}/{{else}}/{{.Collection.Alias}}/{{end}}" class="h-card p-author">{{.Collection.DisplayTitle}}</a></h1> |
||||||
|
<nav> |
||||||
|
{{if .PinnedPosts}} |
||||||
|
{{range .PinnedPosts}}<a class="pinned" href="{{if $.IsOwner}}/{{$.Collection.Alias}}/{{.Slug.String}}{{else}}{{.CanonicalURL}}{{end}}">{{.DisplayTitle}}</a>{{end}} |
||||||
|
{{end}} |
||||||
|
</nav> |
||||||
|
</header> |
||||||
|
|
||||||
|
{{if .Posts -}} |
||||||
|
<section id="wrapper" class="archive" itemscope itemtype="http://schema.org/Blog"> |
||||||
|
{{- else -}} |
||||||
|
<div id="wrapper" class="archive"> |
||||||
|
{{- end}} |
||||||
|
|
||||||
|
<h1>Archive</h1> |
||||||
|
|
||||||
|
{{if .Flash}} |
||||||
|
<div class="alert success flash"> |
||||||
|
<p>{{.Flash}}</p> |
||||||
|
</div> |
||||||
|
{{end}} |
||||||
|
|
||||||
|
<ul> |
||||||
|
{{ $curYear := 0 }} |
||||||
|
{{ range $el := .Posts }} |
||||||
|
{{if ne $curYear .Created.Year}}<li class="year">{{.Created.Year}}</li>{{ $curYear = .Created.Year }}{{end}} |
||||||
|
<li> |
||||||
|
{{if .HasTitleLink -}} |
||||||
|
{{.HTMLTitleArrow}} |
||||||
|
{{- else -}} |
||||||
|
<a href="{{if $.SingleUser}}/{{else}}/{{$.Alias}}/{{end}}{{.Slug.String}}" itemprop="url" class="u-url"> |
||||||
|
{{- if .DisplayTitle -}} |
||||||
|
{{- .DisplayTitle -}} |
||||||
|
{{- else -}} |
||||||
|
(Untitled) |
||||||
|
{{end}} |
||||||
|
</a> |
||||||
|
{{- end}} |
||||||
|
{{if .IsScheduled}}[Scheduled]{{end}} |
||||||
|
{{if $.Format.ShowDates -}} |
||||||
|
<time class="dt-published" datetime="{{.Created8601}}" pubdate itemprop="datePublished" content="{{.Created}}"> |
||||||
|
{{- if .HasTitleLink -}} |
||||||
|
<a href="{{if $.SingleUser}}/{{else}}/{{$.Alias}}/{{end}}{{.Slug.String}}" itemprop="url"> |
||||||
|
{{- end -}} |
||||||
|
{{.DisplayDate}} |
||||||
|
{{- if .HasTitleLink -}} |
||||||
|
{{- if .IsPaid}}{{template "paid-badge" (dict "CDNHost" $.CDNHost)}}{{end -}}</a> |
||||||
|
{{- end -}} |
||||||
|
</time> |
||||||
|
{{- else -}} |
||||||
|
{{- if .HasTitleLink -}} |
||||||
|
<a href="{{if $.SingleUser}}/{{else}}/{{$.Alias}}/{{end}}{{.Slug.String}}" itemprop="url">view</a> |
||||||
|
{{- end -}} |
||||||
|
{{- end}} |
||||||
|
</li> |
||||||
|
{{end}} |
||||||
|
</ul> |
||||||
|
|
||||||
|
{{template "paging" .}} |
||||||
|
|
||||||
|
{{if .Posts}}</section>{{else}}</div>{{end}} |
||||||
|
|
||||||
|
{{if .ShowFooterBranding }} |
||||||
|
<footer> |
||||||
|
<hr /> |
||||||
|
<nav dir="ltr"> |
||||||
|
{{if not .SingleUser}}<a class="home pubd" href="/">{{.SiteName}}</a> · {{end}}powered by <a style="margin-left:0" href="https://writefreely.org">writefreely</a> |
||||||
|
</nav> |
||||||
|
</footer> |
||||||
|
{{ end }} |
||||||
|
|
||||||
|
</body> |
||||||
|
|
||||||
|
{{if .CanShowScript}} |
||||||
|
{{range .ExternalScripts}}<script type="text/javascript" src="{{.}}" async></script>{{end}} |
||||||
|
{{if .Collection.Script}}<script type="text/javascript">{{.ScriptDisplay}}</script>{{end}} |
||||||
|
{{end}} |
||||||
|
<script src="/js/localdate.js"></script> |
||||||
|
</html>{{end}} |
Loading…
Reference in new issue