feat: register all file capabilities as unsafe to jsmod

This commit is contained in:
AI Engineer 2026-05-30 18:55:50 +08:00
parent 1c0612ab08
commit 18e85b1ff1
4 changed files with 44 additions and 0 deletions

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
## [1.3.3] - 2026-05-30
- **新增**: 注册到 `jsmod`将所有文件操作方法Read/Write/Archive 等注册为高危方法unsafeList确保安全沙箱隔离。
## [1.0.7] - 2026-05-06 ## [1.0.7] - 2026-05-06
- **设计哲学对齐**:全面废除 `Must` 前缀函数(`MustRead`, `MustReadBytes`, `MustReadLines`, `MustReadDir`, `MustGzip`, `MustGunzip`, `MustZip`, `MustUnzip`),改为配合 `go/cast``As` 函数消除摩擦。 - **设计哲学对齐**:全面废除 `Must` 前缀函数(`MustRead`, `MustReadBytes`, `MustReadLines`, `MustReadDir`, `MustGzip`, `MustGunzip`, `MustZip`, `MustUnzip`),改为配合 `go/cast``As` 函数消除摩擦。
- **内部优化**:重构 `memory.go` 以移除对废弃 `Must` 函数的内部依赖。 - **内部优化**:重构 `memory.go` 以移除对废弃 `Must` 函数的内部依赖。

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.25.0
require ( require (
apigo.cc/go/cast v1.3.3 apigo.cc/go/cast v1.3.3
apigo.cc/go/encoding v1.3.1 apigo.cc/go/encoding v1.3.1
apigo.cc/go/jsmod v1.0.0
apigo.cc/go/safe v1.3.1 apigo.cc/go/safe v1.3.1
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )

2
go.sum
View File

@ -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/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 h1:y8O58KYAyulkThg1O2ji2BqjnFoSvk42sit9I3z+K7Y=
apigo.cc/go/encoding v1.3.1/go.mod h1:xAJk5b83VZ31mXMTnyp0dfMoBKfT/AHDn0u+cQfojgY= 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 h1:7FvsI6PtQ5XrWER0dTiLVo0p7GIxRidT/TBKhVy93j8=
apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk= apigo.cc/go/rand v1.3.1/go.mod h1:mZ/4Soa3bk+XvDaqPWJuUe1bfEi4eThBj1XmEAuYxsk=
apigo.cc/go/safe v1.3.1 h1:irTCqPAC97gGsX/Lw5AzLelDt1xXLEZIAaVhLELWe9Q= apigo.cc/go/safe v1.3.1 h1:irTCqPAC97gGsX/Lw5AzLelDt1xXLEZIAaVhLELWe9Q=

38
js_export.go Normal file
View File

@ -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",
)
}