mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
🎨 Support searching EPUB asset content Fix https://github.com/siyuan-note/siyuan/issues/9000
This commit is contained in:
parent
732c0805ca
commit
04cf28c962
4 changed files with 47 additions and 1 deletions
|
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
"github.com/wmentor/epub"
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
|
|
@ -456,6 +457,7 @@ func NewAssetsSearcher() *AssetsSearcher {
|
|||
".pptx": &PptxAssetParser{},
|
||||
".xlsx": &XlsxAssetParser{},
|
||||
".pdf": &PdfAssetParser{},
|
||||
".epub": &EpubAssetParser{},
|
||||
},
|
||||
|
||||
lock: &sync.Mutex{},
|
||||
|
|
@ -750,3 +752,41 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
type EpubAssetParser struct {
|
||||
}
|
||||
|
||||
func (parser *EpubAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
||||
if !strings.HasSuffix(strings.ToLower(absPath), ".epub") {
|
||||
return
|
||||
}
|
||||
|
||||
if !gulu.File.IsExist(absPath) {
|
||||
return
|
||||
}
|
||||
|
||||
tmp := copyTempAsset(absPath)
|
||||
if "" == tmp {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(tmp)
|
||||
|
||||
f, err := os.Open(tmp)
|
||||
if nil != err {
|
||||
logging.LogErrorf("open [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
if err = epub.ToTxt(tmp, &buf); nil != err {
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
||||
content := normalizeAssetContent(buf.String())
|
||||
ret = &AssetParseResult{
|
||||
Content: content,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue