Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
e92da8ad73
8 changed files with 61 additions and 23 deletions
|
@ -1017,8 +1017,7 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
bind(element) {
|
||||
element.style.maxWidth = "none";
|
||||
fetchPost("/api/asset/getImageOCRText", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
force: false
|
||||
path: imgElement.getAttribute("src")
|
||||
}, (response) => {
|
||||
element.querySelector("textarea").value = response.data.text;
|
||||
});
|
||||
|
@ -1029,9 +1028,14 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
iconHTML: "",
|
||||
label: window.siyuan.languages.reOCR,
|
||||
click() {
|
||||
fetchPost("/api/asset/getImageOCRText", {
|
||||
fetchPost("/api/asset/ocr", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
force: true
|
||||
}, (response) => {
|
||||
fetchPost("/api/asset/setImageOCRText", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
text: response.data.text
|
||||
});
|
||||
});
|
||||
}
|
||||
}],
|
||||
|
@ -1115,13 +1119,6 @@ export const imgMenu = (protyle: IProtyle, range: Range, assetElement: HTMLEleme
|
|||
const textElements = window.siyuan.menus.menu.element.querySelectorAll("textarea");
|
||||
textElements[0].focus();
|
||||
window.siyuan.menus.menu.removeCB = () => {
|
||||
const ocrElemennt = window.siyuan.menus.menu.element.querySelector('[data-type="ocr"]') as HTMLTextAreaElement;
|
||||
if (ocrElemennt) {
|
||||
fetchPost("/api/asset/setImageOCRText", {
|
||||
path: imgElement.getAttribute("src"),
|
||||
text: ocrElemennt.value
|
||||
});
|
||||
}
|
||||
imgElement.setAttribute("alt", textElements[2].value.replace(/\n|\r\n|\r|\u2028|\u2029/g, ""));
|
||||
nodeElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
|
||||
updateTransaction(protyle, id, nodeElement.outerHTML, html);
|
||||
|
|
|
@ -107,13 +107,9 @@ func getImageOCRText(c *gin.Context) {
|
|||
}
|
||||
|
||||
path := arg["path"].(string)
|
||||
force := false
|
||||
if forceArg := arg["force"]; nil != forceArg {
|
||||
force = forceArg.(bool)
|
||||
}
|
||||
|
||||
ret.Data = map[string]interface{}{
|
||||
"text": util.GetAssetText(path, force),
|
||||
"text": util.GetAssetText(path),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +127,26 @@ func setImageOCRText(c *gin.Context) {
|
|||
util.SetAssetText(path, text)
|
||||
}
|
||||
|
||||
func ocr(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
path := arg["path"].(string)
|
||||
force := false
|
||||
if forceArg := arg["force"]; nil != forceArg {
|
||||
force = forceArg.(bool)
|
||||
}
|
||||
|
||||
ret.Data = map[string]interface{}{
|
||||
"text": util.OcrAsset(path, force),
|
||||
}
|
||||
}
|
||||
|
||||
func renameAsset(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
@ -266,6 +266,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/asset/renameAsset", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, renameAsset)
|
||||
ginServer.Handle("POST", "/api/asset/getImageOCRText", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getImageOCRText)
|
||||
ginServer.Handle("POST", "/api/asset/setImageOCRText", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setImageOCRText)
|
||||
ginServer.Handle("POST", "/api/asset/ocr", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, ocr)
|
||||
ginServer.Handle("POST", "/api/asset/fullReindexAssetContent", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, fullReindexAssetContent)
|
||||
ginServer.Handle("POST", "/api/asset/statAsset", model.CheckAuth, model.CheckAdminRole, statAsset)
|
||||
|
||||
|
|
|
@ -341,11 +341,16 @@ func searchRefBlock(c *gin.Context) {
|
|||
isSquareBrackets = isSquareBracketsArg.(bool)
|
||||
}
|
||||
|
||||
isDatabase := false
|
||||
if isDatabaseArg := arg["isDatabase"]; nil != isDatabaseArg {
|
||||
isDatabase = isDatabaseArg.(bool)
|
||||
}
|
||||
|
||||
rootID := arg["rootID"].(string)
|
||||
id := arg["id"].(string)
|
||||
keyword := arg["k"].(string)
|
||||
beforeLen := int(arg["beforeLen"].(float64))
|
||||
blocks, newDoc := model.SearchRefBlock(id, rootID, keyword, beforeLen, isSquareBrackets)
|
||||
blocks, newDoc := model.SearchRefBlock(id, rootID, keyword, beforeLen, isSquareBrackets, isDatabase)
|
||||
ret.Data = map[string]interface{}{
|
||||
"blocks": blocks,
|
||||
"newDoc": newDoc,
|
||||
|
|
|
@ -1640,6 +1640,15 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
}
|
||||
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
|
||||
|
||||
// 刷新文档关联的数据库 https://github.com/siyuan-note/siyuan/issues/11731
|
||||
allRemoveRootIDs := []string{tree.ID}
|
||||
allRemoveRootIDs = append(allRemoveRootIDs, removeIDs...)
|
||||
for _, rootID := range allRemoveRootIDs {
|
||||
if removeTree, _ := LoadTreeByBlockID(rootID); nil != removeTree {
|
||||
syncDelete2AttributeView(removeTree.Root)
|
||||
}
|
||||
}
|
||||
|
||||
if existChildren {
|
||||
if err = box.Remove(childrenDir); nil != err {
|
||||
logging.LogErrorf("remove children dir [%s%s] failed: %s", box.ID, childrenDir, err)
|
||||
|
|
|
@ -311,7 +311,7 @@ func buildEmbedBlock(embedBlockID string, excludeIDs []string, headingMode int,
|
|||
return
|
||||
}
|
||||
|
||||
func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets bool) (ret []*Block, newDoc bool) {
|
||||
func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets, isDatabase bool) (ret []*Block, newDoc bool) {
|
||||
cachedTrees := map[string]*parse.Tree{}
|
||||
|
||||
onlyDoc := false
|
||||
|
@ -398,9 +398,13 @@ func SearchRefBlock(id, rootID, keyword string, beforeLen int, isSquareBrackets
|
|||
}
|
||||
ret = tmp
|
||||
|
||||
if block := treenode.GetBlockTree(id); nil != block {
|
||||
p := path.Join(block.HPath, keyword)
|
||||
newDoc = nil == treenode.GetBlockTreeRootByHPath(block.BoxID, p)
|
||||
if !isDatabase {
|
||||
// 如果非数据库中搜索块引,则不允许新建重名文档
|
||||
// 如果是数据库中搜索绑定块,则允许新建重名文档 https://github.com/siyuan-note/siyuan/issues/11713
|
||||
if block := treenode.GetBlockTree(id); nil != block {
|
||||
p := path.Join(block.HPath, keyword)
|
||||
newDoc = nil == treenode.GetBlockTreeRootByHPath(block.BoxID, p)
|
||||
}
|
||||
}
|
||||
|
||||
// 在 hPath 中加入笔记本名 Show notebooks in hpath of block ref search list results https://github.com/siyuan-note/siyuan/issues/9378
|
||||
|
|
|
@ -198,7 +198,7 @@ func nodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||
var linkDestStr, ocrText string
|
||||
if nil != linkDest {
|
||||
linkDestStr = linkDest.TokensStr()
|
||||
ocrText = util.GetAssetText(linkDestStr, false)
|
||||
ocrText = util.OcrAsset(linkDestStr, false)
|
||||
}
|
||||
|
||||
linkText := n.ChildByType(ast.NodeLinkText)
|
||||
|
|
|
@ -102,7 +102,7 @@ func LoadAssetsTexts() {
|
|||
}
|
||||
|
||||
func SaveAssetsTexts() {
|
||||
if !assetsTextsChanged.Load() || !TesseractEnabled {
|
||||
if !assetsTextsChanged.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ func ExistsAssetText(asset string) (ret bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetAssetText(asset string, force bool) (ret string) {
|
||||
func OcrAsset(asset string, force bool) (ret string) {
|
||||
if !force {
|
||||
assetsTextsLock.Lock()
|
||||
ret = assetsTexts[asset]
|
||||
|
@ -170,6 +170,12 @@ func GetAssetText(asset string, force bool) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
// https://github.com/siyuan-note/siyuan/pull/11708
|
||||
func GetAssetText(asset string) (ret string) {
|
||||
ret = assetsTexts[asset]
|
||||
return
|
||||
}
|
||||
|
||||
func IsTesseractExtractable(p string) bool {
|
||||
lowerName := strings.ToLower(p)
|
||||
return strings.HasSuffix(lowerName, ".png") || strings.HasSuffix(lowerName, ".jpg") || strings.HasSuffix(lowerName, ".jpeg")
|
||||
|
|
Loading…
Add table
Reference in a new issue