Skip to content

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

:recycle: Consolidate stale map asset cleanup into the build and kernel startup https://github.com/siyuan-note/siyuan/pull/20469

Jeffrey Chen630731e80e77
diff --git a/.dockerignore b/.dockerignore
deleted file mode 100644
index df86dcb179..0000000000
--- a/.dockerignore
+++ /dev/null
@@ -1,2 +0,0 @@
-app/stage/map
-app/stage/build/map
diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml
index cb8aa8e99a..5e05f9e835 100644
--- a/.github/workflows/cd.yml
+++ b/.github/workflows/cd.yml
@@ -680,7 +680,7 @@ jobs:
cd ${{ github.workspace }}/go/src/github.com/${{ github.repository }}/app
node scripts/trimChangelogs.js
python3 ../scripts/prepare-ocr.py
- zip -r app.zip appearance guide stage $([ -d changelogs ] && echo changelogs) -x 'stage/ocr/runtime/*' 'stage/map/*' 'stage/build/map/*'
+ zip -r app.zip appearance guide stage $([ -d changelogs ] && echo changelogs) -x 'stage/ocr/runtime/*'
zip -j app.zip ../LICENSE ../THIRD_PARTY_NOTICES.md
mkdir -p ${{ github.workspace }}/siyuan-android/app/src/main/assets
cp app.zip ${{ github.workspace }}/siyuan-android/app/src/main/assets/app.zip
diff --git a/app/electron-builder-arm64.yml b/app/electron-builder-arm64.yml
index 9c4e092941..6100259ffb 100644
--- a/app/electron-builder-arm64.yml
+++ b/app/electron-builder-arm64.yml
@@ -52,7 +52,7 @@ extraResources:
to: "changelogs"
- from: "stage"
to: "stage"
- filter: ["**/*", "!ocr/runtime/**/*", "!map/**/*", "!build/map/**/*"]
+ filter: ["**/*", "!ocr/runtime/**/*"]
- from: "stage/ocr/runtime/windows-arm64"
to: "stage/ocr/runtime/windows-arm64"
- from: "guide"
diff --git a/app/electron-builder-darwin-arm64.yml b/app/electron-builder-darwin-arm64.yml
index 1050c73495..59b207bcdb 100644
--- a/app/electron-builder-darwin-arm64.yml
+++ b/app/electron-builder-darwin-arm64.yml
@@ -46,7 +46,7 @@ extraResources:
to: "changelogs"
- from: "stage"
to: "stage"
- filter: ["**/*", "!ocr/runtime/**/*", "!map/**/*", "!build/map/**/*"]
+ filter: ["**/*", "!ocr/runtime/**/*"]
- from: "stage/ocr/runtime/darwin-arm64"
to: "stage/ocr/runtime/darwin-arm64"
- from: "guide"
diff --git a/app/electron-builder-darwin.yml b/app/electron-builder-darwin.yml
index 34634229b5..49fec92250 100644
--- a/app/electron-builder-darwin.yml
+++ b/app/electron-builder-darwin.yml
@@ -46,7 +46,7 @@ extraResources:
to: "changelogs"
- from: "stage"
to: "stage"
- filter: ["**/*", "!ocr/runtime/**/*", "!map/**/*", "!build/map/**/*"]
+ filter: ["**/*", "!ocr/runtime/**/*"]
- from: "stage/ocr/runtime/darwin-amd64"
to: "stage/ocr/runtime/darwin-amd64"
- from: "guide"
diff --git a/app/electron-builder-linux-arm64.yml b/app/electron-builder-linux-arm64.yml
index 3f0b043066..9ce97a550a 100644
--- a/app/electron-builder-linux-arm64.yml
+++ b/app/electron-builder-linux-arm64.yml
@@ -55,7 +55,7 @@ extraResources:
to: "changelogs"
- from: "stage"
to: "stage"
- filter: ["**/*", "!ocr/runtime/**/*", "!map/**/*", "!build/map/**/*"]
+ filter: ["**/*", "!ocr/runtime/**/*"]
- from: "stage/ocr/runtime/linux-arm64"
to: "stage/ocr/runtime/linux-arm64"
- from: "guide"
diff --git a/app/electron-builder-linux.yml b/app/electron-builder-linux.yml
index 82e0e97dea..9fb331d17b 100644
--- a/app/electron-builder-linux.yml
+++ b/app/electron-builder-linux.yml
@@ -52,7 +52,7 @@ extraResources:
to: "changelogs"
- from: "stage"
to: "stage"
- filter: ["**/*", "!ocr/runtime/**/*", "!map/**/*", "!build/map/**/*"]
+ filter: ["**/*", "!ocr/runtime/**/*"]
- from: "stage/ocr/runtime/linux-amd64"
to: "stage/ocr/runtime/linux-amd64"
- from: "guide"
diff --git a/app/electron-builder.yml b/app/electron-builder.yml
index ad5440f794..eed41b0ed4 100644
--- a/app/electron-builder.yml
+++ b/app/electron-builder.yml
@@ -51,7 +51,7 @@ extraResources:
to: "changelogs"
- from: "stage"
to: "stage"
- filter: ["**/*", "!ocr/runtime/**/*", "!map/**/*", "!build/map/**/*"]
+ filter: ["**/*", "!ocr/runtime/**/*"]
- from: "stage/ocr/runtime/windows-amd64"
to: "stage/ocr/runtime/windows-amd64"
- from: "guide"
diff --git a/app/package.json b/app/package.json
index 42412be172..c791a0fbd1 100644
--- a/app/package.json
+++ b/app/package.json
@@ -19,7 +19,7 @@
"dev:mobile": "webpack --mode development --config webpack.mobile.js",
"dev:desktop": "webpack --mode development --config webpack.desktop.js",
"dev:export": "webpack --mode development --config webpack.export.js",
- "build": "pnpm run /build:.*/",
+ "build": "node scripts/clean-stage.mjs && pnpm run /build:.*/",
"build:app": "webpack --mode production --config webpack.config.js",
"build:mobile": "webpack --mode production --config webpack.mobile.js",
"build:desktop": "webpack --mode production --config webpack.desktop.js",
diff --git a/app/scripts/clean-stage.mjs b/app/scripts/clean-stage.mjs
new file mode 100644
index 0000000000..f82c40994c
--- /dev/null
+++ b/app/scripts/clean-stage.mjs
@@ -0,0 +1,29 @@
+import fs from "node:fs";
+import path from "node:path";
+import {fileURLToPath} from "node:url";
+
+export const appRoot = fileURLToPath(new URL("../", import.meta.url));
+
+// 整体重建构建输出目录,避免已移除的构建配置留下无人清理的孤儿产物。
+// 只处理 git 忽略的 stage/build;stage 下被跟踪的源码目录不在此处清理。
+export const cleanStageBuild = (buildDir) => {
+ let info;
+ try {
+ info = fs.lstatSync(buildDir);
+ } catch (error) {
+ if (error.code === "ENOENT") {
+ return false;
+ }
+ throw error;
+ }
+ // 符号链接和目录联接不递归删除,避免删除链接指向的其他目录。
+ if (info.isSymbolicLink()) {
+ return false;
+ }
+ fs.rmSync(buildDir, {recursive: true, force: true});
+ return true;
+};
+
+if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ cleanStageBuild(path.join(appRoot, "stage", "build"));
+}
diff --git a/app/scripts/clean-stage.test.js b/app/scripts/clean-stage.test.js
new file mode 100644
index 0000000000..86c5931a5a
--- /dev/null
+++ b/app/scripts/clean-stage.test.js
@@ -0,0 +1,51 @@
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const os = require("node:os");
+const path = require("node:path");
+const test = require("node:test");
+
+test("the aggregate build cleans generated bundles before rebuilding", () => {
+ const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
+ assert.equal(pkg.scripts["clean:stage"], undefined);
+ assert.match(pkg.scripts.build, /^node scripts\/clean-stage\.mjs && /);
+});
+
+test("cleanStageBuild removes the whole output tree and ignores a missing directory", async () => {
+ const {cleanStageBuild} = await import("./clean-stage.mjs");
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-clean-stage-"));
+ try {
+ const buildDir = path.join(root, "stage", "build");
+ fs.mkdirSync(path.join(buildDir, "map"), {recursive: true});
+ fs.writeFileSync(path.join(buildDir, "map", "maplibre-gl.js"), "stale");
+ fs.mkdirSync(path.join(buildDir, "app"), {recursive: true});
+ fs.writeFileSync(path.join(buildDir, "app", "index.html"), "bundle");
+
+ assert.equal(cleanStageBuild(buildDir), true);
+ assert.equal(fs.existsSync(buildDir), false);
+ assert.equal(cleanStageBuild(buildDir), false);
+ } finally {
+ fs.rmSync(root, {recursive: true, force: true});
+ }
+});
+
+test("cleanStageBuild preserves a linked directory", async (t) => {
+ const {cleanStageBuild} = await import("./clean-stage.mjs");
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "siyuan-clean-stage-"));
+ try {
+ const target = path.join(root, "target");
+ fs.mkdirSync(target, {recursive: true});
+ fs.writeFileSync(path.join(target, "keep.txt"), "keep");
+ const link = path.join(root, "linked");
+ try {
+ fs.symlinkSync(target, link, "junction");
+ } catch (error) {
+ t.skip("symlink unavailable: " + error.message);
+ return;
+ }
+
+ assert.equal(cleanStageBuild(link), false);
+ assert.equal(fs.readFileSync(path.join(target, "keep.txt"), "utf8"), "keep");
+ } finally {
+ fs.rmSync(root, {recursive: true, force: true});
+ }
+});
diff --git a/app/tests/retiredMapAssets.test.js b/app/tests/retiredMapAssets.test.js
index adaecfc587..6ac0ff5c52 100644
--- a/app/tests/retiredMapAssets.test.js
+++ b/app/tests/retiredMapAssets.test.js
@@ -18,28 +18,26 @@ test("frontend scripts and dependencies no longer build or include the map SDK",
}
});
-test("all desktop packages exclude stale map sources and generated output", () => {
+test("desktop packages filter the OCR runtime out of the shipped stage folder", () => {
const configs = fs.readdirSync(app).filter(name => /^electron-builder(?:-[\w-]+)?\.yml$/.test(name));
assert.equal(configs.length, 6);
for (const name of configs) {
const stage = read(name).match(/from: "stage"\s+to: "stage"\s+filter: (\[[^\n]+\])/);
assert.ok(stage, name);
- const filters = JSON.parse(stage[1]);
- assert.ok(filters.includes("**/*"), name);
- for (const excluded of ["!map/**/*", "!build/map/**/*", "!ocr/runtime/**/*"]) {
- assert.ok(filters.includes(excluded), name + ": " + excluded);
- }
+ // 精确匹配:已撤回的地图产物不应再出现在打包过滤项里
+ assert.deepEqual(JSON.parse(stage[1]), ["**/*", "!ocr/runtime/**/*"], name);
}
});
-test("Docker and mobile packaging exclude stale map resources", () => {
- const docker = read("../.dockerignore").trim().split(/\r?\n/);
- assert.ok(docker.includes("app/stage/map"));
- assert.ok(docker.includes("app/stage/build/map"));
- const android = read("../scripts/android-dev-run.mjs");
+test("no packaging path special-cases the withdrawn map output", () => {
+ // 已撤回产物由内核启动清理负责;打包路径不应再枚举它们。
+ assert.doesNotMatch(read("../scripts/android-dev-run.mjs"), /stage\/build\/map/);
+ assert.doesNotMatch(read("../scripts/build-release.py"), /"build", "map"/);
+});
+
+test("the release pipeline rebuilds generated bundles instead of enumerating stale map output", () => {
const ci = read("../.github/workflows/cd.yml");
- for (const root of ["stage/map", "stage/build/map"]) {
- assert.ok(android.includes('"--exclude=' + root + '"'));
- assert.ok(ci.includes("'" + root + "/*'"));
- }
+ // 移动端 app.zip 前的聚合构建会先清理 stage/build,因此无需再逐个排除已撤回的地图产物。
+ assert.match(ci, /run: pnpm run build\s*\n/);
+ assert.doesNotMatch(ci, /stage\/build\/map/);
});
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 3ff4228097..d655223de8 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -272,6 +272,9 @@ func InitConf() {
}
clearEncryptedExportTempOnBoot()
clearOldInstallPackages("")
+ if err := CleanupRetiredInstallResources(); err != nil {
+ logging.LogWarnf("clean up retired install resources failed: %s", err)
+ }
confPath := filepath.Join(util.ConfDir, "conf.json")
confFileExists := gulu.File.IsExist(confPath)
var confData []byte
@@ -419,26 +422,6 @@ func InitConf() {
}
Conf.Appearance.Load().Lang = Conf.Lang
- // 历史下划线命名的 i18n 文件(zh_CN.json 等)已重命名为 BCP 47(zh-CN.json 等),
- // 清理 ConfDir/appearance/langs/ 下的旧名残留,避免僵尸文件。
- if langsDir := filepath.Join(util.AppearancePath, "langs"); gulu.File.IsDir(langsDir) {
- if entries, err := os.ReadDir(langsDir); err == nil {
- for _, entry := range entries {
- name := entry.Name()
- if entry.IsDir() || !strings.HasSuffix(name, ".json") {
- continue
- }
- stem := strings.TrimSuffix(name, ".json")
- if _, ok := util.LangLegacyToBCP47[stem]; !ok {
- continue
- }
- os.RemoveAll(filepath.Join(langsDir, name))
- }
- }
- }
- os.RemoveAll(filepath.Join(util.AppearancePath, "icons", "ant"))
- os.RemoveAll(filepath.Join(util.AppearancePath, "icons", "material"))
-
util.CurrentCloudRegion = Conf.CloudRegion
if !isNewWorkspace {
diff --git a/kernel/model/legacy_resources.go b/kernel/model/legacy_resources.go
new file mode 100644
index 0000000000..81ac337e4a
--- /dev/null
+++ b/kernel/model/legacy_resources.go
@@ -0,0 +1,61 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+package model
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/88250/gulu"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+// retiredInstallResourcePaths 返回升级后仍可能残留在磁盘上的已撤回安装资源。
+// 安装包与本机外观目录只增不删,历史版本的文件不会随升级自动消失,因此集中在此处统一清理。
+// 历史字体不在此列:它需要确认替代字体已经可用,由 InitAppearance 在资源复制完成后处理。
+func retiredInstallResourcePaths() []string {
+ return []string{
+ filepath.Join(util.WorkingDir, "stage", "map"), // 已撤回的数据库地图视图静态页面
+ filepath.Join(util.WorkingDir, "stage", "build", "map"), // 地图视图的构建产物
+ filepath.Join(util.AppearancePath, "icons", "ant"), // 已撤回的内置图标集
+ filepath.Join(util.AppearancePath, "icons", "material"),
+ }
+}
+
+// CleanupRetiredInstallResources 删除升级后残留的已撤回安装资源,随启动阶段执行。
+// 这些路径都由安装包管理、不存放用户数据,直接删除目录;目录缺失时忽略。
+func CleanupRetiredInstallResources() error {
+ for _, p := range retiredInstallResourcePaths() {
+ if err := os.RemoveAll(p); err != nil {
+ return err
+ }
+ }
+ cleanLegacyLangFiles()
+ return nil
+}
+
+// cleanLegacyLangFiles 清理外观目录下下划线命名的历史 i18n 文件(zh_CN.json 等)。
+// 这些文件名已在 BCP 47 命名(zh-CN.json 等)迁移后失效,继续存在只会成为僵尸文件。
+func cleanLegacyLangFiles() {
+ langsDir := filepath.Join(util.AppearancePath, "langs")
+ if !gulu.File.IsDir(langsDir) {
+ return
+ }
+ entries, err := os.ReadDir(langsDir)
+ if err != nil {
+ return
+ }
+ for _, entry := range entries {
+ name := entry.Name()
+ if entry.IsDir() || !strings.HasSuffix(name, ".json") {
+ continue
+ }
+ if _, ok := util.LangLegacyToBCP47[strings.TrimSuffix(name, ".json")]; !ok {
+ continue
+ }
+ os.RemoveAll(filepath.Join(langsDir, name))
+ }
+}
diff --git a/kernel/model/legacy_resources_test.go b/kernel/model/legacy_resources_test.go
new file mode 100644
index 0000000000..f4d1cb2350
--- /dev/null
+++ b/kernel/model/legacy_resources_test.go
@@ -0,0 +1,103 @@
+// SiYuan - From thought to insight, with agents
+// Copyright (c) 2020-present, b3log.org
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+package model
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+func TestCleanupRetiredInstallResources(t *testing.T) {
+ workingDir, appearancePath := t.TempDir(), t.TempDir()
+ previousWorkingDir, previousAppearancePath := util.WorkingDir, util.AppearancePath
+ util.WorkingDir, util.AppearancePath = workingDir, appearancePath
+ t.Cleanup(func() {
+ util.WorkingDir, util.AppearancePath = previousWorkingDir, previousAppearancePath
+ })
+
+ // 已撤回资源与同层仍在使用的资源
+ retired := []string{
+ filepath.Join(workingDir, "stage", "map", "index.html"),
+ filepath.Join(workingDir, "stage", "build", "map", "maplibre-gl.js"),
+ filepath.Join(appearancePath, "icons", "ant", "icon.js"),
+ filepath.Join(appearancePath, "icons", "material", "icon.js"),
+ filepath.Join(appearancePath, "langs", "zh_CN.json"),
+ }
+ kept := []string{
+ filepath.Join(workingDir, "stage", "build", "desktop", "index.js"),
+ filepath.Join(workingDir, "stage", "map-icons", "pin.svg"),
+ filepath.Join(appearancePath, "icons", "litheness", "icon.js"),
+ filepath.Join(appearancePath, "langs", "zh-CN.json"),
+ // 历史字体要求替代字体可用,由 InitAppearance 在资源复制后单独处理,不在本函数职责内
+ filepath.Join(appearancePath, "fonts", "JetBrainsMono-1.0.3", "JetBrainsMono-Regular.woff"),
+ }
+ for _, p := range append(append([]string{}, retired...), kept...) {
+ if err := os.MkdirAll(filepath.Dir(p), 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(p, []byte("fixture"), 0644); err != nil {
+ t.Fatal(err)
+ }
+ }
+
+ if err := CleanupRetiredInstallResources(); err != nil {
+ t.Fatal(err)
+ }
+
+ for _, p := range retired {
+ if _, err := os.Lstat(p); !os.IsNotExist(err) {
+ t.Fatalf("retired resource remains: %s", p)
+ }
+ }
+ for _, p := range kept {
+ if _, err := os.Stat(p); err != nil {
+ t.Fatalf("ordinary resource removed: %s", p)
+ }
+ }
+ // 目录已不存在时重复执行不报错
+ if err := CleanupRetiredInstallResources(); err != nil {
+ t.Fatal("retry", err)
+ }
+}
+
+func TestCleanupRetiredInstallResourcesMissingDirsAndLinks(t *testing.T) {
+ workingDir, appearancePath := t.TempDir(), t.TempDir()
+ previousWorkingDir, previousAppearancePath := util.WorkingDir, util.AppearancePath
+ util.WorkingDir, util.AppearancePath = workingDir, appearancePath
+ t.Cleanup(func() {
+ util.WorkingDir, util.AppearancePath = previousWorkingDir, previousAppearancePath
+ })
+
+ // 安装目录不含已撤回资源时直接返回
+ if err := CleanupRetiredInstallResources(); err != nil {
+ t.Fatal(err)
+ }
+
+ outside := t.TempDir()
+ if err := os.WriteFile(filepath.Join(outside, "private"), []byte("private"), 0644); err != nil {
+ t.Fatal(err)
+ }
+ link := filepath.Join(appearancePath, "icons", "ant")
+ if err := os.MkdirAll(filepath.Dir(link), 0755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink(outside, link); err != nil {
+ t.Skipf("symlink unavailable: %v", err)
+ }
+
+ if err := CleanupRetiredInstallResources(); err != nil {
+ t.Fatal(err)
+ }
+ // 只删除链接本身,链接指向的目录内容保持原样
+ if _, err := os.Lstat(link); !os.IsNotExist(err) {
+ t.Fatalf("link remains: %v", err)
+ }
+ if data, err := os.ReadFile(filepath.Join(outside, "private")); err != nil || string(data) != "private" {
+ t.Fatalf("changed linked content: %v", err)
+ }
+}
diff --git a/kernel/server/retired_static_resources.go b/kernel/server/retired_static_resources.go
deleted file mode 100644
index 45268de8a2..0000000000
--- a/kernel/server/retired_static_resources.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// SiYuan - From thought to insight, with agents
-// Copyright (c) 2020-present, b3log.org
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-package server
-
-import (
- "net/http"
- "path"
- "strings"
-
- "github.com/gin-gonic/gin"
-)
-
-func retiredStaticResourcesMiddleware() gin.HandlerFunc {
- return func(c *gin.Context) {
- // 升级后磁盘上可能仍有旧地图产物,禁止通过通用静态路由及文件系统路径别名访问。
- parts := strings.Split(strings.ReplaceAll(c.Request.URL.Path, "\\", "/"), "/")
- for i, part := range parts {
- part = strings.TrimRight(part, " ")
- if part != "." && part != ".." {
- part = strings.TrimRight(part, ". ")
- }
- parts[i] = part
- }
- requestPath := strings.ToLower(path.Clean(strings.Join(parts, "/")))
- if requestPath == "/stage/map" || strings.HasPrefix(requestPath, "/stage/map/") ||
- requestPath == "/stage/build/map" || strings.HasPrefix(requestPath, "/stage/build/map/") {
- c.AbortWithStatus(http.StatusNotFound)
- return
- }
- c.Next()
- }
-}
diff --git a/kernel/server/retired_static_resources_test.go b/kernel/server/retired_static_resources_test.go
deleted file mode 100644
index c5c6257e62..0000000000
--- a/kernel/server/retired_static_resources_test.go
+++ /dev/null
@@ -1,72 +0,0 @@
-// SiYuan - From thought to insight, with agents
-// Copyright (c) 2020-present, b3log.org
-// SPDX-License-Identifier: AGPL-3.0-or-later
-
-package server
-
-import (
- "net/http"
- "net/http/httptest"
- "os"
- "path/filepath"
- "testing"
-
- "github.com/gin-gonic/gin"
-)
-
-func TestRetiredMapResourcesUnavailableWithOldFilesOnDisk(t *testing.T) {
- root := t.TempDir()
- for _, name := range []string{"map/index.html", "map/wrapper.html", "map/host.css",
- "build/map/host.js", "build/map/wrapper.js", "build/map/maplibre-gl.js",
- "build/map/maplibre-gl.css", "build/map/maplibre-gl-csp-worker.js",
- "build/desktop/index.js", "map-icons/pin.svg", "build/mapping.js", "plugins/example/asset.js"} {
- full := filepath.Join(root, filepath.FromSlash(name))
- if err := os.MkdirAll(filepath.Dir(full), 0700); err != nil {
- t.Fatal(err)
- }
- if err := os.WriteFile(full, []byte("fixture:"+name), 0600); err != nil {
- t.Fatal(err)
- }
- }
- router := gin.New()
- router.Use(retiredStaticResourcesMiddleware())
- router.Static("/stage", root)
- router.Static("/plugins", filepath.Join(root, "plugins"))
- router.GET("/api/conf", func(c *gin.Context) { c.String(http.StatusOK, "ordinary route") })
- for _, target := range []string{"/stage/map", "/stage/map/", "/stage/build/map", "/stage/build/map/",
- "/stage/map/index.html", "/stage/map/index.html?provider=openfreemap", "/stage/map/wrapper.html",
- "/stage/map/host.css", "/stage/build/map/host.js", "/stage/build/map/wrapper.js",
- "/stage/build/map/maplibre-gl.js", "/stage/build/map/maplibre-gl.css",
- "/stage/build/map/maplibre-gl-csp-worker.js", "/stage/map/private.json",
- "/stage/map%2findex.html", "/stage/Map/wrapper.html", "/stage/.%2fmap/index.html",
- "/stage/%2fmap/index.html", "/stage/anything/..%2fmap/index.html", "/stage/build/.%2fmap/host.js",
- "/stage/%5cmap%5cindex.html", "/stage/build/MAP/host.js", "/stage/map./index.html",
- "/stage/map%20/index.html", "/stage/build/map.%20/host.js", "/stage/%6dap/index.html"} {
- for _, method := range []string{http.MethodGet, http.MethodHead, http.MethodPost} {
- t.Run(method+" "+target, func(t *testing.T) {
- response := httptest.NewRecorder()
- router.ServeHTTP(response, httptest.NewRequest(method, target, nil))
- if response.Code != http.StatusNotFound || response.Body.Len() != 0 {
- t.Fatalf("retired resource served: status=%d body=%q", response.Code, response.Body.String())
- }
- })
- }
- }
- for _, target := range []string{"build/desktop/index.js", "map-icons/pin.svg", "build/mapping.js"} {
- response := httptest.NewRecorder()
- router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/stage/"+target, nil))
- if response.Code != http.StatusOK || response.Body.String() != "fixture:"+target {
- t.Fatalf("ordinary static resource changed: %s status=%d", target, response.Code)
- }
- }
- response := httptest.NewRecorder()
- router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/plugins/example/asset.js", nil))
- if response.Code != http.StatusOK || response.Body.String() != "fixture:plugins/example/asset.js" {
- t.Fatal("ordinary plugin resource changed")
- }
- response = httptest.NewRecorder()
- router.ServeHTTP(response, httptest.NewRequest(http.MethodGet, "/api/conf", nil))
- if response.Code != http.StatusOK || response.Body.String() != "ordinary route" {
- t.Fatal("ordinary API route changed")
- }
-}
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index 6696ddcb55..ee23738ca4 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -172,7 +172,6 @@ func Serve(fastMode bool, cookieKey string) {
// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-hpj5-f7cj-vvwr
ginServer.Use(tlsEnforceMiddleware())
ginServer.Use(sessions.Sessions("siyuan", sessionStore))
- ginServer.Use(retiredStaticResourcesMiddleware())
serveDebug(ginServer)
serveAssets(ginServer)
diff --git a/scripts/android-dev-run.mjs b/scripts/android-dev-run.mjs
index 13f3fec379..ab63e40f8c 100644
--- a/scripts/android-dev-run.mjs
+++ b/scripts/android-dev-run.mjs
@@ -236,7 +236,7 @@ const zipPath = path.join(os.tmpdir(), "siyuan-android-app.zip");
if (existsSync(zipPath)) {
unlinkSync(zipPath);
}
-const tarArgs = ["-a", "-cf", zipPath, "--exclude=stage/map", "--exclude=stage/build/map",
+const tarArgs = ["-a", "-cf", zipPath,
"-C", appDir, "appearance", "guide", "stage"];
const changelogsDir = path.join(appDir, "changelogs");
if (existsSync(changelogsDir)) {
diff --git a/scripts/build-release.py b/scripts/build-release.py
index 3b34f9cb68..3e5c456197 100644
--- a/scripts/build-release.py
+++ b/scripts/build-release.py
@@ -343,8 +343,6 @@ def create_mobile_assets(destination, version):
continue
if relative.parts[:3] == ("stage", "ocr", "runtime"):
continue
- if relative.parts[:2] == ("stage", "map") or relative.parts[:3] == ("stage", "build", "map"):
- continue
archive.write(path, relative.as_posix())
for filename in ("LICENSE", "THIRD_PARTY_NOTICES.md"):
archive.write(ROOT / filename, filename)
diff --git a/scripts/test_build_release.py b/scripts/test_build_release.py
index 6d961f5c7a..bc934aa50f 100644
--- a/scripts/test_build_release.py
+++ b/scripts/test_build_release.py
@@ -53,11 +53,10 @@ class BuildTests(unittest.TestCase):
build.copy_verified(source, self.root / "outside", self.root / "allowed")
self.assertFalse((self.root / "outside").exists())
- def test_mobile_assets_exclude_retired_map_files(self):
+ def test_mobile_assets_exclude_ocr_runtime(self):
kept = {"stage/build/mobile/index.html", "stage/map-icons/pin.svg", "appearance/theme.css",
"guide/document.sy", "LICENSE", "THIRD_PARTY_NOTICES.md"}
- removed = {"stage/map/index.html", "stage/map/wrapper.html", "stage/build/map/host.js",
- "stage/build/map/maplibre-gl.js", "stage/ocr/runtime/library"}
+ removed = {"stage/ocr/runtime/library"}
for name in kept | removed:
self.write(self.root / (name if name in {"LICENSE", "THIRD_PARTY_NOTICES.md"} else "app/" + name))
destination = self.root / "mobile/app.zip"