Skip to content

Commit ec92954

Browse files
committed
Update use h2 db
1 parent 5e6104d commit ec92954

File tree

14 files changed

+667
-145
lines changed

14 files changed

+667
-145
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ build
2828
/.env
2929
.vscode
3030
/.json
31-
!gradle/wrapper/gradle-wrapper.jar
31+
!gradle/wrapper/gradle-wrapper.jar
32+
*.db

README.md

Lines changed: 100 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,126 @@
1-
# Java Electerm sync server
1+
# Java Electerm Sync Server
22

33
[![Build Status](https://github.com/electerm/electerm-sync-server-java/actions/workflows/linux.yml/badge.svg)](https://github.com/electerm/electerm-sync-server-java/actions)
44

5-
A simple electerm data sync server.
5+
[English](README.md) | [中文](README_CN.md)
66

7-
## Use
7+
A simple, lightweight data synchronization server for [Electerm](https://github.com/electerm/electerm), built with Java and Spark. It provides a REST API for syncing bookmarks, history, and other data across Electerm instances.
88

9-
```bash
10-
git clone git@github.com:electerm/electerm-sync-server-java.git
11-
cd electerm-sync-server-java
9+
## Prerequisites
10+
11+
- **Java 17**: Required for building and running the server. Download from [Adoptium](https://adoptium.net/) or your preferred JDK provider.
12+
- **Gradle**: Included via the Gradle Wrapper (`gradlew`), so no separate installation needed.
13+
- **Git**: For cloning the repository.
14+
15+
## Installation
16+
17+
1. **Clone the repository**:
18+
19+
```bash
20+
git clone https://github.com/electerm/electerm-sync-server-java.git
21+
cd electerm-sync-server-java
22+
```
23+
24+
2. **Set up the environment file**:
25+
26+
```bash
27+
cp sample.env .env
28+
```
1229

13-
# create env file, then edit .env
14-
cp sample.env .env
30+
Edit `.env` with your preferred settings (see Configuration below).
1531

16-
## run
17-
gradlew run
32+
## Configuration
1833

19-
## build
20-
gradlew build
34+
The server uses environment variables from a `.env` file for configuration. Key settings include:
2135

22-
# would show something like
23-
# server running at http://127.0.0.1:7837
24-
# Then you can use http://127.0.0.1:7837/api/sync as API Url in electerm custom sync
36+
- `JWT_SECRET`: A secret key for JWT token signing (generate a strong random string).
37+
- `JWT_USER_NAME`: Username for authentication.
38+
- `JWT_USER_PASSWORD`: Password for authentication.
39+
- `PORT`: Server port (default: 7837).
40+
- `DB_URL`: H2 database URL (default: embedded database).
2541

26-
# in electerm sync settings, set custom sync server with:
27-
# server url: http://127.0.0.1:7837
28-
# JWT_SECRET: your JWT_SECRET in .env
29-
# JWT_USER_NAME: one JWT_USER in .env
42+
Example `.env`:
43+
44+
```properties
45+
JWT_SECRET=your-super-secret-key-here
46+
JWT_USER_NAME=admin
47+
JWT_USER_PASSWORD=securepassword
48+
PORT=7837
49+
DB_URL=jdbc:h2:./electerm_sync_db
3050
```
3151

32-
## Test
52+
**Security Note**: Never commit `.env` to version control. Use strong, unique values for secrets.
53+
54+
## Running the Server
3355

56+
### Development Mode
57+
For quick testing or development:
58+
```bash
59+
./gradlew run
60+
```
61+
- Starts the server on `http://127.0.0.1:7837`.
62+
- Output will show: `server running at http://127.0.0.1:7837`.
63+
- Press `Ctrl+C` to stop.
64+
65+
### Production Mode
66+
1. **Build the application**:
67+
```bash
68+
./gradlew build
69+
```
70+
71+
2. **Extract the distribution**:
72+
```bash
73+
tar -xvf build/distributions/electerm-sync-server-java.tar
74+
cd electerm-sync-server-java
75+
```
76+
77+
3. **Run the server**:
78+
```bash
79+
./bin/electerm-sync-server-java
80+
```
81+
- Runs in the foreground. Use `&` to background it: `./bin/electerm-sync-server-java &`.
82+
- Access at `http://127.0.0.1:7837` (or your configured port).
83+
84+
## Using with Electerm
85+
86+
1. In Electerm, go to **Settings > Sync**.
87+
2. Select **Custom Sync Server**.
88+
3. Set:
89+
- **Server URL**: `http://127.0.0.1:7837` (or your server's URL).
90+
- **JWT Secret**: The `JWT_SECRET` from your `.env`.
91+
- **Username**: The `JWT_USER_NAME` from your `.env`.
92+
4. Save and sync your data.
93+
94+
The API endpoint is `http://127.0.0.1:7837/api/sync`.
95+
96+
## Testing
97+
98+
Run the test suite:
3499
```bash
35-
gradlew test
100+
./gradlew test
36101
```
102+
- Uses JUnit for unit tests.
103+
- Reports are in `build/reports/tests/test/index.html`.
104+
105+
## Customization
106+
107+
### Writing Your Own Data Store
37108

38-
## Write your own data store
109+
The server uses an H2 database by default, but you can implement custom storage.
39110

40-
Just take [src/main/java/ElectermSync/FileStore.java](src/main/java/ElectermSync/FileStore.java) as an example, write your own read/write method.
111+
1. Implement the data store interface by extending or referencing `DataStore.java`.
112+
2. Update `App.java` to use your custom store.
113+
3. Rebuild and run.
41114

115+
Example: Take [src/main/java/ElectermSync/DataStore.java](src/main/java/ElectermSync/DataStore.java) as a reference for read/write methods.
42116

43117
## Docker
44118

45-
[https://github.com/Aliang-code/electerm-sync-server-java-docker](https://github.com/Aliang-code/electerm-sync-server-java-docker)
119+
For containerized deployment, see [electerm-sync-server-java-docker](https://github.com/Aliang-code/electerm-sync-server-java-docker).
46120

47-
## Sync server in other languages
121+
## Sync Servers in Other Languages
48122

49-
[https://github.com/electerm/electerm/wiki/Custom-sync-server](https://github.com/electerm/electerm/wiki/Custom-sync-server)
123+
Explore alternatives: [Custom Sync Server Wiki](https://github.com/electerm/electerm/wiki/Custom-sync-server).
50124

51125
## License
52126

README_CN.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Java Electerm 同步服务器
2+
3+
[![Build Status](https://github.com/electerm/electerm-sync-server-java/actions/workflows/linux.yml/badge.svg)](https://github.com/electerm/electerm-sync-server-java/actions)
4+
5+
[English](README.md) | [中文](README_CN.md)
6+
7+
一个简单、轻量的 [Electerm](https://github.com/electerm/electerm) 数据同步服务器,使用 Java 和 Spark 构建。它提供 REST API 用于跨 Electerm 实例同步书签、历史记录和其他数据。
8+
9+
## 先决条件
10+
11+
- **Java 17**:构建和运行服务器所需。从 [Adoptium](https://adoptium.net/) 或您首选的 JDK 提供商下载。
12+
- **Gradle**:通过 Gradle Wrapper(`gradlew`)包含,因此无需单独安装。
13+
- **Git**:用于克隆仓库。
14+
15+
## 安装
16+
17+
1. **克隆仓库**
18+
19+
```bash
20+
git clone https://github.com/electerm/electerm-sync-server-java.git
21+
cd electerm-sync-server-java
22+
```
23+
24+
2. **设置环境文件**
25+
26+
```bash
27+
cp sample.env .env
28+
```
29+
30+
使用您的首选设置编辑 `.env`(请参阅配置部分)。
31+
32+
## 配置
33+
34+
服务器使用 `.env` 文件中的环境变量进行配置。关键设置包括:
35+
36+
- `JWT_SECRET`:JWT 令牌签名的密钥(生成一个强随机字符串)。
37+
- `JWT_USER_NAME`:用于认证的用户名。
38+
- `JWT_USER_PASSWORD`:用于认证的密码。
39+
- `PORT`:服务器端口(默认:7837)。
40+
- `DB_URL`:H2 数据库 URL(默认:嵌入式数据库)。
41+
42+
示例 `.env`
43+
44+
```properties
45+
JWT_SECRET=your-super-secret-key-here
46+
JWT_USER_NAME=admin
47+
JWT_USER_PASSWORD=securepassword
48+
PORT=7837
49+
DB_URL=jdbc:h2:./electerm_sync_db
50+
```
51+
52+
**安全注意**:切勿将 `.env` 提交到版本控制。使用强且唯一的密钥。
53+
54+
## 运行服务器
55+
56+
### 开发模式
57+
58+
用于快速测试或开发:
59+
60+
```bash
61+
./gradlew run
62+
```
63+
64+
-`http://127.0.0.1:7837` 上启动服务器。
65+
- 输出将显示:`server running at http://127.0.0.1:7837`
66+
-`Ctrl+C` 停止。
67+
68+
### 生产模式
69+
70+
1. **构建应用程序**
71+
72+
```bash
73+
./gradlew build
74+
```
75+
76+
2. **提取分发包**
77+
78+
```bash
79+
tar -xvf build/distributions/electerm-sync-server-java.tar
80+
cd electerm-sync-server-java
81+
```
82+
83+
3. **运行服务器**
84+
85+
```bash
86+
./bin/electerm-sync-server-java
87+
```
88+
89+
- 在前台运行。使用 `&` 在后台运行:`./bin/electerm-sync-server-java &`
90+
-`http://127.0.0.1:7837`(或您的配置端口)访问。
91+
92+
## 与 Electerm 一起使用
93+
94+
1. 在 Electerm 中,转到 **设置 > 同步**
95+
2. 选择 **自定义同步服务器**
96+
3. 设置:
97+
- **服务器 URL**`http://127.0.0.1:7837`(或您的服务器 URL)。
98+
- **JWT 密钥**:来自您的 `.env``JWT_SECRET`
99+
- **用户名**:来自您的 `.env``JWT_USER_NAME`
100+
4. 保存并同步数据。
101+
102+
API 端点是 `http://127.0.0.1:7837/api/sync`
103+
104+
## 测试
105+
106+
运行测试套件:
107+
108+
```bash
109+
./gradlew test
110+
```
111+
112+
- 使用 JUnit 进行单元测试。
113+
- 报告位于 `build/reports/tests/test/index.html`
114+
115+
## 自定义
116+
117+
### 编写您自己的数据存储
118+
119+
服务器默认使用 H2 数据库,但您可以实现自定义存储。
120+
121+
1. 通过扩展或引用 `DataStore.java` 实现数据存储接口。
122+
2. 更新 `App.java` 以使用您的自定义存储。
123+
3. 重新构建并运行。
124+
125+
示例:以 [src/main/java/ElectermSync/DataStore.java](src/main/java/ElectermSync/DataStore.java) 为参考来实现读/写方法。
126+
127+
## Docker
128+
129+
对于容器化部署,请参阅 [electerm-sync-server-java-docker](https://github.com/Aliang-code/electerm-sync-server-java-docker)
130+
131+
## 其他语言的同步服务器
132+
133+
探索替代方案:[自定义同步服务器 Wiki](https://github.com/electerm/electerm/wiki/Custom-sync-server)
134+
135+
## 许可证
136+
137+
MIT

build.gradle

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ dependencies {
2323
implementation 'io.github.cdimascio:java-dotenv:5.2.1'
2424
implementation 'org.slf4j:slf4j-api:1.7.32'
2525
implementation 'ch.qos.logback:logback-classic:1.2.3'
26+
implementation 'com.h2database:h2:2.1.214'
2627
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.3'
2728
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.3'
29+
testImplementation 'io.rest-assured:rest-assured:5.3.0'
30+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
2831
}
2932

3033
application {
@@ -39,9 +42,9 @@ application {
3942
// }
4043
// }
4144

42-
// test {
43-
// useJUnitPlatform()
44-
// testLogging {
45-
// events "passed", "skipped", "failed"
46-
// }
47-
// }
45+
test {
46+
useJUnitPlatform()
47+
testLogging {
48+
events "passed", "skipped", "failed"
49+
}
50+
}

gradle/wrapper/gradle-wrapper.jar

-18.1 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
44
networkTimeout=10000
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)