From 18e85b1ff1b21ffd9de6624ceb3bfa52d9992dfb Mon Sep 17 00:00:00 2001 From: AI Engineer Date: Sat, 30 May 2026 18:55:50 +0800 Subject: [PATCH] feat: register all file capabilities as unsafe to jsmod --- CHANGELOG.md | 3 +++ go.mod | 1 + go.sum | 2 ++ js_export.go | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+) create mode 100644 js_export.go diff --git a/CHANGELOG.md b/CHANGELOG.md index d648984..9fd10ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [1.3.3] - 2026-05-30 +- **新增**: 注册到 `jsmod`,将所有文件操作方法(Read/Write/Archive 等)注册为高危方法(unsafeList),确保安全沙箱隔离。 + ## [1.0.7] - 2026-05-06 - **设计哲学对齐**:全面废除 `Must` 前缀函数(`MustRead`, `MustReadBytes`, `MustReadLines`, `MustReadDir`, `MustGzip`, `MustGunzip`, `MustZip`, `MustUnzip`),改为配合 `go/cast` 的 `As` 函数消除摩擦。 - **内部优化**:重构 `memory.go` 以移除对废弃 `Must` 函数的内部依赖。 diff --git a/go.mod b/go.mod index 5a55f2f..21adc6c 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.25.0 require ( apigo.cc/go/cast v1.3.3 apigo.cc/go/encoding v1.3.1 + apigo.cc/go/jsmod v1.0.0 apigo.cc/go/safe v1.3.1 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index cdb28fe..add22a9 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ apigo.cc/go/cast v1.3.3 h1:aln5eDR5DZVWVzZ/y5SJh1gQNgWv2sT82I25NaO9g34= apigo.cc/go/cast v1.3.3/go.mod h1:lGlwImiOvHxG7buyMWhFzcdvQzmSaoKbmr7bcDfUpHk= apigo.cc/go/encoding v1.3.1 h1:y8O58KYAyulkThg1O2ji2BqjnFoSvk42sit9I3z+K7Y= apigo.cc/go/encoding v1.3.1/go.mod h1:xAJk5b83VZ31mXMTnyp0dfMoBKfT/AHDn0u+cQfojgY= +apigo.cc/go/jsmod v1.0.0 h1:lVQMq0tCno4kbHlQ3j5wzsm+v24J+bznIoHxpton0pE= +apigo.cc/go/jsmod v1.0.0/go.mod h1:bmyeZtOAP/j5am+YRnaiM89smysK24K7ebk0koFtsSw= apigo.cc/go/rand v1.3.1 h1:7FvsI6PtQ5XrWER0dTiLVo0p7GIxRidT/TBKhVy93j8= apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk= apigo.cc/go/safe v1.3.1 h1:irTCqPAC97gGsX/Lw5AzLelDt1xXLEZIAaVhLELWe9Q= diff --git a/js_export.go b/js_export.go new file mode 100644 index 0000000..e8cda83 --- /dev/null +++ b/js_export.go @@ -0,0 +1,38 @@ +package file + +import "apigo.cc/go/jsmod" + +func init() { + jsmod.Register("file", map[string]any{ + "exists": Exists, + "read": Read, + "readBytes": ReadBytes, + "readLines": ReadLines, + "readDir": ReadDir, + "getFileInfo": GetFileInfo, + "getAbsFilename": GetAbsFilename, + "write": Write, + "writeBytes": WriteBytes, + "remove": Remove, + "mkdir": Mkdir, + "copy": Copy, + "move": Move, + "replace": Replace, + "unmarshalFile": UnmarshalFile, + "marshalFile": MarshalFile, + "marshalFilePretty": MarshalFilePretty, + "patchFile": PatchFile, + "archive": Archive, + "extract": Extract, + "compress": Compress, + "decompress": Decompress, + "readFileFromMemory": ReadFileFromMemory, + "readDirFromMemory": ReadDirFromMemory, + }, + "exists", "read", "readBytes", "readLines", "readDir", "getFileInfo", "getAbsFilename", + "write", "writeBytes", "remove", "mkdir", "copy", "move", "replace", + "unmarshalFile", "marshalFile", "marshalFilePretty", "patchFile", + "archive", "extract", "compress", "decompress", + "readFileFromMemory", "readDirFromMemory", + ) +}