Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Support opening assets through other apps on the Android https://github.com/siyuan-note/siyuan/issues/10657

Danielc5cc3ff779c8
diff --git a/kernel/mobile/kernel.go b/kernel/mobile/kernel.go
index 7aff63245d..8ecd3d9f70 100644
--- a/kernel/mobile/kernel.go
+++ b/kernel/mobile/kernel.go
@@ -99,6 +99,10 @@ func GetAssetAbsPath(asset string) (ret string) {
return
}
+func GetMimeTypeByExt(ext string) string {
+ return util.GetMimeTypeByExt(ext)
+}
+
func SetTimezone(container, appDir, timezoneID string) {
if "ios" == container {
os.Setenv("ZONEINFO", filepath.Join(appDir, "app", "zoneinfo.zip"))
diff --git a/kernel/util/file.go b/kernel/util/file.go
index 9dafed651d..4af6e40b06 100644
--- a/kernel/util/file.go
+++ b/kernel/util/file.go
@@ -20,6 +20,7 @@ import (
"bytes"
"io"
"io/fs"
+ "mime"
"os"
"path"
"path/filepath"
@@ -28,10 +29,26 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
+ "github.com/gabriel-vasile/mimetype"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
)
+func GetMimeTypeByExt(filePath string) (ret string) {
+ ret = mime.TypeByExtension(filepath.Ext(filePath))
+ if "" == ret {
+ m, err := mimetype.DetectFile(filePath)
+ if nil != err {
+ logging.LogErrorf("detect mime type of [%s] failed: %s", filePath, err)
+ return
+ }
+ if nil != m {
+ ret = m.String()
+ }
+ }
+ return
+}
+
func IsSymlinkPath(absPath string) bool {
fi, err := os.Lstat(absPath)
if nil != err {