Skip to content

Commit

Permalink
Improve: Doc Update & Fix: Empty Key Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
cwxia0s committed Feb 19, 2024
1 parent ac3d39d commit 0758fda
Show file tree
Hide file tree
Showing 51 changed files with 555 additions and 48 deletions.
49 changes: 35 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,52 @@
# Bark Server On Cloudflare Worker
<p align="center">
<h1 align="center">Bark-Worker</h1>
</p>

This is a Bark Server On Cloudflare Worker.
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

## What is Bark
**[中文文档](README.zh.md)**

<img src="https://wx3.sinaimg.cn/mw690/0060lm7Tly1g0nfnjjxbbj30sg0sg757.jpg" width=200px height=200px />
Bark-Worker is a [Bark-Server](https://github.com/Finb/bark-server) implenmention on Cloudflare Worker. It provides privacy-aware users with a cheap and private bark backend.

### What is [Bark](https://github.com/Finb/Bark)?
[Bark](https://github.com/Finb/Bark) is an iOS App which allows you to push customed notifications to your iPhone.

## Setup [[中文]](README_zh.md)
> [!NOTE]
> A domain is required if worker.dev is unavailable in your country/region
### An availiable domian.
## Features
- Full Bark-Server APIs support
- `register`
- `ping`
- `healthz`
- `info`
- `push`
- Path based parameters resolve
- Easy to deploy, Cheap to use and Convenient to manage

For Cloudflare Worker users, Create a new worker with KV, bind your KV to the bark-worker as 'database'.
## Setup

<img src="doc/images/Screenshot from 2023-10-24 08-54-05.png">
> [!NOTE]
> Select one, D1 or KV Version are both available. D1 Version is recommended for its higher usage than KV Version. However, Cloudflare D1 is still in `beta`, which is unstable, use at your own risk.
<img src="doc/images/Screenshot from 2023-10-24 08-54-31.png">
<!-- > [!CAUTION]
> After Cloudflare D1 is not in Beta, KV Version maybe deprecated. -->

Refer to [Setup Guide](doc/setup_guide.md)

Here's where to bing KV:
### Cloudflare D1 Version

<img src="doc/images/Screenshot from 2023-10-25 22-05-51.png">
Create a Worker and a D1 Database, bind D1 database to Worker with name `database`

If you want to block new registeration, modify code at here:
### Cloudflare KV Version

<img src="doc/images/Screenshot from 2023-10-25 22-05-13.png">
Create a Worker and a KV Storage, bind KV Storage to Worker with name `database`

## If you think this project is helpful to you, please Star it.
## Tips

- Multi Device Key to one Device
- Device Key Alias
- D1 Database Manage in Console
- etc.

Refer to [Tips](doc/tips.md)
50 changes: 50 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<p align="center">
<h1 align="center">Bark-Worker</h1>
</p>

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

Bark-Worker 是一个 [Bark-Server](https://github.com/Finb/bark-server) 在 Cloudflare Worker 上的实现. 为隐私敏感的用户提供一个低成本且保证隐私的服务端.

### 什么是 [Bark](https://github.com/Finb/Bark)?
[Bark](https://github.com/Finb/Bark) 是一个允许向iPhone发送通知的iOS APP.

> [!NOTE]
> 如果worker.dev域名在当前国家/地区不可用,则需要一个自己的域名
## 特性
- 支持所有的Bark-Worker API
- `register`
- `ping`
- `healthz`
- `info`
- `push`
- 基于路径的参数解析
- 便于部署, 低成本且方便管理

## 部署

> [!NOTE]
> 从D1版本和KV版本中选择一个. 更推荐D1版本, D1版本的额度更高. 但是Cloudflare D1还在Beta, 可能不稳定, 使用风险自负.
<!-- > [!CAUTION]
> 当Cloudfalre D1不再Beta后, KV版本的Database部分可能停止维护. -->

参考 [部署指南](doc/setup_guide.zh.md)

### Cloudflare D1 版本

Create a Worker and a D1 Database, bind D1 database to Worker with name `database`

### Cloudflare KV 版本

Create a Worker and a KV Storage, bind KV Storage to Worker with name `database`

## Tips

- 一个设备使用多个Key
- 设备Key别名
- D1数据库Console管理
- etc.

参考 [Tips](doc/tips.zh.md)
20 changes: 0 additions & 20 deletions README_zh.md

This file was deleted.

Binary file removed doc/images/Screenshot from 2023-10-24 08-54-05.png
Binary file not shown.
Binary file not shown.
Binary file removed doc/images/Screenshot from 2023-10-25 22-05-13.png
Binary file not shown.
Binary file removed doc/images/Screenshot from 2023-10-25 22-05-51.png
Binary file not shown.
Binary file added doc/images/bark.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/images.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
122 changes: 122 additions & 0 deletions doc/setup_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Setup Guide

## Register Cloudflare Account

If you already have an account, goto [Create Worker](#create-worker)

Visit Cloudflare Website, Click Sign Up, Register an Account

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-26-05.png" width="500">
</p>

## Create Worker

After Sign Up or Login, Click `Workers & Pages` &rarr; `OverView` &rarr; `Create Worker`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-28-35.png" width="500">
</p>
<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-28-35.png" width="500">
</p>
<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-28-50.png" width="500">
</p>

Then Click `Deploy`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-29-05.png" width="500">
</p>

Then Click `Edit Code`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-29-29.png" width="500">
</p>

Copy Code From [main.js](../main.js) or [main_d1.js](../main_d1.js) and Paste It

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-30-20.png" width="500">
</p>

If it's First Deploy and Has no Device in Database, Modify `isAllowNewDevice` to `true` in order to allow Registeration

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-33-54.png" width="500">
</p>

Then Click `Save`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-30-29.png" width="500">
</p>

## Create Database

Click `Workers & Pages` &rarr; `D1` or `KV` &rarr; `Create`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-31-34.png" width="500">
</p>

Fill a name and Click `Save`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-31-49.png" width="500">
</p>

## Bind Database

Click `Workers & Pages` &rarr; `OverView` &rarr; `The Worker You Just Created`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-14.png" width="500">
</p>

Then Click `Settings` &rarr; `Variables`

Click `D1 Database Bindings` or `KV Namesapce Bindings` Base on D1 or KV Version

Then Click `Edit Variables` &rarr; `Add Binding`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-14.png" width="500">
</p>

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-36.png" width="500">
</p>

Select the Namespace and Name it as `database`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-49.png" width="500">
</p>

Then Click `Save`

> [!CAUTION]
> The name MUST be `database`, Otherwise, Worker will throw exception
## Database Initialize

If you are using KV Version, goto [Register](#register)

After Modify `isAllowQueryNums` to `ture`, Send Request on path `/info`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-34-28.png" width="500">
</p>

If you see Response includes `devices: 0`, the Deploy is Succeed

## Register

Now you can use Bark APP to add the Server, or you can use curl or browser to test the server

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-35-13.png" width="500">
</p>
122 changes: 122 additions & 0 deletions doc/setup_guide.zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 部署指南

## 注册 Cloudflare 账户

如果已有 Cloudflare 账号, 跳转至 [创建Worker](#创建-worker)

访问 Cloudflare 网址, 点击 Sign Up, 注册一个账号

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-26-05.png" width="500">
</p>

## 创建 Worker

当注册或登陆后, 点击 `Workers & Pages` &rarr; `OverView` &rarr; `Create Worker`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-28-35.png" width="500">
</p>
<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-28-35.png" width="500">
</p>
<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-28-50.png" width="500">
</p>

点击 `Deploy`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-29-05.png" width="500">
</p>

点击 `Edit Code`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-29-29.png" width="500">
</p>

[main.js](../main.js)[main_d1.js](../main_d1.js) 复制代码并粘贴

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-30-20.png" width="500">
</p>

如果是第一次部署且数据库中没有设备, 需要将 `isAllowNewDevice` 改为 `true` 以允许新设备注册

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-33-54.png" width="500">
</p>

点击 `Save`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-30-29.png" width="500">
</p>

## 创建数据库

点击 `Workers & Pages` &rarr; `D1``KV` &rarr; `Create`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-31-34.png" width="500">
</p>

选择一个名称并点击 `Save`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-31-49.png" width="500">
</p>

## 绑定数据库

点击 `Workers & Pages` &rarr; `OverView` &rarr; `刚才创建的Worker`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-14.png" width="500">
</p>

点击 `Settings` &rarr; `Variables`

根据代码版本点击 `D1 Database Bindings``KV Namesapce Bindings`

点击 `Edit Variables` &rarr; `Add Binding`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-14.png" width="500">
</p>

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-36.png" width="500">
</p>

选择数据库并将其命名为 `database`

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-32-49.png" width="500">
</p>

点击 `Save`

> [!CAUTION]
> 名称必须为 `database`, 否则Worker会报错
## 初始化数据库

如果使用KV版本, 跳转至 [注册](#注册)

`isAllowQueryNums` 修改为 `ture`, 使用 `/info` 发送请求

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-34-28.png" width="500">
</p>

当返回中包含 `devices: 0`, 说明部署成功

## 注册

至此, 可以使用 Bark APP 或 浏览器等工具测试服务器

<p align="center">
<img src="images/setup/Screenshot from 2024-02-19 08-35-13.png" width="500">
</p>
Loading

0 comments on commit 0758fda

Please sign in to comment.