mirror of
https://github.com/Kakune55/Pixel.git
synced 2025-05-07 02:39:25 +08:00
Compare commits
5 Commits
v1.0-beta1
...
main
Author | SHA1 | Date | |
---|---|---|---|
03bd11a2bb | |||
cb2a49e3c9 | |||
17f94c0a94 | |||
5d4580cbf7 | |||
3496861362 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/data
|
/data
|
||||||
user.json
|
user.json
|
||||||
|
自动交叉编译.cmd
|
||||||
|
5
Dockerfile
Normal file
5
Dockerfile
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
FROM debian
|
||||||
|
ADD ./ /app
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 9090
|
||||||
|
ENTRYPOINT ["/app/main"]
|
31
README.md
31
README.md
@ -17,11 +17,40 @@
|
|||||||
- /idlist 列出所有图片id
|
- /idlist 列出所有图片id
|
||||||
|
|
||||||
## 部分接口文档
|
## 部分接口文档
|
||||||
### `/img` `/img/mini` `/del` `/info`
|
### `/img` `/del` `/info`
|
||||||
#### 请求方式
|
#### 请求方式
|
||||||
Get
|
Get
|
||||||
#### 请求参数
|
#### 请求参数
|
||||||
id 图片id
|
id 图片id
|
||||||
|
|
||||||
|
### `/img/mini`
|
||||||
|
#### 请求方式
|
||||||
|
Get
|
||||||
|
#### 请求参数
|
||||||
|
id 图片id
|
||||||
|
size 图片横向大小 单位像素 0-1024
|
||||||
|
|
||||||
## 使用的外部库
|
## 使用的外部库
|
||||||
"github.com/disintegration/imaging" MIT LICENSE
|
"github.com/disintegration/imaging" MIT LICENSE
|
||||||
|
|
||||||
|
# 部署
|
||||||
|
## 直接部署
|
||||||
|
- 确保本机拥有go环境
|
||||||
|
- 确保网络良好
|
||||||
|
~~~bash
|
||||||
|
git clone https://github.com/Kakune55/Pixel.git #克隆存储库
|
||||||
|
cd ./Pixel #进入工作目录
|
||||||
|
go build main.go #编译
|
||||||
|
./main #运行
|
||||||
|
~~~
|
||||||
|
## 使用Docker (仅支持Linux-X86_64)
|
||||||
|
### 导入镜像
|
||||||
|
~~~bash
|
||||||
|
wget https://github.com/Kakune55/Pixel/releases/download/v1.0/pixel.tar.gz #版本号仅供参考
|
||||||
|
tar -zxvf pixel.tar.gz #解压
|
||||||
|
docker load pixel.tar #导入镜像
|
||||||
|
~~~
|
||||||
|
### 运行容器
|
||||||
|
~~~bash
|
||||||
|
docker run -d -p <你需要的端口号>:9090 --name:pixel pixel
|
||||||
|
~~~
|
@ -68,7 +68,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#imgshow {
|
#imgshow {
|
||||||
width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#delete-button {
|
#delete-button {
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
galleryItem.classList.add("gallery-item");
|
galleryItem.classList.add("gallery-item");
|
||||||
|
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
img.src = `/img/mini?id=${id}`;
|
img.src = `/img/mini?id=${id}&size=192`;
|
||||||
|
|
||||||
const infoBox = document.createElement("div");
|
const infoBox = document.createElement("div");
|
||||||
infoBox.classList.add("info-box");
|
infoBox.classList.add("info-box");
|
||||||
|
@ -217,3 +217,36 @@ func CheckUserPasswd(username string, password string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetFileLinkID(md5in string) string {
|
||||||
|
db, err := sql.Open("sqlite3", "./data/database.db")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
|
||||||
|
// SQL语句
|
||||||
|
SQL := `
|
||||||
|
SELECT * FROM "mytable" WHERE md5 = ?
|
||||||
|
`
|
||||||
|
|
||||||
|
row := db.QueryRow(SQL,md5in)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 扫描查询结果
|
||||||
|
var md5 string
|
||||||
|
var linkID string
|
||||||
|
var ext string
|
||||||
|
err = row.Scan(&linkID,&md5,&ext)
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
return ""
|
||||||
|
} else {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return linkID
|
||||||
|
}
|
15
main.go
15
main.go
@ -130,6 +130,12 @@ func upload(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
md5sum := fmt.Sprintf("%x", h.Sum(nil))
|
md5sum := fmt.Sprintf("%x", h.Sum(nil))
|
||||||
|
|
||||||
|
oldLinkID := database.GetFileLinkID(md5sum)
|
||||||
|
if oldLinkID != "" {
|
||||||
|
w.Write([]byte(oldLinkID))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// 获取文件扩展名
|
// 获取文件扩展名
|
||||||
fname := handler.Filename
|
fname := handler.Filename
|
||||||
ext := path.Ext(fname)
|
ext := path.Ext(fname)
|
||||||
@ -227,6 +233,13 @@ func generateThumbnail(filePath string, width, height int) (*image.NRGBA, error)
|
|||||||
func displayThumbnailHandler(w http.ResponseWriter, r *http.Request) {
|
func displayThumbnailHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// 获取请求参数,例如文件名
|
// 获取请求参数,例如文件名
|
||||||
filename := r.FormValue("id")
|
filename := r.FormValue("id")
|
||||||
|
imgsize, err := strconv.Atoi(r.FormValue("size"))
|
||||||
|
if err != nil {
|
||||||
|
http.Error(w, "size参数错误 应为纯数字", http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
if imgsize <= 1 || imgsize > 1024 {
|
||||||
|
http.Error(w, "size参数错误 范围应在0-1024之间", http.StatusBadRequest)
|
||||||
|
}
|
||||||
if filename == "" {
|
if filename == "" {
|
||||||
http.Error(w, "未提供文件名", http.StatusBadRequest)
|
http.Error(w, "未提供文件名", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
@ -236,7 +249,7 @@ func displayThumbnailHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
filePath := filepath.Join("./data/img", database.GetFileName(filename))
|
filePath := filepath.Join("./data/img", database.GetFileName(filename))
|
||||||
|
|
||||||
// 生成缩略图
|
// 生成缩略图
|
||||||
thumbnail, err := generateThumbnail(filePath, 128, 0) // 设置缩略图的宽度和高度
|
thumbnail, err := generateThumbnail(filePath, imgsize, 0) // 设置缩略图的宽度和高度
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "无法生成缩略图", http.StatusInternalServerError)
|
http.Error(w, "无法生成缩略图", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user