Skip to content

Commit

Permalink
Merge pull request 'dev' (#17) from dev into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fanxb committed Dec 1, 2023
2 parents 5a8f805 + b0b608d commit 44c1ca9
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 123 deletions.
24 changes: 16 additions & 8 deletions DEPLOY.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
本程序基于 docker 来进行部署,使用 docker-compose 管理服务。

部署过程如下:
**注意,仅在 x86 环境下测试,arm 下不保证可用性(目前测试可用)**

**注意,仅在 x86 环境下测试,arm下不保证可用性(目前测试可用)**
## 首次部署

1. 安装新版的 docker,docker-compose,zip(注意:以下操作均在项目根目录下执行)
2. 修改.env 文件中的参数,改为你的实际配置
3. 修改`浏览器插件/bookmarkBrowserPlugin/static/js/config.js`中的 bookmarkHost,改为你的实际部署路径
4. 修改`浏览器插件/bookmarkBrowserPlugin/tab/index.html`中的`<meta http-equiv="Refresh" content="0;url=https://bm.fleyx.com" />`,将 url 改为你的实际部署地址
5. 执行`build.sh`编译前后端代码
6. root 权限运行 `docker-compose up -d` 启动服务。
0. 克隆代码`git clone https://github.com/FleyX/bookmark.git`
1. 进入文件夹`cd bookmark`
2. 安装新版的 docker,docker-compose,zip `apt install docker docker-compose zip`
3. 修改.env 文件中的参数,改为你的实际配置
4. 修改`浏览器插件/bookmarkBrowserPlugin/static/js/config.js`中的 bookmarkHost,改为你的实际部署路径
5. 修改`浏览器插件/bookmarkBrowserPlugin/tab/index.html`中的`<meta http-equiv="Refresh" content="0;url=https://bm.fleyx.com" />`,将 url 改为你的实际部署地址
6. 执行`build.sh`编译前后端代码 `bash build.sh`
7. root 权限运行 `docker-compose up -d` 启动服务。

## 更新系统

0. 代码库更新`cd bookmark;git pull`
1. 执行`build.sh`编译前后端代码 `bash build.sh`
2. root 权限运行 `docker-compose restart` 启动服务
5 changes: 5 additions & 0 deletions bookMarkService/business/bookmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<artifactId>pinyin</artifactId>
<version>0.3.1</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.44.1.0</version>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Result getBookmarkMap() {
*/
@RequestMapping("/uploadBookmarkFile")
public Result uploadFile(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) throws Exception {
bookmarkService.parseBookmarkFile(UserContextHolder.get().getUserId(), file.getInputStream(), path);
bookmarkService.parseBookmarkFile(UserContextHolder.get().getUserId(), file, path);
return Result.success(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fanxb.bookmark.business.bookmark.entity.BookmarkEs;
import com.fanxb.bookmark.business.bookmark.entity.MoveNodeBody;
import com.fanxb.bookmark.common.entity.po.Bookmark;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.List;
Expand Down Expand Up @@ -54,7 +55,7 @@ public interface BookmarkService {
* @author fanxb
* @date 2019/7/9 18:44
*/
void parseBookmarkFile(int userId, InputStream stream, String path) throws Exception;
void parseBookmarkFile(int userId, MultipartFile file, String path) throws Exception;

/**
* Description: 详情
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.*;
import cn.hutool.core.util.HashUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.fanxb.bookmark.business.api.UserApi;
import com.fanxb.bookmark.business.bookmark.constant.FileConstant;
Expand Down Expand Up @@ -38,7 +36,9 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.awt.print.Book;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
Expand All @@ -49,6 +49,10 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -81,18 +85,25 @@ public BookmarkServiceImpl(BookmarkDao bookmarkDao, PinYinService pinYinService,

@Override
@Transactional(rollbackFor = Exception.class)
public void parseBookmarkFile(int userId, InputStream stream, String path) throws Exception {
Document doc = Jsoup.parse(stream, "utf-8", "");
Elements elements = doc.select("html>body>dl>dt");
public void parseBookmarkFile(int userId, MultipartFile file, String path) throws Exception {
List<Bookmark> bookmarks = new ArrayList<>();
//获取当前层sort最大值
Integer sortBase = bookmarkDao.selectMaxSort(userId, path);
if (sortBase == null) {
sortBase = 0;
}
List<Bookmark> bookmarks = new ArrayList<>();
for (int i = 0, length = elements.size(); i < length; i++) {
dealBookmark(userId, elements.get(i), path, sortBase + i, bookmarks);
if (file.getOriginalFilename().endsWith(".db3")) {
//处理db文件
readFromOneEnv(bookmarks, userId, file, path, sortBase);
} else {
InputStream stream = file.getInputStream();
Document doc = Jsoup.parse(stream, "utf-8", "");
Elements elements = doc.select("html>body>dl>dt");
for (int i = 0, length = elements.size(); i < length; i++) {
dealBookmark(userId, elements.get(i), path, sortBase + i, bookmarks);
}
}

//每一千条处理插入一次,批量更新搜索字段
List<Bookmark> tempList = new ArrayList<>(1000);
for (int i = 0; i < bookmarks.size(); i++) {
Expand Down Expand Up @@ -151,6 +162,57 @@ private void dealBookmark(int userId, Element ele, String path, int sort, List<B
}
}

/**
* 处理oneenv的导出
*
* @param bookmarks 书签列表
* @param userId 用户id
* @param file file
* @param path path
* @param sort sort
*/
private void readFromOneEnv(List<Bookmark> bookmarks, int userId, MultipartFile file, String path, int sort) {
String filePath = CommonConstant.fileSavePath + "/files/" + IdUtil.simpleUUID() + ".db3";
try {
file.transferTo(FileUtil.newFile(filePath));
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:" + filePath)) {
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select * from on_categorys");
Map<Long, Bookmark> folderMap = new HashMap<>();
Map<Long, Integer> childSortBaseMap = new HashMap<>();
while (rs.next()) {
long addTime = rs.getLong("add_time");
Bookmark folder = new Bookmark(userId, path, StrUtil.nullToEmpty(rs.getString("name")), addTime == 0 ? System.currentTimeMillis() : addTime * 1000, sort++);
int childSortBase = 0;
if (insertOne(folder)) {
childSortBase = ObjectUtil.defaultIfNull(bookmarkDao.selectMaxSort(userId, path), 0);
}
long id = rs.getLong("id");
folderMap.put(id, folder);
childSortBaseMap.put(id, childSortBase);
}
rs.close();
rs = stat.executeQuery("select * from on_links");
while (rs.next()) {
long fId = rs.getLong("fid");
long addTime = rs.getLong("add_time");
int tempSort = childSortBaseMap.get(fId);
childSortBaseMap.put(fId, tempSort + 1);
Bookmark folder = folderMap.get(fId);
String curPath = folder == null ? "" : folder.getPath() + "." + folder.getBookmarkId();
Bookmark bookmark = new Bookmark(userId, curPath, StrUtil.nullToEmpty(rs.getString("title"))
, StrUtil.nullToEmpty(rs.getString("url")), "", addTime == 0 ? System.currentTimeMillis() : addTime * 1000, tempSort);
bookmarks.add(bookmark);
insertOne(bookmark);
}
rs.close();
stat.close();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}

/**
* Description: 插入一条书签,如果已经存在同名书签将跳过
*
Expand Down Expand Up @@ -288,7 +350,7 @@ public void updateUserBookmarkIcon(int userId) {
int size = 100;
int start = 0;
List<Bookmark> deal;
while ((deal = bookmarkDao.selectUserNoIcon(userId, start, size)).size() > 0) {
while (!(deal = bookmarkDao.selectUserNoIcon(userId, start, size)).isEmpty()) {
start += size;
deal.forEach(item -> {
String icon = getIconPath(item.getUrl(), null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fanxb.bookmark.common.constant.CommonConstant;
import com.fanxb.bookmark.common.constant.NumberConstant;
import com.fanxb.bookmark.common.constant.RedisConstant;
import com.fanxb.bookmark.common.dao.GlobalConfigDao;
Expand All @@ -12,11 +15,16 @@
import com.fanxb.bookmark.common.service.ConfigService;
import com.fanxb.bookmark.common.util.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -61,21 +69,23 @@ public String getCacheBingImg() {
return str;
}
str = getBingImg();
if (str != null) {
stringRedisTemplate.opsForValue().set(RedisConstant.BING_IMG, str, 2, TimeUnit.HOURS);
}
stringRedisTemplate.opsForValue().set(RedisConstant.BING_IMG, str, 2, TimeUnit.HOURS);
return str;
}

private String getBingImg() {
try {
JSONObject bingObj = HttpUtil.getObj(bingHost + bingUrl, null, false);
String path = bingObj.getJSONArray("images").getJSONObject(0).getString("url");
return bingHost + path;
JSONObject bingObj = HttpUtil.getObj(bingHost + bingUrl, null, false);
String path = bingObj.getJSONArray("images").getJSONObject(0).getString("url");
String picUrl = bingHost + path;
Request request = new Request.Builder().url(picUrl).build();
try (Response res = HttpUtil.getClient(false).newCall(request).execute()) {
byte[] bytes = res.body().bytes();
String filePath = CommonConstant.fileSavePath + "/files/public/bing.jpg";
FileUtil.writeBytes(bytes, filePath);
} catch (Exception e) {
log.error("获取bing每日一图错误:{}", e.getLocalizedMessage(), e);
}
return null;
return "/files/public/bing.jpg";
}


Expand Down
12 changes: 11 additions & 1 deletion bookmark_front/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@

<script>
export default {
name: "App"
name: "App",
mounted() {
window.qieziStatisticKey = "b74c4b571b644782a837433209827874";
let script = document.createElement("script");
script.type = "text/javascript";
script.defer = true;
script.src = "https://qiezi.fleyx.com/qiezijs/1.0/qiezi_statistic.min.js";
document.getElementsByTagName("head")[0].appendChild(script);
}
};
</script>

<style lang="less">
@import "./global.less";
html,
body {
margin: 0;
Expand All @@ -20,6 +29,7 @@ body {
background-color: @bgColor;
height: initial;
}
#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
Expand Down
1 change: 1 addition & 0 deletions bookmark_front/src/components/main/things/AddBookmark.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:data="{ path: form.path }"
:headers="{ 'jwt-token': token }"
action="/bookmark/api/bookmark/uploadBookmarkFile"
accept=".html,.db3"
@change="fileChange"
>
<p class="ant-upload-drag-icon">
Expand Down
Loading

0 comments on commit 44c1ca9

Please sign in to comment.