Skip to content

Commit

Permalink
Merge pull request #81 from helloxz/dev
Browse files Browse the repository at this point in the history
3.1.1
  • Loading branch information
helloxz authored Oct 31, 2022
2 parents 128e043 + 62915fe commit 7386526
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 50 deletions.
2 changes: 1 addition & 1 deletion cli/Version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package cli
import "fmt"

func GetVersion() {
fmt.Printf("Release 3.1.0\n")
fmt.Printf("Release 3.1.1\n")
}
2 changes: 1 addition & 1 deletion compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ OS=$1
ARCH=$2

#Zdir版本号
VERSION=3.1.0
VERSION=3.1.1

#编译linux
compile_linux() {
Expand Down
11 changes: 7 additions & 4 deletions controller/DeleteFile.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controller

import (
"fmt"
"os"
"zdir/config"

Expand Down Expand Up @@ -36,8 +37,8 @@ func Delete_File(c *gin.Context) {
c.Abort()
return
}
//判断文件是否存在
if !V_is_file(full_path) {
//判断文件或文件夹是否存在
if !V_is_path(full_path) {
c.JSON(200, gin.H{
"code": -1000,
"msg": "文件路径不存在!",
Expand All @@ -49,15 +50,17 @@ func Delete_File(c *gin.Context) {

//上述验证通过,执行文件删除

err := os.Remove(full_path)
err := os.RemoveAll(full_path)

//如果删除失败
if err != nil {
c.JSON(200, gin.H{
"code": -1000,
"msg": "文件删除失败!",
"data": err,
"data": "",
})
//打印错误日志
fmt.Println(err)
c.Abort()
return
} else {
Expand Down
22 changes: 22 additions & 0 deletions controller/FileInfo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package controller

import (
"crypto/md5"
"encoding/hex"
"fmt"
"io"
"log"
"os"
"strings"
Expand All @@ -16,6 +20,7 @@ type finfo struct {
Mtime string
Fpath string
Ext string
Md5 string
}

func FileInfo(c *gin.Context) {
Expand Down Expand Up @@ -80,6 +85,8 @@ func FileInfo(c *gin.Context) {
new_info.Name = finfo.Name()
//获取路径
new_info.Fpath = fpath
//获取MD5
new_info.Md5 = GetFileMd5(full_path)
c.JSON(200, gin.H{
"code": 200,
"msg": "success",
Expand All @@ -90,3 +97,18 @@ func FileInfo(c *gin.Context) {

}
}

// 获取文件的md5码,来自:https://blog.csdn.net/yzf279533105/article/details/106305721
func GetFileMd5(fpath string) string {

pFile, err := os.Open(fpath)
if err != nil {
fmt.Println("打开文件失败!")
return ""
}
defer pFile.Close()
md5h := md5.New()
io.Copy(md5h, pFile)

return hex.EncodeToString(md5h.Sum(nil))
}
4 changes: 2 additions & 2 deletions controller/Rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func RenameFile(c *gin.Context) {
old_path := public_dir + fpath + old_name
new_path := public_dir + fpath + new_name
//判断原文件是否存在
if !V_is_file(old_path) {
if !V_is_path(old_path) {
c.JSON(200, gin.H{
"code": -1000,
"msg": "文件路径不存在!",
Expand Down Expand Up @@ -91,7 +91,7 @@ func RenameFile(c *gin.Context) {
c.JSON(200, gin.H{
"code": -1000,
"msg": "文件重命名失败!",
"data": err,
"data": "",
})
fmt.Println(err)
c.Abort()
Expand Down
14 changes: 14 additions & 0 deletions controller/Verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ func V_is_file(fpath string) bool {
}
}

// 验证是否是文件或文件夹
func V_is_path(fpath string) bool {
//获取文件信息
_, err := os.Stat(fpath)

//如果读取文件出现错误,比如不存在的情况,返回false
if err != nil {
return false
} else {
//文件和文件夹视为有效路径
return true
}
}

// 验证搜索名称
func V_search_name(name string) bool {
//正则验证,不能包含.. | & * exec --
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions data/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Zdir</title>
<script type="module" crossorigin src="/assets/index.e099be15.js"></script>
<link rel="stylesheet" href="/assets/index.cbbaaf3f.css">
<script type="module" crossorigin src="/assets/index.4bbbb634.js"></script>
<link rel="stylesheet" href="/assets/index.70b4fc0e.css">
</head>
<body>
<div id="app"></div>
Expand Down
13 changes: 11 additions & 2 deletions docker/install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

VERSION=3.1.0
VERSION=3.1.1

# 初始化环境
init() {
Expand Down Expand Up @@ -28,7 +28,7 @@ init() {
download(){
cd /root && mkdir zdir && cd zdir
name=zdir_${VERSION}_linux_amd64.tar.gz
wget https://soft.xiaoz.org/zdir/${name}
wget https://soft.xiaoz.org/zdir/${VERSION}/${name}

#解压
tar -xvf ${name}
Expand All @@ -39,6 +39,15 @@ download(){
#删除压缩文件
rm -rf /root/${name}
rm -rf /data/apps/zdir/*.tar.gz

# 下载ARM架构
cd /tmp && mkdir zdir && cd zdir
name=zdir_${VERSION}_linux_arm64.tar.gz
wget https://soft.xiaoz.org/zdir/${VERSION}/${name}
#解压
tar -xvf ${name}
#拷贝文件
cp -ar /tmp/zdir/zdir /data/apps/zdir/zdir_arm64
}


Expand Down
9 changes: 8 additions & 1 deletion docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ check_dir() {
# 运行zdir
run() {
cd /data/apps/zdir/
./zdir start
# 判断架构
get_arch=$(arch)
if [[ "${get_arch}" == "x86_64" ]]
then
./zdir start
else
./zdir_arm64 start
fi
}

check_dir && run
7 changes: 3 additions & 4 deletions router/routers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package router

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -42,9 +41,9 @@ func check_auth() gin.HandlerFunc {
token := string(headers["X-Token"][0])
//获取内存
get_token := string(controller.GetCache(cid))
fmt.Println(headers)
fmt.Println("这是header获取的:" + token)
fmt.Println("这是内存获取的:" + get_token)
// fmt.Println(headers)
// fmt.Println("这是header获取的:" + token)
// fmt.Println("这是内存获取的:" + get_token)

if token == get_token {
c.Next()
Expand Down
4 changes: 3 additions & 1 deletion sh/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ check(){
upgrade(){
# 下载对应版本
cd $zdir_path
#删除原有的压缩包
rm -rf *.tar.gz
name=zdir_${VERSION}_linux_amd64.tar.gz
wget https://soft.xiaoz.org/zdir/${name}
wget https://soft.xiaoz.org/zdir/${VERSION}/${name}

#停止Zdir
systemctl stop zdir
Expand Down
2 changes: 1 addition & 1 deletion sh/zdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##### name:Zdir一键安装脚本 #####

#声明Zdir版本
VERSION="3.1.0"
VERSION="3.1.1"

#检查是否已经安装过
is_install() {
Expand Down

0 comments on commit 7386526

Please sign in to comment.