Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2024-11-08 01:17:57 +08:00
commit 748b045c3d
15 changed files with 78 additions and 15 deletions

View file

@ -16,7 +16,7 @@ import {initAbout} from "../settings/about";
import {getRecentDocs} from "./getRecentDocs";
import {initEditor} from "../settings/editor";
import {App} from "../../index";
import {isHuawei, isInAndroid, isInIOS, isIPhone} from "../../protyle/util/compatibility";
import {isDisabledFeature, isHuawei, isInAndroid, isInIOS, isIPhone} from "../../protyle/util/compatibility";
import {newFile} from "../../util/newFile";
import {afterLoadPlugin} from "../../plugin/loader";
import {commandPanel} from "../../boot/globalEvent/command/panel";
@ -45,8 +45,9 @@ export const initRightMenu = (app: App) => {
let aiHTML = `<div class="b3-menu__item${window.siyuan.config.readonly ? " fn__none" : ""}" id="menuAI">
<svg class="b3-menu__icon"><use xlink:href="#iconSparkles"></use></svg><span class="b3-menu__label">AI</span>
</div>`;
if (isHuawei()) {
if (isHuawei() || isDisabledFeature("ai")) {
// Access to the OpenAI API is no longer supported on Huawei devices https://github.com/siyuan-note/siyuan/issues/8192
// Apps in Chinese mainland app stores no longer provide AI access settings https://github.com/siyuan-note/siyuan/issues/13051
aiHTML = "";
}

View file

@ -110,6 +110,10 @@ export const isHuawei = () => {
return window.siyuan.config.system.osPlatform.toLowerCase().indexOf("huawei") > -1;
};
export const isDisabledFeature = (feature: string): boolean => {
return window.siyuan.config.system.disabledFeatures.indexOf(feature) > -1;
}
export const isIPhone = () => {
return navigator.userAgent.indexOf("iPhone") > -1;
};

View file

@ -1521,6 +1521,10 @@ declare namespace Config {
* The absolute path of the workspace directory
*/
workspaceDir: string;
/**
* Disabled features.
*/
disabledFeatures: string[];
}
/**

File diff suppressed because one or more lines are too long

View file

@ -302,6 +302,12 @@ func getUnusedAssets(c *gin.Context) {
defer c.JSON(http.StatusOK, ret)
unusedAssets := model.UnusedAssets()
// List only 512 unreferenced assets https://github.com/siyuan-note/siyuan/issues/13075
if len(unusedAssets) > 512 {
unusedAssets = unusedAssets[:512]
}
ret.Data = map[string]interface{}{
"unusedAssets": unusedAssets,
}

View file

@ -44,6 +44,8 @@ type System struct {
DownloadInstallPkg bool `json:"downloadInstallPkg"`
AutoLaunch2 int `json:"autoLaunch2"` // 0不自动启动1自动启动2自动启动+隐藏主窗口
LockScreenMode int `json:"lockScreenMode"` // 0手动1手动+跟随系统 https://github.com/siyuan-note/siyuan/issues/9087
DisabledFeatures []string `json:"disabledFeatures"`
}
func NewSystem() *System {

View file

@ -10,7 +10,7 @@ require (
github.com/88250/epub v0.0.0-20230830085737-c19055cd1f48
github.com/88250/go-humanize v0.0.0-20240424102817-4f78fac47ea7
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02
github.com/88250/lute v1.7.7-0.20241104160608-6885b1ea84cd
github.com/88250/lute v1.7.7-0.20241106021724-1c970cf3f601
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1
github.com/ClarkThan/ahocorasick v0.0.0-20231011042242-30d1ef1347f4

View file

@ -14,8 +14,8 @@ github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950 h1:Pa5hMiBceT
github.com/88250/go-sqlite3 v1.14.13-0.20231214121541-e7f54c482950/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02 h1:3e5+yobj655pTeKOYMbJrnc1mE51ZkbXIxquTYZuYCY=
github.com/88250/gulu v1.2.3-0.20240612035750-c9cf5f7a4d02/go.mod h1:MUfzyfmbPrRDZLqxc7aPrVYveatTHRfoUa5TynPS0i8=
github.com/88250/lute v1.7.7-0.20241104160608-6885b1ea84cd h1:pBo4pZnyed6hnab8LmT/AYHl9mUI2k5xkGWHdedr9FI=
github.com/88250/lute v1.7.7-0.20241104160608-6885b1ea84cd/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/lute v1.7.7-0.20241106021724-1c970cf3f601 h1:AEt0XZj8XzjWt0hQ4MveQzjTiT5RyL6XPjetEn7VeKU=
github.com/88250/lute v1.7.7-0.20241106021724-1c970cf3f601/go.mod h1:VDAzL8b+oCh+e3NAlmwwLzC53ten0rZlS8NboB7ljtk=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c h1:Dl/8S9iLyPMTElnWIBxmjaLiWrkI5P4a21ivwAn5pU0=
github.com/88250/pdfcpu v0.3.14-0.20230401044135-c7369a99720c/go.mod h1:S5YT38L/GCjVjmB4PB84PymA1qfopjEhfhTNQilLpv4=
github.com/88250/vitess-sqlparser v0.0.0-20210205111146-56a2ded2aba1 h1:48T899JQDwyyRu9yXHePYlPdHtpJfrJEUGBMH3SMBWY=

View file

@ -114,3 +114,7 @@ func SetTimezone(container, appDir, timezoneID string) {
}
time.Local = z
}
func DisableFeature(feature string) {
util.DisableFeature(feature)
}

View file

@ -63,6 +63,9 @@ func GetAssetContent(id, query string, queryMethod int) (ret *AssetContent) {
query = stringQuery(query)
}
}
if !ast.IsNodeIDPattern(id) {
return
}
table := "asset_contents_fts_case_insensitive"
filter := " id = '" + id + "'"

View file

@ -220,6 +220,7 @@ func InitConf() {
util.UseSingleLineSave = Conf.FileTree.UseSingleLineSave
util.CurrentCloudRegion = Conf.CloudRegion
Conf.System.DisabledFeatures = util.DisabledFeatures
if nil == Conf.Tag {
Conf.Tag = conf.NewTag()

View file

@ -448,6 +448,13 @@ func FullTextSearchHistoryItems(created, query, box, op string, typ int) (ret []
table := "histories_fts_case_insensitive"
stmt := "SELECT * FROM " + table + " WHERE "
stmt += buildSearchHistoryQueryFilter(query, op, box, table, typ)
_, parseErr := strconv.Atoi(created)
if nil != parseErr {
ret = []*HistoryItem{}
return
}
stmt += " AND created = '" + created + "' ORDER BY created DESC LIMIT " + fmt.Sprintf("%d", fileHistoryPageSize)
sqlHistories := sql.SelectHistoriesRawStmt(stmt)
ret = fromSQLHistories(sqlHistories)
@ -473,6 +480,10 @@ func buildSearchHistoryQueryFilter(query, op, box, table string, typ int) (stmt
stmt += " AND op = '" + op + "'"
}
if "%" != box && !ast.IsNodeIDPattern(box) {
box = "%"
}
if HistoryTypeDocName == typ || HistoryTypeDoc == typ || HistoryTypeDocID == typ {
if HistoryTypeDocName == typ || HistoryTypeDoc == typ {
stmt += " AND path LIKE '%/" + box + "/%' AND path LIKE '%.sy'"

View file

@ -261,12 +261,15 @@ func RenderAttributeViewTable(attrView *av.AttributeView, view *av.View, query s
}
if nil != destAv {
blocks := map[string]*av.Value{}
for _, blockValue := range destAv.GetBlockKeyValues().Values {
blocks[blockValue.BlockID] = blockValue
}
for _, blockID := range cell.Value.Relation.BlockIDs {
if val := blocks[blockID]; nil != val {
cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, val)
blockValues := destAv.GetBlockKeyValues()
if nil != blockValues {
for _, blockValue := range blockValues.Values {
blocks[blockValue.BlockID] = blockValue
}
for _, blockID := range cell.Value.Relation.BlockIDs {
if val := blocks[blockID]; nil != val {
cell.Value.Relation.Contents = append(cell.Value.Relation.Contents, val)
}
}
}
}

View file

@ -343,10 +343,24 @@ func GetBlockTrees(ids []string) (ret map[string]*BlockTree) {
return
}
sqlStmt := "SELECT * FROM blocktrees WHERE id IN ('" + strings.Join(ids, "','") + "')"
rows, err := db.Query(sqlStmt)
stmtBuf := bytes.Buffer{}
stmtBuf.WriteString("SELECT * FROM blocktrees WHERE id IN (")
for i := range ids {
stmtBuf.WriteString("?")
if i == len(ids)-1 {
stmtBuf.WriteString(")")
} else {
stmtBuf.WriteString(",")
}
}
var args []any
for _, id := range ids {
args = append(args, id)
}
stmt := stmtBuf.String()
rows, err := db.Query(stmt, args...)
if err != nil {
logging.LogErrorf("sql query [%s] failed: %s", sqlStmt, err)
logging.LogErrorf("sql query [%s] failed: %s", stmt, err)
return
}
defer rows.Close()

View file

@ -38,6 +38,13 @@ import (
"github.com/siyuan-note/logging"
)
var DisabledFeatures []string
func DisableFeature(feature string) {
DisabledFeatures = append(DisabledFeatures, feature)
DisabledFeatures = gulu.Str.RemoveDuplicatedElem(DisabledFeatures)
}
// UseSingleLineSave 是否使用单行保存 .sy 和数据库 .json 文件。
var UseSingleLineSave = true
@ -88,6 +95,9 @@ func logBootInfo() {
" * database [ver=%s]\n"+
" * workspace directory [%s]",
Ver, runtime.GOARCH, plat, os.Getpid(), Mode, WorkingDir, ReadOnly, Container, DatabaseVer, WorkspaceDir)
if 0 < len(DisabledFeatures) {
logging.LogInfof("disabled features [%s]", strings.Join(DisabledFeatures, ", "))
}
}
func RandomSleep(minMills, maxMills int) {