From a43c5c5b4048ca46ef91ecf482bc3b2135c95366 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 30 May 2022 18:02:12 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=94=B9=E8=BF=9B=20`=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E5=9B=BE=E7=89=87=E8=BD=AC=E6=8D=A2=E4=B8=BA=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=9B=BE=E7=89=87`=20=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=90=8E=E7=BC=80=20Fix=20https://github.com/siyuan-note/siyua?= =?UTF-8?q?n/issues/5053?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + README_zh_CN.md | 1 + .../20201121224345-rc27qvo.sy | 74 +++++++++++++++++- .../20201121212605-9td1a62.sy | 78 ++++++++++++++++++- .../20211226114929-08ap1r0.sy | 74 +++++++++++++++++- kernel/go.mod | 3 +- kernel/go.sum | 3 + kernel/model/assets.go | 6 ++ 8 files changed, 231 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8498841b2..3fc609e62 100644 --- a/README.md +++ b/README.md @@ -261,6 +261,7 @@ SiYuan is made possible by the following open source projects. * [https://github.com/facette/natsort](https://github.com/facette/natsort) `BSD-3-Clause License` * [https://github.com/flopp/go-findfont](https://github.com/flopp/go-findfont) `MIT License` * [https://github.com/fsnotify/fsnotify](https://github.com/fsnotify/fsnotify) `BSD-3-Clause License` +* [https://github.com/gabriel-vasile/mimetype](https://github.com/gabriel-vasile/mimetype) `MIT License` * [https://github.com/gin-contrib/cors](https://github.com/gin-contrib/cors) `MIT License` * [https://github.com/gin-contrib/gzip](https://github.com/gin-contrib/gzip) `MIT License` * [https://github.com/gin-contrib/sessions](https://github.com/gin-contrib/sessions) `MIT License` diff --git a/README_zh_CN.md b/README_zh_CN.md index 1e1f28a35..e4bd426a1 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -269,6 +269,7 @@ * [https://github.com/facette/natsort](https://github.com/facette/natsort) `BSD-3-Clause License` * [https://github.com/flopp/go-findfont](https://github.com/flopp/go-findfont) `MIT License` * [https://github.com/fsnotify/fsnotify](https://github.com/fsnotify/fsnotify) `BSD-3-Clause License` +* [https://github.com/gabriel-vasile/mimetype](https://github.com/gabriel-vasile/mimetype) `MIT License` * [https://github.com/gin-contrib/cors](https://github.com/gin-contrib/cors) `MIT License` * [https://github.com/gin-contrib/gzip](https://github.com/gin-contrib/gzip) `MIT License` * [https://github.com/gin-contrib/sessions](https://github.com/gin-contrib/sessions) `MIT License` diff --git a/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy b/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy index 88ca399f6..5081bbf95 100644 --- a/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy +++ b/app/guide/20210808180117-6v0mkxr/20201121224345-rc27qvo.sy @@ -6,7 +6,7 @@ "id": "20201121224345-rc27qvo", "title": "Acknowledgements", "type": "doc", - "updated": "20220522101213" + "updated": "20220530180108" }, "Children": [ { @@ -29,7 +29,7 @@ "ListData": {}, "Properties": { "id": "20220522101213-z3hokh2", - "updated": "20220522101213" + "updated": "20220530180108" }, "Children": [ { @@ -1572,6 +1572,76 @@ } ] }, + { + "ID": "20220530180107-u2pjucg", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220530180107-u2pjucg", + "updated": "20220530180108" + }, + "Children": [ + { + "ID": "20220530180107-zbx81j2", + "Type": "NodeParagraph", + "Properties": { + "id": "20220530180107-zbx81j2", + "updated": "20220530180108" + }, + "Children": [ + { + "Type": "NodeLink", + "Data": "span", + "Children": [ + { + "Type": "NodeOpenBracket" + }, + { + "Type": "NodeLinkText", + "Data": "https://github.com/gabriel-vasile/mimetype" + }, + { + "Type": "NodeCloseBracket" + }, + { + "Type": "NodeOpenParen" + }, + { + "Type": "NodeLinkDest", + "Data": "https://github.com/gabriel-vasile/mimetype" + }, + { + "Type": "NodeCloseParen" + } + ] + }, + { + "Type": "NodeText", + "Data": " " + }, + { + "Type": "NodeCodeSpan", + "Data": "code", + "Children": [ + { + "Type": "NodeCodeSpanOpenMarker" + }, + { + "Type": "NodeCodeSpanContent", + "Data": "MIT License" + }, + { + "Type": "NodeCodeSpanCloseMarker" + } + ] + } + ] + } + ] + }, { "ID": "20220522101213-xvc77du", "Type": "NodeListItem", diff --git a/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy b/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy index 998d3c2ec..87a339b87 100644 --- a/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy +++ b/app/guide/20210808180117-czj9bvb/20201121212605-9td1a62.sy @@ -6,7 +6,7 @@ "id": "20201121212605-9td1a62", "title": "致谢", "type": "doc", - "updated": "20220522101224" + "updated": "20220530180055" }, "Children": [ { @@ -29,7 +29,7 @@ "ListData": {}, "Properties": { "id": "20220522101224-ctmcj3d", - "updated": "20220522101224" + "updated": "20220530180055" }, "Children": [ { @@ -1511,7 +1511,7 @@ }, "Properties": { "id": "20220522101224-gbd2na7", - "updated": "20220522101224" + "updated": "20220530180049" }, "Children": [ { @@ -1519,7 +1519,7 @@ "Type": "NodeParagraph", "Properties": { "id": "20220522101224-mwz2rxp", - "updated": "20220522101224" + "updated": "20220530180049" }, "Children": [ { @@ -1572,6 +1572,76 @@ } ] }, + { + "ID": "20220530180049-796wwcg", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220530180049-796wwcg", + "updated": "20220530180055" + }, + "Children": [ + { + "ID": "20220530180049-qvs3gi0", + "Type": "NodeParagraph", + "Properties": { + "id": "20220530180049-qvs3gi0", + "updated": "20220530180055" + }, + "Children": [ + { + "Type": "NodeLink", + "Data": "span", + "Children": [ + { + "Type": "NodeOpenBracket" + }, + { + "Type": "NodeLinkText", + "Data": "https://github.com/gabriel-vasile/mimetype" + }, + { + "Type": "NodeCloseBracket" + }, + { + "Type": "NodeOpenParen" + }, + { + "Type": "NodeLinkDest", + "Data": "https://github.com/gabriel-vasile/mimetype" + }, + { + "Type": "NodeCloseParen" + } + ] + }, + { + "Type": "NodeText", + "Data": " " + }, + { + "Type": "NodeCodeSpan", + "Data": "code", + "Children": [ + { + "Type": "NodeCodeSpanOpenMarker" + }, + { + "Type": "NodeCodeSpanContent", + "Data": "MIT License" + }, + { + "Type": "NodeCodeSpanCloseMarker" + } + ] + } + ] + } + ] + }, { "ID": "20220522101224-rb7cnss", "Type": "NodeListItem", diff --git a/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy b/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy index 4f97fe763..b99deef9e 100644 --- a/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy +++ b/app/guide/20211226090932-5lcq56f/20211226114929-08ap1r0.sy @@ -5,7 +5,7 @@ "icon": "1f64f", "id": "20211226114929-08ap1r0", "title": "致謝", - "updated": "20220522101124" + "updated": "20220530180118" }, "Children": [ { @@ -28,7 +28,7 @@ "ListData": {}, "Properties": { "id": "20220326092650-r61gazd", - "updated": "20220522101124" + "updated": "20220530180118" }, "Children": [ { @@ -1571,6 +1571,76 @@ } ] }, + { + "ID": "20220530180117-4u0c53m", + "Type": "NodeListItem", + "ListData": { + "BulletChar": 42, + "Marker": "Kg==" + }, + "Properties": { + "id": "20220530180117-4u0c53m", + "updated": "20220530180118" + }, + "Children": [ + { + "ID": "20220530180117-wnowy4x", + "Type": "NodeParagraph", + "Properties": { + "id": "20220530180117-wnowy4x", + "updated": "20220530180118" + }, + "Children": [ + { + "Type": "NodeLink", + "Data": "span", + "Children": [ + { + "Type": "NodeOpenBracket" + }, + { + "Type": "NodeLinkText", + "Data": "https://github.com/gabriel-vasile/mimetype" + }, + { + "Type": "NodeCloseBracket" + }, + { + "Type": "NodeOpenParen" + }, + { + "Type": "NodeLinkDest", + "Data": "https://github.com/gabriel-vasile/mimetype" + }, + { + "Type": "NodeCloseParen" + } + ] + }, + { + "Type": "NodeText", + "Data": " " + }, + { + "Type": "NodeCodeSpan", + "Data": "code", + "Children": [ + { + "Type": "NodeCodeSpanOpenMarker" + }, + { + "Type": "NodeCodeSpanContent", + "Data": "MIT License" + }, + { + "Type": "NodeCodeSpanCloseMarker" + } + ] + } + ] + } + ] + }, { "ID": "20220326092650-zmj3bdd", "Type": "NodeListItem", diff --git a/kernel/go.mod b/kernel/go.mod index 7d74fec5f..03115553e 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -24,6 +24,7 @@ require ( github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb github.com/flopp/go-findfont v0.1.0 github.com/fsnotify/fsnotify v1.5.4 + github.com/gabriel-vasile/mimetype v1.4.0 github.com/getsentry/sentry-go v0.13.0 github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/gzip v0.0.5 @@ -32,6 +33,7 @@ require ( github.com/imroc/req/v3 v3.11.3 github.com/jinzhu/copier v0.3.5 github.com/mattn/go-sqlite3 v2.0.3+incompatible + github.com/mattn/go-zglob v0.0.3 github.com/mitchellh/go-ps v1.0.0 github.com/mssola/user_agent v0.5.3 github.com/panjf2000/ants/v2 v2.5.0 @@ -78,7 +80,6 @@ require ( github.com/juju/errors v0.0.0-20220331221717-b38fca44723b // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/mattn/go-isatty v0.0.14 // indirect - github.com/mattn/go-zglob v0.0.3 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect diff --git a/kernel/go.sum b/kernel/go.sum index 4ee08a108..c06d3b2cc 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -136,6 +136,8 @@ github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3 github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI= github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU= +github.com/gabriel-vasile/mimetype v1.4.0 h1:Cn9dkdYsMIu56tGho+fqzh7XmvY2YyGU0FnbhiOsEro= +github.com/gabriel-vasile/mimetype v1.4.0/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8= github.com/getsentry/sentry-go v0.13.0 h1:20dgTiUSfxRB/EhMPtxcL9ZEbM1ZdR+W/7f7NWD+xWo= github.com/getsentry/sentry-go v0.13.0/go.mod h1:EOsfu5ZdvKPfeHYV6pTVQnsjfp30+XA7//UooKNumH0= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= @@ -554,6 +556,7 @@ golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= +golang.org/x/net v0.0.0-20210505024714-0287a6fb4125/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 3ecbaba7f..3f07737c8 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -34,6 +34,7 @@ import ( "github.com/88250/gulu" "github.com/88250/lute/ast" "github.com/88250/lute/parse" + "github.com/gabriel-vasile/mimetype" "github.com/siyuan-note/siyuan/kernel/filesys" "github.com/siyuan-note/siyuan/kernel/search" "github.com/siyuan-note/siyuan/kernel/sql" @@ -116,6 +117,11 @@ func NetImg2LocalAssets(rootID string) (err error) { } name, _ = url.PathUnescape(name) ext := path.Ext(name) + if "" == ext { + if mtype := mimetype.Detect(data); nil != mtype { + ext = mtype.Extension() + } + } if "" == ext { contentType := resp.Header.Get("Content-Type") exts, _ := mime.ExtensionsByType(contentType)