-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from helloxz/dev
Dev
- Loading branch information
Showing
24 changed files
with
6,422 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Zdir | ||
|
||
使用Golang + Vue3开发的轻量级目录列表程序,支持Linux、Docker、Windows部署,适合个人或初创公司文件分享使用,亦可作为轻量级网盘使用。 | ||
|
||
![](https://img.rss.ink/imgs/2022/10/17/10d74765a20fdc7a.png) | ||
|
||
## 功能特点 | ||
|
||
- [x] 目录列表 | ||
- [x] MarkDown预览 | ||
- [x] 支持搜索当前目录与全局搜索(备注:全局搜索仅Linux支持) | ||
- [x] 视频预览(支持H.264编码的`.mp4`格式及`.m3u8`) | ||
- [x] 音频预览 | ||
- [x] 图片预览 | ||
- [x] 代码与文本预览,支持部分代码高亮 | ||
- [x] CSS/JavaScript一键复制 | ||
- [x] Office在线预览(支持.doc .docx .xls .xlsx .ppt .pptx),**注意:如果是内网或IP访问或非标准多端口方式不支持预览** | ||
- [x] 二维码生成 | ||
- [x] 支持中文显示 | ||
- [x] 支持Linux、Docker、Windows等多种部署方式 | ||
- [ ] 后台管理(站点信息设置等) | ||
- [ ] 文件管理(上传、删除、编辑、复制、移动) | ||
- [ ] 私有文件 | ||
- [ ] 私有文件分享 | ||
- [ ] 音乐播放列表 | ||
|
||
## 快速开始 | ||
|
||
**Linux一键安装:** | ||
|
||
如果您想快速安装Zdir,可以使用Zdir官方提供的一键安装脚本,只需要执行下面的命令: | ||
|
||
```bash | ||
# CentOS系统 | ||
yum -y install curl | ||
curl "http://soft.xiaoz.org/zdir/sh/zir.sh" | bash -s install | ||
# Debian or Ubuntu系统 | ||
apt-get install curl | ||
curl "http://soft.xiaoz.org/zdir/sh/zir.sh" | bash -s install | ||
``` | ||
|
||
* 默认安装路径为:`/data/apps/zdir` | ||
* 需要公开的文件列表路径位于`/data/apps/zdir/data/public` | ||
|
||
安装完毕后访问`http://IP:6080`即可 | ||
|
||
___ | ||
|
||
一键安装脚本适合对Linux系统不太熟悉或者想快速体验Zdir的朋友,您可以参考帮助文档:[https://doc.xiaoz.me/books/zdir-3](https://doc.xiaoz.me/books/zdir-3) 获取更多安装方式。 | ||
|
||
## 文档 & Demo | ||
|
||
* 帮助文档:[https://doc.xiaoz.me/books/zdir-3](https://doc.xiaoz.me/books/zdir-3) | ||
* Demo:[http://soft.xiaoz.org/](http://soft.xiaoz.org/) | ||
|
||
## 问题反馈 | ||
|
||
* 论坛:[https://xiawen.cc/t/zdir](https://xiawen.cc/t/zdir) | ||
* QQ:446199062 | ||
* QQ群:932795364 | ||
* TG:xiaozme | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"runtime" | ||
) | ||
|
||
// 命令行初始化 | ||
func Init() { | ||
//检查配置文件是否存在,如果存在了,则不进行初始化 | ||
_, err := os.Stat("data/config.ini") | ||
//返回的error为空,说明文件存在,存在则不允许再次初始化 | ||
if err == nil { | ||
fmt.Printf("Initialization failed, the configuration file already exists.\n") | ||
os.Exit(1) | ||
} else { | ||
//复制配置文件,参考:https://juejin.cn/post/6951352094003560484 | ||
|
||
//打开源文件 | ||
source, s_error := os.Open("config.simple.ini") | ||
if s_error != nil { | ||
fmt.Printf("s%\n", s_error) | ||
os.Exit(1) | ||
} | ||
|
||
//创建目标文件 | ||
target, t_error := os.Create("data/config.ini") | ||
if t_error != nil { | ||
fmt.Printf("%s\n", t_error) | ||
os.Exit(1) | ||
} | ||
|
||
//关闭文件句柄 | ||
defer source.Close() | ||
defer target.Close() | ||
|
||
//拷贝文件 | ||
_, e := io.Copy(target, source) | ||
|
||
if e != nil { | ||
fmt.Printf("Failed to copy the configuration file, please check the permissions.\n") | ||
os.Exit(1) | ||
} else { | ||
//文件拷贝成功,继续执行初始化命令 | ||
sysType := runtime.GOOS | ||
|
||
//注册windows服务 | ||
if sysType == "windows" { | ||
windows_service() | ||
fmt.Printf("Init success.\n") | ||
} else if sysType == "linux" { | ||
linux_service() | ||
fmt.Printf("Init success.\n") | ||
} else { | ||
fmt.Printf("The current system does not support.\n") | ||
os.Exit(1) | ||
} | ||
} | ||
} | ||
//根据操作系统执行不同的命令 | ||
} | ||
|
||
// linux添加服务 | ||
func linux_service() { | ||
_, err := exec.Command("bash", "sh/reg_service.sh").Output() | ||
|
||
if err != nil { | ||
fmt.Printf("Failed to register for the service\n") | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// windows添加服务 | ||
func windows_service() { | ||
//注册服务 | ||
_, err1 := exec.Command("./run.exe", "install").Output() | ||
//运行服务 | ||
//_, err2 := exec.Command("./run.exe", "start").Output() | ||
|
||
if err1 != nil { | ||
fmt.Printf("Failed to register for the service\n") | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package cli | ||
|
||
import "fmt" | ||
|
||
func GetVersion() { | ||
fmt.Printf("Release 3.0.0\n") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/bin/bash | ||
##### name:编译并打包zdir ##### | ||
|
||
#编译linux | ||
compile_linux() { | ||
rm -rf *.tar.gz *.exe | ||
#编译程序 | ||
go env -w CGO_ENABLED=0 | ||
go env -w GOOS=linux | ||
go env -w GOARCH=amd64 | ||
#删除原有的编译文件 | ||
rm -rf main zdir | ||
|
||
go build -ldflags -w main.go | ||
|
||
#压缩程序 | ||
upx -9 main | ||
#重命名程序 | ||
mv main zdir | ||
tar -zcvf zdir_3.0.0_linux_amd64.tar.gz --exclude=.gitignore --exclude=docker --exclude=.git --exclude=*.gz --exclude=cli --exclude=config --exclude=controller --exclude=data/public/* --exclude=logs/* --exclude=router --exclude=compile.sh --exclude=config.ini --exclude=go.mod --exclude=go.sum --exclude=main.go --exclude=run.* --exclude=zdir.exe . | ||
echo "Compiled successfully.(Linux)" | ||
reset_golang_env | ||
} | ||
|
||
# 编译Windows | ||
compile_windows() { | ||
rm -rf *.tar.gz | ||
#编译程序 | ||
go env -w CGO_ENABLED=0 | ||
go env -w GOOS=windows | ||
go env -w GOARCH=amd64 | ||
|
||
#删除原有的编译文件 | ||
rm -rf main.exe zdir.exe | ||
|
||
go build -ldflags -w main.go | ||
#压缩程序 | ||
upx -9 main.exe | ||
#重命名程序 | ||
mv main.exe zdir.exe | ||
#打包程序 | ||
tar -zcvf zdir_3.0.0_windows_amd64.tar.gz --exclude=.gitignore --exclude=docker --exclude=.git --exclude=sh --exclude=*.gz --exclude=cli --exclude=config --exclude=controller --exclude=data/public/* --exclude=logs/* --exclude=router --exclude=compile.sh --exclude=config.ini --exclude=go.mod --exclude=go.sum --exclude=main.go --exclude=zdir . | ||
echo "Compiled successfully.(Windows)" | ||
reset_golang_env | ||
} | ||
|
||
# 重置为默认变量 | ||
reset_golang_env() { | ||
go env -w CGO_ENABLED=0 | ||
go env -w GOOS=linux | ||
go env -w GOARCH=amd64 | ||
} | ||
|
||
case $1 in | ||
linux) | ||
compile_linux | ||
;; | ||
windows) | ||
compile_windows | ||
;; | ||
*) | ||
echo "Parameter error!" | ||
;; | ||
esac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# 服务端设置 | ||
[servers] | ||
port = :6080 | ||
RunMode = release | ||
|
||
# 存储设置 | ||
[storages] | ||
public_path = data/public | ||
public_domain = | ||
|
||
# 站点信息设置 | ||
[sites] | ||
title = Zdir | ||
name = Zdir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gopkg.in/ini.v1" | ||
) | ||
|
||
func Load_ini() *ini.File { | ||
//载入配置文件 | ||
cfg, err := ini.Load("data/config.ini") | ||
//如果载入配置出错,则终止执行 | ||
if err != nil { | ||
fmt.Printf("Fail to read file: %v", err) | ||
os.Exit(1) | ||
} | ||
return cfg | ||
} | ||
|
||
// 返回公共存储的路径 | ||
func Public_path() string { | ||
//载入配置文件,通过cfg调用 | ||
cfg := Load_ini() | ||
dir := cfg.Section("storages").Key("public_path").String() | ||
return dir | ||
} | ||
|
||
// 返回公共存储的域名 | ||
func Public_domain() string { | ||
//载入配置文件,通过cfg调用 | ||
cfg := Load_ini() | ||
domain := cfg.Section("storages").Key("public_domain").String() | ||
return domain | ||
} | ||
|
||
// 返回端口 | ||
func Listen() string { | ||
//载入配置文件,通过cfg调用 | ||
cfg := Load_ini() | ||
info := cfg.Section("servers").Key("port").String() | ||
return info | ||
} | ||
|
||
// 返回gin运行模式 | ||
func RunMode() string { | ||
//载入配置文件,通过cfg调用 | ||
cfg := Load_ini() | ||
info := cfg.Section("servers").Key("RunMode").String() | ||
return info | ||
} | ||
|
||
// 返回站点信息 | ||
func Site_info() (string, string) { | ||
//载入配置文件,通过cfg调用 | ||
cfg := Load_ini() | ||
title := cfg.Section("sites").Key("title").String() | ||
name := cfg.Section("sites").Key("name").String() | ||
|
||
return title, name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package controller | ||
|
||
import ( | ||
"zdir/config" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// 定义一个结构体,用来存放文件或文件夹信息 | ||
type storages struct { | ||
Public_domain string | ||
} | ||
|
||
// 定义一个结构体,用来存放站点信息 | ||
type sites struct { | ||
Title string | ||
Name string | ||
} | ||
|
||
// 定义一个结构体,用来返回综合信息 | ||
type appinfos struct { | ||
Storage storages | ||
Site sites | ||
} | ||
|
||
func GetAppInfo(c *gin.Context) { | ||
var storage storages | ||
|
||
// 载入配置文件,通过cfg调用 | ||
cfg = config.Load_ini() | ||
//从配置文件获取存储域名 | ||
public_domain := config.Public_domain() | ||
|
||
//获取请求host | ||
host := c.Request.Host | ||
|
||
//如果存储域名为空,则使用请求host作为存储域名 | ||
if public_domain == "" { | ||
storage.Public_domain = "http://" + host + "/public" | ||
} else { | ||
storage.Public_domain = public_domain | ||
} | ||
|
||
//声明结构体 | ||
var site sites | ||
//获取站点信息 | ||
site.Title, site.Name = config.Site_info() | ||
|
||
//声明一个map | ||
var appinfo appinfos | ||
appinfo.Storage = storage | ||
appinfo.Site = site | ||
|
||
c.JSON(200, gin.H{ | ||
"code": 200, | ||
"msg": "success", | ||
"data": appinfo, | ||
}) | ||
} |
Oops, something went wrong.