Skip to content

Commit

Permalink
Merge pull request #859 from Hi-Windom/v0.35
Browse files Browse the repository at this point in the history
V0.35
  • Loading branch information
Soltus authored Jul 7, 2024
2 parents b566355 + e067e9c commit 673a2a2
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions .vscode/PackageJsonMapping.sillot.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"a:\\Github\\Hi-Windom\\Sillot\\docs\\starlight\\package.json",
"a:\\Github\\Hi-Windom\\Sillot\\package.json",
"a:\\Github\\Hi-Windom\\winsaybuilder\\package\\package.json",
"a:\\Github\\Hi-Windom\\Sillot-android\\package.json",
],
}
2 changes: 1 addition & 1 deletion .vscode/extensions/Sillot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sillot",
"displayName": "汐洛 Sillot",
"description": "汐洛彖夲肜矩阵(Sillot T☳Converbenk Matrix)为智慧新彖务服务。此插件为汐洛官方插件,提供多功能一体化集成。",
"version": "0.35.24070622",
"version": "0.35.24070801",
"preview": true,
"repository": "https://github.com/Hi-Windom/Sillot",
"publisher": "Hi-Windom",
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sillot",
"version": "0.35.24070622",
"version": "0.35.24070801",
"syv": "3.1.0",
"sypv": "[3.0.16, 3.0.17]",
"description": "Build Your Eternal Digital Garden",
Expand Down
2 changes: 1 addition & 1 deletion app/src/types/protyle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ declare class Lute {

public SetFootnotes(enable: boolean): void;

public SetLinkRef(enalbe: boolean): void;
public SetLinkRef(enable: boolean): void;

public SetEmojiSite(emojiSite: string): void;

Expand Down
2 changes: 1 addition & 1 deletion docs/starlight/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "starlight",
"type": "module",
"version": "0.35.24070622",
"version": "0.35.24070801",
"scripts": {
"test": "echo 'Test your sister day by day'",
"dev": "astro dev",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
title: 序列化
---
## kotlin compose中使用@Serializable好还是@Parcelize好

在Kotlin的Compose框架中,数据序列化是一个重要的方面,尤其是在处理UI状态、持久化或跨组件传递数据时。`@Serializable`和 `@Parcelize`是两种常用的注解,用于实现数据序列化,但它们的使用场景和优势各不相同。
`@Serializable`是Kotlin标准库的一部分,它允许你轻松地将数据类对象转换为JSON格式,反之亦然。这对于网络请求、本地存储和与其他系统交换数据非常有用。`@Serializable`注解通过Kotlin的序列化库支持,可以处理复杂的数据结构和嵌套类,同时提供了灵活的定制选项,比如自定义序列化器和忽略某些属性。
另一方面,`@Parcelize`是Android KTX库的一部分,专为Android开发设计,用于实现Parcelable接口。Parcelable是一种高效的序列化机制,专门用于Android中的跨进程通信(IPC)。它比Serializable更快,因为它直接将数据序列化为字节流,适合在Android组件之间传递数据,如Intent和Bundle。
在决定使用哪个注解时,应考虑以下几点:

1. **性能需求**:如果你需要高效的跨进程通信,尤其是在Android应用中,`@Parcelize`可能是更好的选择。
2. **数据交换格式**:如果你需要将数据序列化为JSON或其他格式,或者需要与不支持Parcelable的系统交换数据,`@Serializable`更适合。
3. **平台兼容性**:`@Serializable`可以在任何支持Kotlin的平台中使用,而 `@Parcelize`仅限于Android。
4. **复杂性和灵活性**:如果你的数据结构复杂,需要更多的定制和灵活性,`@Serializable`提供了更多的选项。
在实际应用中,你可能需要根据具体情况选择最合适的注解。例如,对于Compose中的状态管理,如果状态对象需要在Compose组件之间传递,并且需要跨进程传递,那么 `@Parcelize`可能是更好的选择。如果状态对象需要被持久化到本地存储,或者通过网络传输,那么 `@Serializable`可能更合适。
总之,没有绝对的“好”与“坏”,应根据具体需求和应用场景来选择最合适的序列化方式。


由于 `@Parcelize`依赖于Android的Parcelable机制,它不适用于Kotlin的多平台项目,这些项目可能会针对除了Android之外的其他平台,如JVM、iOS、Linux等。在Kotlin的多平台项目中使用Compose时,如果您需要序列化数据,应该使用 `@Serializable`注解。`@Serializable`是Kotlin的跨平台序列化机制的一部分,它允许您在不同的平台之间轻松地序列化和反序列化数据。这意味着您可以在多平台项目中使用 `@Serializable`来序列化Compose中的状态对象,而不用担心平台兼容性问题。
4 changes: 2 additions & 2 deletions kernel/api/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/sync/listCloudSyncDir", model.CheckAuth, model.CheckAdminRole, listCloudSyncDir)
ginServer.Handle("POST", "/api/sync/performSync", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, performSync)
ginServer.Handle("POST", "/api/sync/performBootSync", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, performBootSync)
ginServer.Handle("POST", "/api/sync/getBootSync", model.CheckAuth, model.CheckAdminRole, getBootSync)
ginServer.Handle("POST", "/api/sync/getBootSync", model.CheckAuth, getBootSync)
ginServer.Handle("POST", "/api/sync/getSyncInfo", model.CheckAuth, model.CheckAdminRole, getSyncInfo)
ginServer.Handle("POST", "/api/sync/exportSyncProviderS3", model.CheckAuth, model.CheckAdminRole, exportSyncProviderS3)
ginServer.Handle("POST", "/api/sync/importSyncProviderS3", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, importSyncProviderS3)
Expand Down Expand Up @@ -326,7 +326,7 @@ func ServeAPI(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/setting/setSearch", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSearch)
ginServer.Handle("POST", "/api/setting/setKeymap", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setKeymap)
ginServer.Handle("POST", "/api/setting/setAppearance", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setAppearance)
ginServer.Handle("POST", "/api/setting/getCloudUser", model.CheckAuth, model.CheckAdminRole, getCloudUser)
ginServer.Handle("POST", "/api/setting/getCloudUser", model.CheckAuth, getCloudUser)
ginServer.Handle("POST", "/api/setting/logoutCloudUser", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, logoutCloudUser)
ginServer.Handle("POST", "/api/setting/login2faCloudUser", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, login2faCloudUser)
ginServer.Handle("POST", "/api/setting/setEmoji", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setEmoji)
Expand Down
4 changes: 4 additions & 0 deletions kernel/api/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,10 @@ func getCloudUser(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

if !model.IsAdminRoleContext(c) {
return
}

arg, ok := util.JsonArg(c, ret)
if !ok {
return
Expand Down
4 changes: 4 additions & 0 deletions kernel/api/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,10 @@ func getBootSync(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)

if !model.IsAdminRoleContext(c) {
return
}

if model.Conf.Sync.Enabled && 1 == model.BootSyncSucc {
ret.Code = 1
ret.Msg = model.Conf.Language(17)
Expand Down
4 changes: 4 additions & 0 deletions kernel/model/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ func GetGinContextRole(c *gin.Context) Role {
return RoleVisitor
}
}

func IsAdminRoleContext(c *gin.Context) bool {
return GetGinContextRole(c) == RoleAdministrator
}
4 changes: 1 addition & 3 deletions kernel/model/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ func CheckAuth(c *gin.Context) {
}

func CheckAdminRole(c *gin.Context) {
if IsValidRole(GetGinContextRole(c), []Role{
RoleAdministrator,
}) {
if IsAdminRoleContext(c) {
c.Next()
} else {
c.AbortWithStatus(http.StatusForbidden)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Sillot-workspace",
"version": "0.35.24070622",
"version": "0.35.24070801",
"description": "汐洛 pnpm 工作区",
"packageManager": "[email protected]",
"scripts": {
Expand Down

0 comments on commit 673a2a2

Please sign in to comment.