Compare commits

...

8 Commits

Author SHA1 Message Date
a3af1a0a17 Merge pull request #5 from FatttSnake/FatttSnake
Build(build-docker.sh): Save build time to file
2024-09-04 23:02:19 +08:00
9d16a11a89 Build(build-docker.sh): Save build time to file 2024-09-04 22:52:52 +08:00
7d328a11d1 Merge pull request #4 from FatttSnake/FatttSnake
Add README. Optimize pom and docker build script.
2024-09-04 18:53:04 +08:00
3202bb5422 Build(build-docker.sh): Optimize script 2024-09-04 18:12:54 +08:00
126af27c02 Refactor(README): Update README.md and README_zh.md 2024-09-04 17:37:31 +08:00
6b3639232b Build(pom): Update version from 0.0.1-SNAPSHOT to 1.0.0-SNAPSHOT 2024-09-04 17:35:42 +08:00
909a169373 Docs(README): Add README.md and README_zh.md 2024-09-04 17:34:42 +08:00
834f283f8b Build(pom): Optimize structure 2024-09-04 16:50:42 +08:00
5 changed files with 375 additions and 157 deletions

77
README.md Normal file
View File

@@ -0,0 +1,77 @@
<div align="center">
<h1>
<img alt="Logo" src="doc/logo.svg" width="128">
<br>
<span>API of Oxygen Toolbox</span>
</h1>
</div>
<div align="center">
<a href="https://ci.fatweb.top/job/Oxygen%20Toolbox%20API/">
<img alt="Build" src="https://ci.fatweb.top/job/Oxygen%20Toolbox%20API/badge/icon">
</a>
<a href="https://github.com/FatttSnake/oxygen-api/releases/latest">
<img alt="Release" src="https://img.shields.io/github/v/release/FatttSnake/oxygen-api">
</a>
<a href="LICENSE">
<img alt="LICENSE" src="https://img.shields.io/github/license/FatttSnake/oxygen-api">
</a>
</div>
# Overview ([ZH](README_zh.md), EN)
This project is the backend API of Oxygen Toolbox. Provides tool store, tool management, authentication, user management and other functions.
# Requires
- Java 17+
- MySQL
- Redis
# Related projects
[Web UI of Oxygen Toolbox](https://github.com/FatttSnake/oxygen-ui)
[Desktop Client of Oxygen Toolbox](https://github.com/FatttSnake/oxygen-desktop)
[Android Client of Oxygen Toolbox](https://github.com/FatttSnake/oxygen-android)
# Quick Start
1. First run, generate configuration file template
```shell
java -jar oxygen-api.jar
```
2. Copy the `application-config.example.yml` file in the `data` directory to the running directory and rename it to `application-config.yml`
```shell
cp ./data/application-config.example.yml application-config.yml
```
3. Edit the content of the configuration file `application-config.yml`
4. Run again
```shell
java -jar oxygen-api.jar
```
# Security
Integration with Spring Security and add other filter for jwt token process. The secret key is stored in `application-config.yml`.
# Database
Two databases, MySQL + SQLite, are used. MySQL is used to store key data, and SQLite is used to store logs and other data that require a large amount of reading and writing.
# Q&A
> **Q: What is the default administrator account and password?**
>
> A: If configured in `application-config.yml` before initializing the database, use the specified account and password. If not configured, a random password will be generated by default. See the console output for details.
> **Q: Do I need to initialize the database?**
>
> A: This project uses `Flyway` to automatically initialize the database without manually defining the data table structure. To ensure data security, please back up the database before upgrading.

77
README_zh.md Normal file
View File

@@ -0,0 +1,77 @@
<div align="center">
<h1>
<img alt="Logo" src="doc/logo.svg" width="128">
<br>
<span>API of Oxygen Toolbox</span>
</h1>
</div>
<div align="center">
<a href="https://ci.fatweb.top/job/Oxygen%20Toolbox%20API/">
<img alt="Build" src="https://ci.fatweb.top/job/Oxygen%20Toolbox%20API/badge/icon">
</a>
<a href="https://github.com/FatttSnake/oxygen-api/releases/latest">
<img alt="Release" src="https://img.shields.io/github/v/release/FatttSnake/oxygen-api">
</a>
<a href="LICENSE">
<img alt="LICENSE" src="https://img.shields.io/github/license/FatttSnake/oxygen-api">
</a>
</div>
# 概述 (ZH, [EN](README.md))
本项目为 Oxygen Toolbox 的后端 API。提供工具商店、工具管理、认证鉴权、用户管理等功能。
# 环境要求
- Java 17+
- MySQL
- Redis
# 关联项目
[Web UI of Oxygen Toolbox](https://github.com/FatttSnake/oxygen-ui)
[Desktop Client of Oxygen Toolbox](https://github.com/FatttSnake/oxygen-desktop)
[Android Client of Oxygen Toolbox](https://github.com/FatttSnake/oxygen-android)
# 快速开始
1. 初次运行,生成配置文件模板
```shell
java -jar oxygen-api.jar
```
2.`data` 目录下的 `application-config.example.yml` 文件复制到运行目录下,并重命名为 `application-config.yml`
```shell
cp ./data/application-config.example.yml application-config.yml
```
3. 编辑配置文件 `application-config.yml` 内容
4. 再次运行
```shell
java -jar oxygen-api.jar
```
# 安全
集成 Spring Security 并采用 jwt 令牌, 密钥存储在 `application-config.yml` 中。
# 数据库
采用 MySQL + SQLite 双数据库MySQL 用于存放关键数据SQLite 用于存放日志等需要大量读写的数据。
# Q&A
> **Q: 默认管理员账号和密码是什么?**
>
> A: 初始化数据库前配置在 `application-config.yml` 中,则使用所指定账号密码。未配置则默认生成随机密码,详见控制台输出。
> **Q: 是否需要初始化数据库?**
>
> A: 本项目采用 `Flyway` 自动初始化数据库,无需手动定义数据表结构。为保证数据安全,升级时请先备份数据库。

View File

@@ -1,24 +1,19 @@
#!/bin/bash
JAR_NAME=`ls target | grep api-|grep -v original`
JAR_NAME=`ls target | grep oxygen-api- | grep -vE "original|asc|pom|javadoc"`
JAR_VERSION=${JAR_NAME%.*}
JAR_VERSION=${JAR_VERSION#*-}
JAR_VERSION=${JAR_VERSION#*-}
BUILD_TIME=$(date "+%Y%m%d%H%M%S")
echo ${BUILD_TIME} > .build_time
mkdir target/extracted
java -Djarmode=layertools -jar target/*.jar extract --destination target/extracted
java -Djarmode=layertools -jar target/${JAR_NAME} extract --destination target/extracted
if [[ "${JAR_VERSION}" =~ ^.*SNAPSHOT$ ]]
then
docker build -t ${DOCKER_HUB_URL}/oxygen-api:snapshot-latest -t ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION -t ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION-${BUILD_TIME} .
cat "${KEYS_PATH}/docker.password" | docker login ${DOCKER_HUB_URL} -u jenkins --password-stdin
docker push ${DOCKER_HUB_URL}/oxygen-api:snapshot-latest
docker push ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION
docker push ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION-${BUILD_TIME}
docker build -t ${DOCKER_HUB_URL}/oxygen-api:snapshot-latest -t ${DOCKER_HUB_URL}/oxygen-api:${JAR_VERSION} -t ${DOCKER_HUB_URL}/oxygen-api:${JAR_VERSION}-${BUILD_TIME} .
else
docker build -t ${DOCKER_HUB_URL}/oxygen-api:latest -t ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION -t ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION-${BUILD_TIME} .
cat "${KEYS_PATH}/docker.password" | docker login ${DOCKER_HUB_URL} -u jenkins --password-stdin
docker push ${DOCKER_HUB_URL}/oxygen-api:latest
docker push ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION
docker push ${DOCKER_HUB_URL}/oxygen-api:$JAR_VERSION-${BUILD_TIME}
docker build -t ${DOCKER_HUB_URL}/oxygen-api:latest -t ${DOCKER_HUB_URL}/oxygen-api:${JAR_VERSION} -t ${DOCKER_HUB_URL}/oxygen-api:${JAR_VERSION}-${BUILD_TIME} .
fi

1
doc/logo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.9 KiB

358
pom.xml
View File

@@ -8,78 +8,140 @@
<version>3.2.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>top.fatweb</groupId>
<groupId>top.fatweb.oxygen</groupId>
<artifactId>api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
<name>oxygen-api</name>
<description>oxygen-api</description>
<repositories>
<repository>
<id>sonatype-oss-snapshots</id>
<name>sonatype-oss-snapshots</name>
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<activation>
<property>
<name>env</name>
<value>prod</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-ui</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</profile>
</profiles>
<description>API of Oxygen Toolbox</description>
<url>https://github.com/FatttSnake/oxygen-api</url>
<properties>
<java.version>17</java.version>
<kotlin.version>1.9.21</kotlin.version>
<build.timestamp>${maven.build.timestamp}</build.timestamp>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss</maven.build.timestamp.format>
<retrofit.version>3.0.3</retrofit.version>
<velocity.version>2.3</velocity.version>
<mybatis-plus.version>3.5.7</mybatis-plus.version>
<dynamic-datasource.version>4.3.1</dynamic-datasource.version>
<flyway.version>9.22.3</flyway.version>
<jwt.version>4.4.0</jwt.version>
<avatar-generator.version>1.1.0</avatar-generator.version>
<oshi.version>6.4.9</oshi.version>
<zxing.version>3.5.3</zxing.version>
<knife4j.version>4.4.0</knife4j.version>
</properties>
<organization>
<name>FatWeb</name>
<url>https://fatweb.top</url>
</organization>
<licenses>
<license>
<name>GNU General Public License v3.0 or later</name>
<url>https://www.gnu.org/licenses/gpl-3.0-standalone.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<developers>
<developer>
<id>fatttsnake</id>
<name>FatttSnake</name>
<email>fatttsnake@gmail.com</email>
</developer>
</developers>
<build>
<finalName>${project.name}-${project.version}</finalName>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
<source>target/generated-sources/annotations</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
<source>target/generated-sources/annotations</source>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>1.9.10</version>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>dokka</goal>
</goals>
</execution>
<execution>
<id>attach-javadocJar</id>
<phase>package</phase>
<goals>
<goal>javadocJar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -111,20 +173,10 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.lianjiatech</groupId>
<artifactId>retrofit-spring-boot-starter</artifactId>
<version>3.0.3</version>
<version>${retrofit.version}</version>
</dependency>
<dependency>
@@ -147,7 +199,7 @@
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
@@ -157,17 +209,16 @@
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter</artifactId>
<version>3.5.7</version>
<version>${mybatis-plus.version}</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.44.1.0</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>4.3.1</version>
<version>${dynamic-datasource.version}</version>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
@@ -178,94 +229,111 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter-test</artifactId>
<version>3.5.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>4.4.0</version>
<version>${jwt.version}</version>
</dependency>
<dependency>
<groupId>top.fatweb</groupId>
<artifactId>avatar-generator</artifactId>
<version>1.1.0</version>
<version>${avatar-generator.version}</version>
</dependency>
<dependency>
<groupId>com.github.oshi</groupId>
<artifactId>oshi-core</artifactId>
<version>6.4.9</version>
<version>${oshi.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.16.1</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.5.3</version>
<version>${zxing.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-spring-boot3-starter-test</artifactId>
<version>${mybatis-plus.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
<source>target/generated-sources/annotations</source>
</sourceDirs>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>1.9.10</version>
<executions>
<execution>
<phase>pre-site</phase>
<goals>
<goal>dokka</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>dev</id>
<activation>
<activeByDefault>true</activeByDefault>
<property>
<name>env</name>
<value>dev</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>release</id>
<activation>
<property>
<name>env</name>
<value>release</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
<exclusions>
<exclusion>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-ui</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>sign-artifact</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>