Skip to content

Commit

Permalink
Merge pull request #39 from libsgh/dev
Browse files Browse the repository at this point in the history
v2.0.0
  • Loading branch information
libsgh authored Jun 4, 2021
2 parents 39e1a05 + b579a5d commit 5a616a5
Show file tree
Hide file tree
Showing 39 changed files with 1,031 additions and 142 deletions.
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
[![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy?template=https://github.com/libsgh/PanIndex)

## 简单的网盘目录列表
- [x] cookie登录
- [x] 本地模式,天翼云网盘,teambition网盘
- [x] 下载直链
- [x] 跨平台、易部署
- [x] 多模式,多账户
- [x] 多主题
- [x] 下载直链
- [x] 防盗链
- [x] 文件夹打包下载(天翼云)
- [x] 图片、视频、office文件在线预览
- [x] 定时缓存文件及目录信息(每小时同步一次)
- [x] 定时同步cookie(每天8点)
- [x] heroku防止休眠(每5分钟访问一次应用)

## 示例
- [https://pan.noki.top](https://pan.noki.top "https://pan.noki.top")
- [开发版-测试,演示](https://t1.netrss.cf "https://t1.netrss.cf")
- [在线演示](https://t1.netrss.cf "https://t1.netrss.cf")

## 文档
[在线文档](https://libsgh.github.io/PanIndex/)
15 changes: 15 additions & 0 deletions Util/Base.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@ package Util
import (
"fmt"
"strconv"
"strings"
"time"
)

func ShortDur(d time.Duration) string {
v, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", d.Seconds()), 64)
return fmt.Sprint(v) + "s"
}
func GetCurBetweenStr(str, start, end string) string {
n := strings.Index(str, start)
if n == -1 {
return ""
}
n = n + len(start)
str = string([]byte(str)[n:])
m := strings.Index(str, end)
if m == -1 {
return ""
}
str = string([]byte(str)[:m])
return str
}
60 changes: 44 additions & 16 deletions Util/Cloud189.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"PanIndex/config"
"PanIndex/entity"
"PanIndex/model"
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
Expand All @@ -15,7 +16,11 @@ import (
jsoniter "github.com/json-iterator/go"
uuid "github.com/satori/go.uuid"
log "github.com/sirupsen/logrus"
"io"
"io/ioutil"
math_rand "math/rand"
"mime/multipart"
"net/http"
"os"
"regexp"
"sort"
Expand All @@ -28,7 +33,7 @@ import (
var CLoud189Sessions = map[string]nic.Session{}

//获取文件列表
func Cloud189GetFiles(accountId, rootId, fileId string) {
func Cloud189GetFiles(accountId, rootId, fileId, prefix string) {
CLoud189Session := CLoud189Sessions[accountId]
defer func() {
if p := recover(); p != nil {
Expand Down Expand Up @@ -67,6 +72,12 @@ func Cloud189GetFiles(accountId, rootId, fileId string) {
}
}
}
if p == "/" && prefix != "" {
p = prefix
} else if p != "/" && prefix != "" {
p = prefix + p
}
fmt.Println(p)
if d != nil {
m := []entity.FileNode{}
err = jsoniter.Unmarshal([]byte(d.ToString()), &m)
Expand All @@ -83,7 +94,7 @@ func Cloud189GetFiles(accountId, rootId, fileId string) {
item.ParentPath = p
item.SizeFmt = FormatFileSize(item.FileSize)
if item.IsFolder == true {
Cloud189GetFiles(accountId, rootId, item.FileId)
Cloud189GetFiles(accountId, rootId, item.FileId, prefix)
} else {
//如果是文件,解析下载直链
/*dRedirectRep, _ := CLoud189Session.Get("https://cloud.189.cn/downloadFile.action?fileStr="+item.FileIdDigest+"&downloadType=1", nic.H{
Expand Down Expand Up @@ -340,6 +351,37 @@ func GetValidateCode(accountId, params string) string {
return ""
}

func Cloud189UploadFiles(accountId, parentId string, files []*multipart.FileHeader) bool {
CLoud189Session := CLoud189Sessions[accountId]
response, _ := CLoud189Session.Get("https://cloud.189.cn/main.action#home", nil)
sessionKey := GetCurBetweenStr(response.Text, "window.edrive.sessionKey = '", "';")
log.Debug(sessionKey)
for _, file := range files {
t1 := time.Now()
log.Debugf("开始上传文件:%s,大小:%d", file.Filename, file.Size)
fileContent, _ := file.Open()
byteContent, _ := ioutil.ReadAll(fileContent)
reader := bytes.NewReader(byteContent)
b := &bytes.Buffer{}
writer := multipart.NewWriter(b)
writer.WriteField("parentId", parentId)
writer.WriteField("sessionKey", sessionKey)
writer.WriteField("opertype", "1")
writer.WriteField("fname", file.Filename)
part, _ := writer.CreateFormFile("Filedata", file.Filename)
io.Copy(part, reader)
writer.Close()
r, _ := http.NewRequest("POST", "https://hb02.upload.cloud.189.cn/v1/DCIWebUploadAction", b)
r.Header.Add("Content-Type", writer.FormDataContentType())
res, _ := http.DefaultClient.Do(r)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
log.Debugf("上传接口返回:%s", string(body))
log.Debugf("文件:%s,上传成功,耗时:%s", file.Filename, ShortDur(time.Now().Sub(t1)))
}
return true
}

var b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"
Expand Down Expand Up @@ -406,20 +448,6 @@ func FormatFileSize(fileSize int64) (size string) {
}
}

func GetBetweenStr1(str, start, end string) string {
n := strings.Index(str, start)
if n == -1 {
return ""
}
n = n + len(start)
str = string([]byte(str)[n:])
m := strings.Index(str, end)
if m == -1 {
return ""
}
str = string([]byte(str)[:m])
return str
}
func GetBetweenStr(str, start, end string) string {
n := strings.Index(str, start)
if n == -1 {
Expand Down
Loading

0 comments on commit 5a616a5

Please sign in to comment.