From 9c1a1bd59d1400a5ed854dc7910aff5caba05a86 Mon Sep 17 00:00:00 2001 From: "453530270@qq.com" Date: Thu, 2 May 2024 19:43:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=81=8D=E5=8E=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/init.sh | 46 ++++++++++++++++ .../xtfs/jwebfs/api/ApWbFileController.java | 53 +++++++++++++++++++ .../java/io/xtfs/jwebfs/utils/AjaxResult.java | 12 +++++ .../java/io/xtfs/jwebfs/utils/FsUtils.java | 41 ++++++++++++++ .../io/xtfs/jwebfs/web/WbFileController.java | 4 +- src/test/java/io/xtfs/jwebfs/Fstest.java | 19 +++++++ wbfs.sh | 19 +++---- 7 files changed, 184 insertions(+), 10 deletions(-) create mode 100644 sh/init.sh create mode 100644 src/main/java/io/xtfs/jwebfs/api/ApWbFileController.java create mode 100644 src/main/java/io/xtfs/jwebfs/utils/FsUtils.java create mode 100644 src/test/java/io/xtfs/jwebfs/Fstest.java diff --git a/sh/init.sh b/sh/init.sh new file mode 100644 index 0000000..547d926 --- /dev/null +++ b/sh/init.sh @@ -0,0 +1,46 @@ +#! /bin/bash +# 监视目录 +webroot="/root/demo" + + +cp /dev/null rsync_file +# 判断是否存在 +if [ !-f file.x01 ];then + find $webroot -type f -exec md5sum {} \; >>file.x01 +else + # 新文件 + for newfile in $(find $webroot -type f) + do + grep $newfile file.x01 >/dev/null 2>&1 + if [ $? -gt 0 ];then + mdval = $(md5sum $newfile) + # mdval = md5sum $newfile >> file.md5 + # 拼装POST json + # ret = curl --location 'http://192.168.66.180/api/notify' --header 'Content-Type:application/json' -data '{"filename":"$newfile","filehash":"$mdval"}' + + # echo "$newfile" + echo "$ret\r\n" + fi + done +fi + + +#!/bin/bash + +A="a a" +B="bb" + +read -r -d '' PAYLOAD <<-EOM +{ + "A": "${A}", + "B": "${B}" +} +EOM + +#PAYLOAD=$(echo $PAYLOAD | jq -c .) + PAYLOAD=$(jq -c . <<<${PAYLOAD}) + + +CMD="curl --noproxy '*' -d '${PAYLOAD}' http://localhost:8080/path/url" +echo ${CMD} +eval ${CMD} \ No newline at end of file diff --git a/src/main/java/io/xtfs/jwebfs/api/ApWbFileController.java b/src/main/java/io/xtfs/jwebfs/api/ApWbFileController.java new file mode 100644 index 0000000..f2f24fd --- /dev/null +++ b/src/main/java/io/xtfs/jwebfs/api/ApWbFileController.java @@ -0,0 +1,53 @@ +package io.xtfs.jwebfs.api; + +import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import io.xtfs.jwebfs.service.WbFileService; +import io.xtfs.jwebfs.utils.AjaxResult; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.HashMap; +import java.util.Map; + +@RestController +@RequestMapping("/api") +public class ApWbFileController { + private static final Log log = LogFactory.getLog(ApWbFileController.class); + @Autowired + private WbFileService wbFileService; + + /** + * 提醒JSON + * @param reqstr + * @return + */ + @PostMapping("/notify") + public int notify(@RequestBody String reqstr){ + if(StringUtils.isNotBlank(reqstr)){ + log.info("post string:"+reqstr); + Map rtmap = new HashMap(); + JSONObject json = JSONObject.parseObject(reqstr); + log.info("your json :"+json); + return 1; + } + return 0; + } + + /** + * help + * @return + */ + @RequestMapping("/help") + public JSONObject help(){ + Map rmap = new HashMap(); + rmap.put("curts",System.currentTimeMillis()); + return AjaxResult.success("success",rmap); + } +} diff --git a/src/main/java/io/xtfs/jwebfs/utils/AjaxResult.java b/src/main/java/io/xtfs/jwebfs/utils/AjaxResult.java index 831265d..c96f9b4 100644 --- a/src/main/java/io/xtfs/jwebfs/utils/AjaxResult.java +++ b/src/main/java/io/xtfs/jwebfs/utils/AjaxResult.java @@ -35,4 +35,16 @@ public class AjaxResult { jsonObject.put("data",dlist); return jsonObject; } + + /** + * 显示字符串 + * @param msg + * @return + */ + public static JSONObject success(String msg){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("code",0); + jsonObject.put("msg",msg); + return jsonObject; + } } diff --git a/src/main/java/io/xtfs/jwebfs/utils/FsUtils.java b/src/main/java/io/xtfs/jwebfs/utils/FsUtils.java new file mode 100644 index 0000000..fac452c --- /dev/null +++ b/src/main/java/io/xtfs/jwebfs/utils/FsUtils.java @@ -0,0 +1,41 @@ +package io.xtfs.jwebfs.utils; + +import java.io.File; +import java.util.List; + +public class FsUtils { + /** + * 遍历文件 +// * @param wpath + * @return + */ +// public static List foldWalk(String wpath){ +// if(wpath){ +// +// } +// } + + /** + * 遍历文件 + * @param dir + */ + public static void ListFiles(File dir){ + if(!dir.exists()||!dir.isDirectory())return; + + String []files = dir.list();//通过初始化数组列表遍历 + for(int i=0; i" + ); + ListFiles(file);//对于子目录,进行递归调用。 + } + } + } + +} diff --git a/src/main/java/io/xtfs/jwebfs/web/WbFileController.java b/src/main/java/io/xtfs/jwebfs/web/WbFileController.java index bb2855a..eefae19 100644 --- a/src/main/java/io/xtfs/jwebfs/web/WbFileController.java +++ b/src/main/java/io/xtfs/jwebfs/web/WbFileController.java @@ -63,9 +63,11 @@ public class WbFileController { * @param reqstr * @return */ + @ResponseBody @PostMapping("/notify") public int add(@RequestBody String reqstr){ - log.info("notify:"+reqstr); + JSONObject json = JSONObject.parseObject(reqstr); + log.info("notify:"+json); return 1; } } diff --git a/src/test/java/io/xtfs/jwebfs/Fstest.java b/src/test/java/io/xtfs/jwebfs/Fstest.java new file mode 100644 index 0000000..5ca5849 --- /dev/null +++ b/src/test/java/io/xtfs/jwebfs/Fstest.java @@ -0,0 +1,19 @@ +package io.xtfs.jwebfs; + +import io.xtfs.jwebfs.utils.FsUtils; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.io.File; + +@SpringBootTest +@RunWith(SpringJUnit4ClassRunner.class) +public class Fstest { + @Test + public void dirloop(){ + File dir = new File("D:\\xworks\\boyu"); + FsUtils.ListFiles(dir); + } +} diff --git a/wbfs.sh b/wbfs.sh index 44f63bc..1e79754 100644 --- a/wbfs.sh +++ b/wbfs.sh @@ -1,11 +1,11 @@ #! /bin/bash -webroot="/home/www/" +webroot="/root/demo" cp /dev/null rsync_file -if [ ! -f file.md5 ];then - find $webroot -type f -exec md5sum {} \; >>file.md5 +if [ !-f file.md5 ];then + find $webroot -type f -exec md5sum {} \; >>file.md5 else - for file in $(md5sum -c file.md5|awk -F':' '/FAILED/{print $1}') - do + for file in $(md5sum -c file.md5|awk -F':' '/FAILED/{print $1}') + do if [ -f $file ];then filename_z=$(echo $file|sed 's#/#\\/#g') sed -i "/ $filename_z/"d file.md5 @@ -23,8 +23,9 @@ else echo "$newfile" >> rsync_file fi done -for rfile in $(cat rsync_file) -do -rsync -avzp $rfile /home/www3/ -done + # 文件同步 + for rfile in $(cat rsync_file) + do + rsync -avzp $rfile /home/www3/ + done fi \ No newline at end of file