Skip to content

Commit

Permalink
feat: add ysk function
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Aug 2, 2024
1 parent c2ad9f9 commit 55b3712
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 0 deletions.
165 changes: 165 additions & 0 deletions api/message_bus/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ tags:
- name: PropertyType
description: |-
<SchemaDefinition schemaRef="#/components/schemas/PropertyType" />
- name: YSK methods
description: |-
(TODO)
x-tagGroups:
- name: Methods
Expand Down Expand Up @@ -337,6 +342,37 @@ paths:
"200":
description: |
Polling continued from SocketIO
/ysk:
get:
description: |-
Get need display YSK card
operationId: getYskCard
tags:
- YSK methods
responses:
"200":
$ref: "#/components/responses/ResponseGetYSKCardListOK"
"500":
$ref: "#/components/responses/ResponseInternalServerError"
/ysk/{id}:
delete:
description: |-
Not display YSK card
operationId: deleteYskCard
tags:
- YSK methods
parameters:
- name: id
in: path
description: YSK card id
required: true
schema:
type: string
responses:
"200":
$ref: "#/components/responses/ResponseOK"
"500":
$ref: "#/components/responses/ResponseInternalServerError"

components:
securitySchemes:
Expand Down Expand Up @@ -528,6 +564,17 @@ components:
application/json:
schema:
$ref: "#/components/schemas/Action"

ResponseGetYSKCardListOK:
description: OK
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/BaseResponse"
- properties:
data:
$ref: "#/components/schemas/YSKCardList"

schemas:
BaseResponse:
Expand Down Expand Up @@ -668,3 +715,121 @@ components:
type: string
description: timestamp this action took place
format: date-time

YSKCardList:
type: array
items:
$ref: "#/components/schemas/YSKCard"

YSKCard:
type: object
# properties:
# id:
# type: string
# example: "1234567890"
# cardType:
# type: string
# enum:
# - "task"
# - "long-notice"
# - "short-notice"
# renderType:
# type: string
# enum:
# - "task"
# - "list-notice"
# - "icon-text-notice"
# - "markdown-notice"
# content:
# $ref: "#/components/schemas/YSKCardContent"
x-go-type: ysk.YSKCard
x-go-import:
name: ysk
path: github.com/IceWhaleTech/ZimaOS/ysk


YSKCardContent:
type: object
x-go-type: ysk.YSKCardContent
x-go-import:
name: ysk
path: github.com/IceWhaleTech/ZimaOS/ysk

# properties:
# titleIcon:
# $ref: "#/components/schemas/YSKCardIcon"
# titleText:
# type: string
# example: "CasaOS"
# bodyProgress:
# $ref: "#/components/schemas/YSKCardProgress"
# bodyIconWithText:
# $ref: "#/components/schemas/YSKCardIconWithText"
# bodyList:
# type: array
# items:
# $ref: "#/components/schemas/YSKCardListItem"
# footerActions:
# type: array
# items:
# $ref: "#/components/schemas/YSKCardFooterAction"

YSKCardProgress:
type: object
properties:
label:
type: string
example: "Installing jellyfin"
value:
type: integer
example: 50

YSKCardIconWithText:
type: object
properties:
icon:
$ref: "#/components/schemas/YSKCardIcon"
description:
type: string
example: "CasaOS"

YSKCardListItem:
type: object
properties:
icon:
$ref: "#/components/schemas/YSKCardIcon"
description:
type: string
example: "CasaOS"
rightText:
type: string
example: "4 TB"

YSKCardFooterAction:
type: object
properties:
side:
type: string
example: "View Details"
style:
type: string
example: "view-details"
text:
type: string
example: "https://casaos.com"
messageBus:
$ref: "#/components/schemas/YSKCardMessageBusAction"

YSKCardMessageBusAction:
type: object
properties:
key:
type: string
example: "open-url"
payload:
type: string
example: "https://casaos.com"

YSKCardIcon:
type: string
example: "https://raw.githubusercontent.com/IceWhaleTech/logo/main/casaos/casaos_banner_twilight_blue_800px.png"
82 changes: 82 additions & 0 deletions pkg/ysk/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package ysk

type CartType string

const (
CardTypeTask CartType = "task"
CardTypeLongNote CartType = "long-notice"
CardTypeShortNote CartType = "short-notice"
)

type RenderType string

const (
RenderTypeCardTask RenderType = "task"
RenderTypeCardListNotice RenderType = "list-notice"
RenderTypeCardIconTextNotice RenderType = "icon-text-notice"
RenderTypeCardMarkdownNotice RenderType = "markdown-notice"
)

type ActionPosition string

const (
ActionPositionLeft ActionPosition = "left"
ActionPositionRight ActionPosition = "right"
)

type YSKCard struct {
ID string
CardType CartType
RenderType RenderType
Content YSKCardContent
}

func (yskCard YSKCard) WithProgress(label string, progress int) YSKCard {
if yskCard.Content.BodyProgress != nil {
yskCard.Content.BodyProgress = &YSKCardProgress{
Label: label,
Value: progress,
}
return yskCard
}
return yskCard
}

type YSKCardContent struct {
TitleIcon string
TitleText string
BodyProgress *YSKCardProgress
BodyIconWithText *YSKCardIconWithText
BodyList []YSKCardListItem
FooterActions []YSKCardFooterAction
}

type YSKCardProgress struct {
Label string
Value int
}

type YSKCardIconWithText struct {
Icon string
Description string
}

type YSKCardListItem struct {
Icon string
Description string
RightText string
}

type YSKCardFooterAction struct {
Side ActionPosition
Style string
Text string
MessageBus YSKCardMessageBusAction
}

type YSKCardMessageBusAction struct {
Key string
Payload string
}

type YSKCardIcon = string
27 changes: 27 additions & 0 deletions pkg/ysk/ysk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package ysk

import (
"context"
"encoding/json"
)

const (
SERVICENAME = "ysk"
)

func DefineCard(ctx context.Context, cardID string) YSKCard {
return YSKCard{}
}

func NewYSKCard(ctx context.Context, YSKCard YSKCard, publish func(context.Context, string, string, map[string]string)) error {
// do something
yskCardBodyJSON, _ := json.Marshal(YSKCard)
publish(ctx, SERVICENAME, "ysk:card:create", map[string]string{"body": string(yskCardBodyJSON)})
return nil
}

func DeleteCard(ctx context.Context, cardID string, publish func(context.Context, string, string, map[string]string)) error {
// do something
publish(ctx, SERVICENAME, "ysk:card:delete", map[string]string{"body": string(``)})
return nil
}
33 changes: 33 additions & 0 deletions pkg/ysk/ysk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ysk_test

import (
"context"
"testing"

"github.com/IceWhaleTech/ZimaOS/pkg/ysk"
)

func TestUpdateProgress(t *testing.T) {
ApplicationInstallProgress := ysk.YSKCard{
ID: "task:application:install",
CardType: ysk.CardTypeTask,
RenderType: ysk.RenderTypeCardTask,
Content: ysk.YSKCardContent{
TitleIcon: "jellyfin logo",
TitleText: "APP Installing",
BodyProgress: &ysk.YSKCardProgress{},
BodyIconWithText: nil,
BodyList: nil,
FooterActions: nil,
},
}

ysk.NewYSKCard(context.Background(), ApplicationInstallProgress.WithProgress(
"Installing LinuxServer/Jellyfin",
50,
), nil)

ysk.DeleteCard(context.Background(), ApplicationInstallProgress.ID, nil)
}

func TestNoticeInUser

0 comments on commit 55b3712

Please sign in to comment.