Compare commits

...

9 Commits

Author SHA1 Message Date
Ted Unangst fd0aff3099 revert previous, doesn't seem to help 2023-05-01 17:40:06 -04:00
Ted Unangst af4c98c07d provide json directly at alt link 2023-05-01 17:32:12 -04:00
Ted Unangst 20f2cb81f1 add alternate rel link for activity to header 2023-05-01 17:06:04 -04:00
Ted Unangst 4e3e07d670 svg image support 2023-05-01 15:32:36 -04:00
Ted Unangst 65c29304f2 up webs 2023-05-01 14:48:10 -04:00
Ted Unangst 0a3515268c be a bit more permissive with the quick mentions 2023-05-01 14:27:39 -04:00
Ted Unangst e212f4eb1e we need to go deeper 2023-04-28 11:09:46 -04:00
Ted Unangst 372a274aa6 pong should quote ping id. from curt 2023-03-30 19:17:48 -04:00
Ted Unangst 664f319b28 search can now load posts 2023-03-27 12:47:48 -04:00
10 changed files with 53 additions and 8 deletions

View File

@ -17,10 +17,13 @@ package main
import (
"bytes"
"errors"
"net"
"net/http"
"net/rpc"
"os"
"os/exec"
"strings"
"humungus.tedunangst.com/r/webs/gate"
"humungus.tedunangst.com/r/webs/image"
@ -55,7 +58,32 @@ func backendSockname() string {
return dataDir + "/backend.sock"
}
func isSVG(data []byte) bool {
ct := http.DetectContentType(data)
if strings.HasPrefix(ct, "text/xml") {
return strings.Index(string(data), "<!DOCTYPE svg PUBLIC") != -1
}
if strings.HasPrefix(ct, "text/plain") {
return bytes.HasPrefix(data, []byte("<svg "))
}
return ct == "image/svg+xml"
}
func imageFromSVG(data []byte) (*image.Image, error) {
if len(data) > 100000 {
return nil, errors.New("my svg is too big")
}
svg := &image.Image{
Data: data,
Format: "svg+xml",
}
return svg, nil
}
func shrinkit(data []byte) (*image.Image, error) {
if isSVG(data) {
return imageFromSVG(data)
}
cl, err := rpc.Dial("unix", backendSockname())
if err != nil {
return nil, err

View File

@ -250,7 +250,7 @@ func gethonksforme(userid int64, wanted int64) []*Honk {
func gethonksfromlongago(userid int64, wanted int64) []*Honk {
now := time.Now()
var honks []*Honk
for i := 1; i <= 3; i++ {
for i := 1; i <= 4; i++ {
dt := time.Date(now.Year()-i, now.Month(), now.Day(), now.Hour(), now.Minute(),
now.Second(), 0, now.Location())
dt1 := dt.Add(-36 * time.Hour).UTC().Format(dbtimeformat)
@ -548,6 +548,8 @@ func savefileandxid(name string, desc string, url string, media string, local bo
xid += ".png"
case "image/jpeg":
xid += ".jpg"
case "image/svg+xml":
xid += ".svg"
case "application/pdf":
xid += ".pdf"
case "text/plain":

View File

@ -1,5 +1,9 @@
changelog
=== next
+ search can now load external posts
=== 0.9.91 One More Time
+ Swallow a follow bug.

View File

@ -170,6 +170,7 @@ The
page lists recently seen honkers that are not otherwise tracked.
It also allows the import of external objects via URL, either individual
posts or actor URLs, in which case their recent outbox is imported.
Probably easier to use the search box for this.
.Ss Account
It's all about you.
An avatar may be selected from the

3
fun.go
View File

@ -463,7 +463,7 @@ func memetize(honk *Honk) {
honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl)
}
var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]]+([ \n.,']|$)")
var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]_]+([ \n:;.,']|$)")
func quickrename(s string, userid int64) string {
nonstop := true
@ -479,6 +479,7 @@ func quickrename(s string, userid int64) string {
m = m[1:]
tail := ""
if last := m[len(m)-1]; last == ' ' || last == '\n' ||
last == ':' || last == ';' ||
last == '.' || last == ',' || last == '\'' {
tail = m[len(m)-1:]
m = m[:len(m)-1]

2
go.mod
View File

@ -9,5 +9,5 @@ require (
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
humungus.tedunangst.com/r/go-sqlite3 v1.1.3
humungus.tedunangst.com/r/webs v0.6.60
humungus.tedunangst.com/r/webs v0.6.61
)

4
go.sum
View File

@ -25,5 +25,5 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI=
humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M=
humungus.tedunangst.com/r/webs v0.6.60 h1:2PjVTVH3js4PXv8lrEw7nxtRmwwt1COl7t7tZMPxBPs=
humungus.tedunangst.com/r/webs v0.6.60/go.mod h1:03R0N9BcT49HB4TDd1YmarpbiPvPzVDm74Mk4h1hYPc=
humungus.tedunangst.com/r/webs v0.6.61 h1:Sgy0Htb8Y0jmmLPp73nYDuD4NebeUsgXftP+wB86wSg=
humungus.tedunangst.com/r/webs v0.6.61/go.mod h1:03R0N9BcT49HB4TDd1YmarpbiPvPzVDm74Mk4h1hYPc=

View File

@ -6,6 +6,7 @@
{{ if .LocalStyleParam }}
<link href="/local.css{{ .LocalStyleParam }}" rel="stylesheet">
{{ end }}
{{ .APAltLink }}
<link href="/icon.png" rel="icon">
<meta name="theme-color" content="#305">
<meta name="viewport" content="width=device-width">

View File

@ -4,7 +4,7 @@
<form action="/ximport" method="POST">
<input type="hidden" name="CSRF" value="{{ .XCSRF }}">
<p><span class="title">import</span>
<p><input tabindex=1 type="text" name="xid" autocomplete=off> - xid
<p><input tabindex=1 type="text" name="q" autocomplete=off> - xid
<p><button tabindex=1 name="fetch" value="fetch">fetch</button>
</form>
</div>

12
web.go
View File

@ -395,7 +395,7 @@ func inbox(w http.ResponseWriter, r *http.Request) {
case "Ping":
id, _ := j.GetString("id")
ilog.Printf("ping from %s: %s", who, id)
pong(user, who, obj)
pong(user, who, id)
case "Pong":
ilog.Printf("pong from %s: %s", who, obj)
case "Follow":
@ -549,7 +549,7 @@ func serveractor(w http.ResponseWriter, r *http.Request) {
func ximport(w http.ResponseWriter, r *http.Request) {
u := login.GetUserInfo(r)
xid := strings.TrimSpace(r.FormValue("xid"))
xid := strings.TrimSpace(r.FormValue("q"))
xonk := getxonk(u.UserID, xid)
if xonk == nil {
p, _ := investigate(xid)
@ -788,6 +788,10 @@ func showconvoy(w http.ResponseWriter, r *http.Request) {
}
func showsearch(w http.ResponseWriter, r *http.Request) {
q := r.FormValue("q")
if strings.HasPrefix(q, "https://") {
ximport(w, r)
return
}
u := login.GetUserInfo(r)
honks := gethonksbysearch(u.UserID, q, 0)
templinfo := getInfo(r)
@ -1075,6 +1079,7 @@ func showonehonk(w http.ResponseWriter, r *http.Request) {
templinfo := getInfo(r)
templinfo["ServerMessage"] = "one honk maybe more"
templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)
templinfo["APAltLink"] = templates.Sprintf("<link href='%s' rel='alternate' type='application/activity+json'>", xid)
honkpage(w, u, honks, templinfo)
}
@ -1499,6 +1504,9 @@ func submitdonk(w http.ResponseWriter, r *http.Request) (*Donk, error) {
if format == "jpeg" {
format = "jpg"
}
if format == "svg+xml" {
format = "svg"
}
name = xfiltrate() + "." + format
} else {
ct := http.DetectContentType(data)