Compare commits
9 Commits
10bca44dc5
...
fd0aff3099
Author | SHA1 | Date |
---|---|---|
Ted Unangst | fd0aff3099 | |
Ted Unangst | af4c98c07d | |
Ted Unangst | 20f2cb81f1 | |
Ted Unangst | 4e3e07d670 | |
Ted Unangst | 65c29304f2 | |
Ted Unangst | 0a3515268c | |
Ted Unangst | e212f4eb1e | |
Ted Unangst | 372a274aa6 | |
Ted Unangst | 664f319b28 |
28
backend.go
28
backend.go
|
@ -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
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
changelog
|
||||
|
||||
=== next
|
||||
|
||||
+ search can now load external posts
|
||||
|
||||
=== 0.9.91 One More Time
|
||||
|
||||
+ Swallow a follow bug.
|
||||
|
|
|
@ -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
3
fun.go
|
@ -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
2
go.mod
|
@ -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
4
go.sum
|
@ -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=
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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
12
web.go
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue