Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dbd86535d | ||
|
|
f534cc9f9b | ||
|
|
a77cafb3ae | ||
|
|
48cbbf652a | ||
|
|
e05f572eb2 | ||
|
|
7ddb288ae3 | ||
|
|
cee889bd58 | ||
|
|
aacd7d3d0c | ||
|
|
3134869cce | ||
|
|
083de67f45 | ||
|
|
339af195c2 | ||
|
|
83e2689111 | ||
|
|
68a680d1b0 | ||
|
|
35ecbe8f09 |
@@ -117,6 +117,7 @@ type Object struct {
|
|||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ContentMap map[string]string `json:"contentMap,omitempty"`
|
ContentMap map[string]string `json:"contentMap,omitempty"`
|
||||||
Tag []Tag `json:"tag"`
|
Tag []Tag `json:"tag"`
|
||||||
|
Attachment []Attachment `json:"attachment,omitempty"`
|
||||||
|
|
||||||
// Extensions
|
// Extensions
|
||||||
// NOTE: add extensions here
|
// NOTE: add extensions here
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package activitystreams
|
||||||
|
|
||||||
|
import (
|
||||||
|
"mime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Attachment struct {
|
||||||
|
Type AttachmentType `json:"type"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
MediaType string `json:"mediaType"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AttachmentType string
|
||||||
|
|
||||||
|
const AttachImage AttachmentType = "Image"
|
||||||
|
|
||||||
|
// NewImageAttachment creates a new Attachment from the given URL, setting the
|
||||||
|
// correct type and automatically detecting the MediaType based on the file
|
||||||
|
// extension.
|
||||||
|
func NewImageAttachment(url string) Attachment {
|
||||||
|
var imgType string
|
||||||
|
extIdx := strings.LastIndexByte(url, '.')
|
||||||
|
if extIdx > -1 {
|
||||||
|
imgType = mime.TypeByExtension(url[extIdx:])
|
||||||
|
}
|
||||||
|
return Attachment{
|
||||||
|
Type: AttachImage,
|
||||||
|
URL: url,
|
||||||
|
MediaType: imgType,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package activitystreams
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewImageAttachment(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
url string
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want *Attachment
|
||||||
|
}{
|
||||||
|
{name: "good svg", args: args{"https://writefreely.org/img/writefreely.svg"}, want: &Attachment{
|
||||||
|
Type: "Image",
|
||||||
|
URL: "https://writefreely.org/img/writefreely.svg",
|
||||||
|
MediaType: "image/svg+xml",
|
||||||
|
}},
|
||||||
|
{name: "good png", args: args{"https://i.snap.as/12345678.png"}, want: &Attachment{
|
||||||
|
Type: "Image",
|
||||||
|
URL: "https://i.snap.as/12345678.png",
|
||||||
|
MediaType: "image/png",
|
||||||
|
}},
|
||||||
|
{name: "no extension", args: args{"https://i.snap.as/12345678"}, want: &Attachment{
|
||||||
|
Type: "Image",
|
||||||
|
URL: "https://i.snap.as/12345678",
|
||||||
|
MediaType: "",
|
||||||
|
}},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := NewImageAttachment(tt.args.url); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("NewImageAttachment() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,5 +10,5 @@ type TagType string
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
TagHashtag TagType = "Hashtag"
|
TagHashtag TagType = "Hashtag"
|
||||||
TagMention = "Mention"
|
TagMention TagType = "Mention"
|
||||||
)
|
)
|
||||||
|
|||||||
+3
-3
@@ -1,7 +1,7 @@
|
|||||||
package auth
|
package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
uuid "github.com/nu7hatch/gouuid"
|
uuid "github.com/gofrs/uuid"
|
||||||
"github.com/writeas/web-core/log"
|
"github.com/writeas/web-core/log"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -16,7 +16,7 @@ func GetToken(header string) []byte {
|
|||||||
token = f[1]
|
token = f[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t, err := uuid.ParseHex(token)
|
t, err := uuid.FromString(token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
||||||
} else {
|
} else {
|
||||||
@@ -31,7 +31,7 @@ func GetHeaderToken(header string) []byte {
|
|||||||
if len(header) > 0 {
|
if len(header) > 0 {
|
||||||
f := strings.Fields(header)
|
f := strings.Fields(header)
|
||||||
if len(f) == 2 && f[0] == "Token" {
|
if len(f) == 2 && f[0] == "Token" {
|
||||||
t, err := uuid.ParseHex(f[1])
|
t, err := uuid.FromString(f[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -3,13 +3,12 @@ module github.com/writeas/web-core
|
|||||||
go 1.10
|
go 1.10
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/gofrs/uuid v3.3.0+incompatible
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec
|
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec
|
||||||
github.com/microcosm-cc/bluemonday v1.0.2
|
github.com/microcosm-cc/bluemonday v1.0.2
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||||
github.com/writeas/impart v1.1.0
|
github.com/writeas/impart v1.1.0
|
||||||
github.com/writeas/nerds v1.0.0
|
|
||||||
github.com/writeas/openssl-go v1.0.0
|
github.com/writeas/openssl-go v1.0.0
|
||||||
github.com/writeas/saturday v1.6.0
|
github.com/writeas/saturday v1.6.0
|
||||||
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613
|
golang.org/x/crypto v0.0.0-20190131182504-b8fe1690c613
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU=
|
||||||
|
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
|
||||||
|
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
@@ -7,14 +10,10 @@ github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec h1:ZXWuspq
|
|||||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g=
|
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
|
github.com/microcosm-cc/bluemonday v1.0.2 h1:5lPfLTTAvAbtS0VqT+94yOtFnGfUWYyx0+iToC3Os3s=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
|
|
||||||
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/writeas/impart v1.1.0 h1:nPnoO211VscNkp/gnzir5UwCDEvdHThL5uELU60NFSE=
|
github.com/writeas/impart v1.1.0 h1:nPnoO211VscNkp/gnzir5UwCDEvdHThL5uELU60NFSE=
|
||||||
github.com/writeas/impart v1.1.0/go.mod h1:g0MpxdnTOHHrl+Ca/2oMXUHJ0PcRAEWtkCzYCJUXC9Y=
|
github.com/writeas/impart v1.1.0/go.mod h1:g0MpxdnTOHHrl+Ca/2oMXUHJ0PcRAEWtkCzYCJUXC9Y=
|
||||||
github.com/writeas/nerds v1.0.0 h1:ZzRcCN+Sr3MWID7o/x1cr1ZbLvdpej9Y1/Ho+JKlqxo=
|
|
||||||
github.com/writeas/nerds v1.0.0/go.mod h1:Gn2bHy1EwRcpXeB7ZhVmuUwiweK0e+JllNf66gvNLdU=
|
|
||||||
github.com/writeas/openssl-go v1.0.0 h1:YXM1tDXeYOlTyJjoMlYLQH1xOloUimSR1WMF8kjFc5o=
|
github.com/writeas/openssl-go v1.0.0 h1:YXM1tDXeYOlTyJjoMlYLQH1xOloUimSR1WMF8kjFc5o=
|
||||||
github.com/writeas/openssl-go v1.0.0/go.mod h1:WsKeK5jYl0B5y8ggOmtVjbmb+3rEGqSD25TppjJnETA=
|
github.com/writeas/openssl-go v1.0.0/go.mod h1:WsKeK5jYl0B5y8ggOmtVjbmb+3rEGqSD25TppjJnETA=
|
||||||
github.com/writeas/saturday v1.6.0 h1:HNUtX8TVJJnSdxE8vaAgtHiAJVt+Of5AJYlm62pmVlI=
|
github.com/writeas/saturday v1.6.0 h1:HNUtX8TVJJnSdxE8vaAgtHiAJVt+Of5AJYlm62pmVlI=
|
||||||
|
|||||||
+16
-2
@@ -2,11 +2,25 @@ package id
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/writeas/nerds/store"
|
"crypto/rand"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GenerateRandomString creates a random string of characters of the given
|
||||||
|
// length from the given dictionary of possible characters.
|
||||||
|
//
|
||||||
|
// This example generates a hexadecimal string 6 characters long:
|
||||||
|
// GenerateRandomString("0123456789abcdef", 6)
|
||||||
|
func GenerateRandomString(dictionary string, l int) string {
|
||||||
|
var bytes = make([]byte, l)
|
||||||
|
rand.Read(bytes)
|
||||||
|
for k, v := range bytes {
|
||||||
|
bytes[k] = dictionary[v%byte(len(dictionary))]
|
||||||
|
}
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
// GenSafeUniqueSlug generatees a reasonably unique random slug from the given
|
// GenSafeUniqueSlug generatees a reasonably unique random slug from the given
|
||||||
// original slug. It's "safe" because it uses 0-9 b-z excluding vowels.
|
// original slug. It's "safe" because it uses 0-9 b-z excluding vowels.
|
||||||
func GenSafeUniqueSlug(slug string) string {
|
func GenSafeUniqueSlug(slug string) string {
|
||||||
return fmt.Sprintf("%s-%s", slug, store.GenerateRandomString("0123456789bcdfghjklmnpqrstvwxyz", 4))
|
return fmt.Sprintf("%s-%s", slug, GenerateRandomString("0123456789bcdfghjklmnpqrstvwxyz", 4))
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-8
@@ -3,24 +3,24 @@ package l10n
|
|||||||
var phrasesZH = map[string]string{
|
var phrasesZH = map[string]string{
|
||||||
"Anonymous post": "匿名文章",
|
"Anonymous post": "匿名文章",
|
||||||
"Blogs": "博客",
|
"Blogs": "博客",
|
||||||
"Enter": "按下Enter按钮",
|
"Enter": "按下回车",
|
||||||
"Newer": "最近的博客",
|
"Newer": "更新",
|
||||||
"Older": "之前的博客",
|
"Older": "较旧",
|
||||||
"Posts": "文章",
|
"Posts": "文章",
|
||||||
"Publish to...": "发布到...",
|
"Publish to...": "发布到...",
|
||||||
"Publish": "发布",
|
"Publish": "发布",
|
||||||
"Read more...": "阅读更多",
|
"Read more...": "阅读更多",
|
||||||
"This blog requires a password.": "这篇博客需要密码",
|
"This blog requires a password.": "这篇文章需要密码",
|
||||||
"Toggle theme": "更换主题",
|
"Toggle theme": "更换主题",
|
||||||
"View posts": "查看文章",
|
"View posts": "查看文章",
|
||||||
"delete": "删除",
|
"delete": "删除",
|
||||||
"edit": "编辑",
|
"edit": "编辑",
|
||||||
"move to...": "移动到",
|
"move to...": "移动到",
|
||||||
"pin": "固定文章",
|
"pin": "固定文章",
|
||||||
"published with write.as": "用write.as来发布",
|
"published with write.as": "通过 write.as 发布",
|
||||||
"share modal ending": "发送给朋友,或者线上分享,如果可能的话,分享到推特上。了解更多。",
|
"share modal ending": "发送给朋友、与世界分享或者发条推。了解更多。",
|
||||||
"share modal introduction": "发布的每篇文章都有一个唯一的私有URL,你可以把它分享给任何人。这是URL:",
|
"share modal introduction": "发布的每篇文章都有一个唯一的私有网址,你可以把它分享给任何人:",
|
||||||
"share modal title": "分享这篇文章",
|
"share modal title": "分享文章",
|
||||||
"share": "分享",
|
"share": "分享",
|
||||||
"unpin": "取消固定",
|
"unpin": "取消固定",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,3 +67,13 @@ func (memo *Memo) Get() (value interface{}, err error) {
|
|||||||
}
|
}
|
||||||
return memo.cache.res.value, memo.cache.res.err
|
return memo.cache.res.value, memo.cache.res.err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset forcibly resets the cache to nil without checking if the cache
|
||||||
|
// duration has elapsed.
|
||||||
|
func (memo *Memo) Reset() {
|
||||||
|
defer memo.mu.Unlock()
|
||||||
|
memo.mu.Lock()
|
||||||
|
|
||||||
|
memo.cache = nil
|
||||||
|
memo.lastCache = time.Now()
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package silobridge
|
||||||
|
|
||||||
|
// fakeAPInstances contains a list of sites that we allow writers to mention
|
||||||
|
// with the @handle@instance.tld syntax, plus the corresponding prefix to
|
||||||
|
// insert between `https://instance.tld/` and `handle` (e.g.
|
||||||
|
// https://medium.com/@handle)
|
||||||
|
var fakeAPInstances = map[string]string{
|
||||||
|
"deviantart.com": "",
|
||||||
|
"facebook.com": "",
|
||||||
|
"flickr.com": "photos/",
|
||||||
|
"github.com": "",
|
||||||
|
"instagram.com": "",
|
||||||
|
"medium.com": "@",
|
||||||
|
"reddit.com": "user/",
|
||||||
|
"twitter.com": "",
|
||||||
|
"wattpad.com": "user/",
|
||||||
|
"youtube.com": "user/",
|
||||||
|
}
|
||||||
|
|
||||||
|
// Profile returns the full profile URL for a fake ActivityPub instance, based
|
||||||
|
// on the given handle and domain. If the domain isn't recognized, an empty
|
||||||
|
// string is returned.
|
||||||
|
func Profile(handle, domain string) string {
|
||||||
|
prefix, ok := fakeAPInstances[domain]
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return "https://" + domain + "/" + prefix + handle
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user