Skip to content

Commit

Permalink
Add subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
Finb committed Dec 11, 2024
1 parent 0d72079 commit 5ed7573
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 26 deletions.
5 changes: 3 additions & 2 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ vars:
sh: date "+%F %T"
COMMIT_ID:
sh: git rev-parse HEAD
DOCKER_SOCK: /var/run/docker.sock

tasks:
clean:
Expand Down Expand Up @@ -227,9 +228,9 @@ tasks:
vars:
PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
cmds:
- docker run -dt --name dind -v {{.DOCKER_SOCK}}:/var/run/docker.sock -v $(pwd):/bark-server docker
- docker run -dt --name dind -v {{.DOCKER_SOCK}}:/var/run/docker.sock -v $(pwd):/bark-server docker tail -f /dev/null
- defer: docker rm -f dind
#- docker exec -w /bark-server -it dind docker run --privileged --rm tonistiigi/binfmt --install all
- docker exec -w /bark-server -it dind docker login
- docker exec -w /bark-server -it dind docker buildx create --name builder --driver docker-container --bootstrap --use
- docker exec -w /bark-server -it dind docker buildx build --platform {{.PLATFORM}} -t finab/bark-server:{{.BUILD_VERSION}} -f deploy/Dockerfile --push .
default:
Expand Down
5 changes: 3 additions & 2 deletions apns/apns.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type PushMessage struct {
DeviceToken string `form:"-" json:"-" xml:"-" query:"-"`
DeviceKey string `form:"device_key,omitempty" json:"device_key,omitempty" xml:"device_key,omitempty" query:"device_key,omitempty"`
Category string `form:"category,omitempty" json:"category,omitempty" xml:"category,omitempty" query:"category,omitempty"`
Subtitle string `form:"subtitle,omitempty" json:"subtitle,omitempty" xml:"subtitle,omitempty" query:"subtitle,omitempty"`
Title string `form:"title,omitempty" json:"title,omitempty" xml:"title,omitempty" query:"title,omitempty"`
Body string `form:"body,omitempty" json:"body,omitempty" xml:"body,omitempty" query:"body,omitempty"`
// ios notification sound(system sound please refer to http://iphonedevwiki.net/index.php/AudioServices)
Expand Down Expand Up @@ -79,9 +79,10 @@ func init() {
func Push(msg *PushMessage) error {
pl := payload.NewPayload().
AlertTitle(msg.Title).
AlertSubtitle(msg.Subtitle).
AlertBody(msg.Body).
Sound(msg.Sound).
Category(msg.Category)
Category("myNotificationCategory")

group, exist := msg.ExtParams["group"]
if exist {
Expand Down
2 changes: 1 addition & 1 deletion deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ RUN echo 'hosts: files dns' > /etc/nsswitch.conf
# override it with `--build-arg TIMEZONE=xxxx`
ARG TIMEZONE=Asia/Shanghai

ENV TZ ${TIMEZONE}
ENV TZ=${TIMEZONE}

RUN set -ex \
&& apk upgrade \
Expand Down
11 changes: 4 additions & 7 deletions docs/API_V2.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ the V2 version.**
| Field | Type | Description |
| ----- | ---- | ----------- |
| title | string | Notification title (font size would be larger than the body) |
| subtitle | string | | Notification subtitle |
| body | string | Notification content |
| category | string | Reserved field, no use yet |
| device_key | string | The key for each device |
| level (optional) | string | `'active'`, `'timeSensitive'`, or `'passive'` |
| badge (optional) | integer | The number displayed next to App icon ([Apple Developer](https://developer.apple.com/documentation/usernotifications/unnotificationcontent/1649864-badge)) |
Expand All @@ -45,7 +45,6 @@ curl -X "POST" "http://127.0.0.1:8080/push" \
"device_key": "ynJ5Ft4atkMkWeo2PAvFhF",
"title": "bleem",
"badge": 1,
"category": "myNotificationCategory",
"sound": "minuet.caf",
"icon": "https://day.app/assets/images/avatar.jpg",
"group": "test",
Expand All @@ -68,7 +67,7 @@ import (
func sendPush() {
// push (POST http://127.0.0.1:8080/push)

json := []byte(`{"body": "Test Bark Server","device_key": "nysrshcqielvoxsa","title": "bleem", "badge": 1, "icon": "https://day.app/assets/images/avatar.jpg", "group": "test", "url": "https://mritd.com","category": "myNotificationCategory","sound": "minuet.caf"}`)
json := []byte(`{"body": "Test Bark Server","device_key": "nysrshcqielvoxsa","title": "bleem", "badge": 1, "icon": "https://day.app/assets/images/avatar.jpg", "group": "test", "url": "https://mritd.com","sound": "minuet.caf"}`)
body := bytes.NewBuffer(json)

// Create client
Expand Down Expand Up @@ -124,7 +123,6 @@ def send_request():
"body": "Test Bark Server",
"device_key": "nysrshcqielvoxsa",
"title": "bleem",
"category": "myNotificationCategory",
"sound": "minuet.caf",
"badge": 1,
"icon": "https://day.app/assets/images/avatar.jpg",
Expand Down Expand Up @@ -166,7 +164,7 @@ public class SendRequest
.addHeader("Content-Type", "application/json; charset=utf-8")

// Add body
.bodyString("{\"body\": \"Test Bark Server\",\"device_key\": \"nysrshcqielvoxsa\",\"title\": \"bleem\",\"url\": \"https://mritd.com\", \"group\": \"test\",\"category\": \"myNotificationCategory\",\"sound\": \"minuet.caf\"}", ContentType.APPLICATION_JSON)
.bodyString("{\"body\": \"Test Bark Server\",\"device_key\": \"nysrshcqielvoxsa\",\"title\": \"bleem\",\"url\": \"https://mritd.com\", \"group\": \"test\",\"sound\": \"minuet.caf\"}", ContentType.APPLICATION_JSON)

// Fetch request and return content
.execute().returnContent();
Expand Down Expand Up @@ -223,7 +221,7 @@ public class SendRequest
.on('error', (error) => {
callback(error);
});
request.write("{\"device_key\":\"nysrshcqielvoxsa\",\"body\":\"Test Bark Server\",\"title\":\"bleem\",\"sound\":\"minuet.caf\",\"category\":\"myNotificationCategory\",\"url\":\"https://mritd.com\", \"group\":\"test\"}")
request.write("{\"device_key\":\"nysrshcqielvoxsa\",\"body\":\"Test Bark Server\",\"title\":\"bleem\",\"sound\":\"minuet.caf\",\"url\":\"https://mritd.com\", \"group\":\"test\"}")
request.end();


Expand All @@ -247,7 +245,6 @@ curl_setopt_array($curl, [
"device_key": "ynJ5Ft4atkMkWeo2PAvFhF",
"title": "bleem",
"badge": 1,
"category": "myNotificationCategory",
"sound": "minuet.caf",
"icon": "https://day.app/assets/images/avatar.jpg",
"group": "test",
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func main() {
ProxyHeader: c.String("proxy-header"),
ReduceMemoryUsage: c.Bool("reduce-memory-usage"),
JSONEncoder: jsoniter.Marshal,
Network: "tcp",
Network: "tcp",
ErrorHandler: func(c *fiber.Ctx, err error) error {
code := fiber.StatusInternalServerError
if e, ok := err.(*fiber.Error); ok {
Expand Down Expand Up @@ -183,7 +183,7 @@ func main() {
}

go func() {
sigs := make(chan os.Signal)
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
for range sigs {
logger.Warn("Received a termination signal, bark server shutdown...")
Expand Down
22 changes: 11 additions & 11 deletions route_push.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"github.com/gofiber/fiber/v2/utils"
"net/url"
"strings"

"github.com/gofiber/fiber/v2/utils"

"github.com/finb/bark-server/v2/apns"

"github.com/gofiber/fiber/v2"
Expand All @@ -27,8 +28,8 @@ func init() {
router.Get("/:device_key/:title/:body", func(c *fiber.Ctx) error { return routeDoPush(c) })
router.Post("/:device_key/:title/:body", func(c *fiber.Ctx) error { return routeDoPush(c) })

router.Get("/:device_key/:category/:title/:body", func(c *fiber.Ctx) error { return routeDoPush(c) })
router.Post("/:device_key/:category/:title/:body", func(c *fiber.Ctx) error { return routeDoPush(c) })
router.Get("/:device_key/:title/:subtitle/:body", func(c *fiber.Ctx) error { return routeDoPush(c) })
router.Post("/:device_key/:title/:subtitle/:body", func(c *fiber.Ctx) error { return routeDoPush(c) })
})
}

Expand Down Expand Up @@ -70,7 +71,7 @@ func routeDoPushV2(c *fiber.Ctx) error {
return c.Status(400).JSON(failed(400, "request bind failed: %v", err))
}
// parse query args (medium priority)
c.Request().URI().QueryArgs().VisitAll(func(key, value []byte){
c.Request().URI().QueryArgs().VisitAll(func(key, value []byte) {
params[strings.ToLower(string(key))] = string(value)
})
return push(c, params)
Expand All @@ -79,8 +80,7 @@ func routeDoPushV2(c *fiber.Ctx) error {
func push(c *fiber.Ctx, params map[string]interface{}) error {
// default value
msg := apns.PushMessage{
Category: "myNotificationCategory",
Body: "NoContent",
Body: "",
Sound: "1107",
ExtParams: make(map[string]interface{}),
}
Expand All @@ -91,8 +91,8 @@ func push(c *fiber.Ctx, params map[string]interface{}) error {
switch strings.ToLower(string(key)) {
case "device_key":
msg.DeviceKey = val
case "category":
msg.Category = val
case "subtitle":
msg.Subtitle = val
case "title":
msg.Title = val
case "body":
Expand Down Expand Up @@ -120,12 +120,12 @@ func push(c *fiber.Ctx, params map[string]interface{}) error {
if pathDeviceKey := c.Params("device_key"); pathDeviceKey != "" {
msg.DeviceKey = pathDeviceKey
}
if category := c.Params("category"); category != "" {
str, err := url.QueryUnescape(category)
if subtitle := c.Params("subtitle"); subtitle != "" {
str, err := url.QueryUnescape(subtitle)
if err != nil {
return err
}
msg.Category = str
msg.Subtitle = str
}
if title := c.Params("title"); title != "" {
str, err := url.QueryUnescape(title)
Expand Down
2 changes: 1 addition & 1 deletion router.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func registerRouteWithWeight(name string, weight int, f func(router fiber.Router
}

for _, r := range routes {
if strings.ToLower(name) == strings.ToLower(r.Name) {
if strings.EqualFold(name, r.Name) {
logger.Fatalf("route [%s] already registered", r.Name)
}
}
Expand Down

0 comments on commit 5ed7573

Please sign in to comment.