-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3,221 changed files
with
368,898 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
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,33 @@ | ||
#debug or release | ||
RUN_MODE = debug | ||
[app] | ||
PAGE_SIZE = 10 | ||
LOCATION = "/home/sophia/data/local/" | ||
|
||
[server] | ||
HTTP_PORT = 8010 | ||
READ_TIMEOUT = 60 | ||
WRITE_TIMEOUT = 60 | ||
|
||
[database] | ||
TYPE = mysql | ||
USER = root | ||
PASSWORD = admin123 | ||
HOST = 127.0.0.1:3306 | ||
NAME = mycloud | ||
TABLE_PREFIX = "" | ||
|
||
[redis] | ||
HOST = 127.0.0.1:6379 | ||
INDEX = 1 | ||
|
||
[qq] | ||
APP_ID = | ||
REDIRECT_URI = "http://www.pyxgo.cn/callbackQQ" | ||
APP_KEY = | ||
|
||
[oss] | ||
ACCESS_KEY_ID = "" | ||
ACCESS_KEY_SECRET = "" | ||
END_POINT = "" | ||
BUCKET_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,16 @@ | ||
package conf | ||
|
||
const ( | ||
|
||
/* | ||
accessKey 和 secretKey 是ceph集群搭建后的创建的user生成的,可以通过命令 | ||
docker exec ceph-rgw radosgw-admin user create --uid="user1" --display-name="user1" | ||
创建用户并查看 | ||
*/ | ||
// CephAccessKey : 访问Key | ||
CephAccessKey = "0JC8W5QG4MDZ9V8K7NYB" | ||
// CephSecretKey : 访问密钥 | ||
CephSecretKey = "drcnFT4GVb1NTLAJDTICRZ7ScgAr3icBOejNujRT" | ||
// CephGWEndpoint : gateway地址 | ||
CephGWEndpoint = "http://127.0.0.1:7000" | ||
) |
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,9 @@ | ||
package conf | ||
|
||
const ( | ||
CookieDomain = "43.138.211.58" | ||
CookieTime = 3600 | ||
ImageUrl = "../static/img/avatar.png" //所有用户头像都是使用的这个地址...还待fix | ||
|
||
CephPath = "/home/sophia/data/ceph/" | ||
) |
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,128 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"mycloud/db/mysql" | ||
data "mycloud/meta" | ||
"mycloud/util" | ||
"path" | ||
"strconv" | ||
"strings" | ||
"time" | ||
) | ||
|
||
//获取父类的id | ||
func GetParentFolder(fId string) (fileFolder data.FileFolder) { | ||
mysql.DB.Find(&fileFolder, "id = ?", fId) | ||
return | ||
} | ||
|
||
//获取用户文件夹数量 | ||
func GetUserFileFolderCount(fileStoreId int) (fileFolderCount int) { | ||
var fileFolder []data.FileFolder | ||
mysql.DB.Find(&fileFolder, "file_store_id = ?", fileStoreId).Count(&fileFolderCount) | ||
return | ||
} | ||
|
||
//获取目录所有文件夹 | ||
func GetFileFolders(parentId string, fileStoreId int) (fileFolders []data.FileFolder) { | ||
mysql.DB.Order("time desc").Find(&fileFolders, "parent_folder_id = ? and file_store_id = ?", parentId, fileStoreId) | ||
return | ||
} | ||
|
||
//获取当前的目录信息 | ||
func GetCurrentFolders(fId string) (fileFolder data.FileFolder) { | ||
mysql.DB.Find(&fileFolder, "id = ?", fId) | ||
return | ||
} | ||
|
||
//获取当前路径所有的父级 | ||
func GetCurrentAllParent(folder data.FileFolder, folders []data.FileFolder) []data.FileFolder { | ||
var parentFolder data.FileFolder | ||
if folder.ParentFolderId != 0 { | ||
mysql.DB.Find(&parentFolder, "id = ?", folder.ParentFolderId) | ||
folders = append(folders, parentFolder) | ||
//递归查找当前所有父级 | ||
return GetCurrentAllParent(parentFolder, folders) | ||
} | ||
|
||
//反转切片 | ||
for i, j := 0, len(folders)-1; i < j; i, j = i+1, j-1 { | ||
folders[i], folders[j] = folders[j], folders[i] | ||
} | ||
|
||
return folders | ||
} | ||
|
||
//新建文件夹 | ||
func CreateFolder(folderName, parentId string, fileStoreId int) { | ||
parentIdInt, err := strconv.Atoi(parentId) | ||
if err != nil { | ||
fmt.Println("父类id错误") | ||
return | ||
} | ||
fileFolder := data.FileFolder{ | ||
FileFolderName: folderName, | ||
ParentFolderId: parentIdInt, | ||
FileStoreId: fileStoreId, | ||
Time: time.Now().Format("2006-01-02 15:04:05"), | ||
} | ||
mysql.DB.Create(&fileFolder) | ||
} | ||
|
||
//修改文件夹名 | ||
func UpdateFolderName(fId, fName string) { | ||
var fileFolder data.FileFolder | ||
mysql.DB.Model(&fileFolder).Where("id = ?", fId).Update("file_folder_name", fName) | ||
} | ||
|
||
//删除文件夹信息 | ||
func DeleteFileFolder(fId string) bool { | ||
var fileFolder data.FileFolder | ||
var fileFolder2 data.FileFolder | ||
//删除文件夹信息 | ||
mysql.DB.Where("id = ?", fId).Delete(data.FileFolder{}) | ||
//删除文件夹中文件信息 | ||
mysql.DB.Where("parent_folder_id = ?", fId).Delete(data.MyFile{}) | ||
//删除文件夹中文件夹信息 | ||
mysql.DB.Find(&fileFolder, "parent_folder_id = ?", fId) | ||
mysql.DB.Where("parent_folder_id = ?", fId).Delete(data.FileFolder{}) | ||
|
||
mysql.DB.Find(&fileFolder2, "parent_folder_id = ?", fileFolder.Id) | ||
if fileFolder2.Id != 0 { //递归删除文件下的文件夹 | ||
return DeleteFileFolder(strconv.Itoa(fileFolder.Id)) | ||
} | ||
|
||
return true | ||
} | ||
|
||
//添加文件数据 | ||
func CreateFile(filename, fileHash string, fileSize int64, fId string, fileStoreId int, file_location string) { | ||
var sizeStr string | ||
//获取文件后缀 | ||
fileSuffix := path.Ext(filename) | ||
//获取文件名 | ||
filePrefix := filename[0 : len(filename)-len(fileSuffix)] | ||
fid, _ := strconv.Atoi(fId) | ||
|
||
if fileSize < 1048576 { | ||
sizeStr = strconv.FormatInt(fileSize/1024, 10) + "KB" | ||
} else { | ||
sizeStr = strconv.FormatInt(fileSize/102400, 10) + "MB" | ||
} | ||
|
||
myFile := data.MyFile{ | ||
FileName: filePrefix, | ||
FileHash: fileHash, | ||
FileStoreId: fileStoreId, | ||
FilePath: file_location, | ||
DownloadNum: 0, | ||
UploadTime: time.Now().Format("2006-01-02 15:04:05"), | ||
ParentFolderId: fid, | ||
Size: fileSize / 1024, | ||
SizeStr: sizeStr, | ||
Type: util.GetFileTypeInt(fileSuffix), | ||
Postfix: strings.ToLower(fileSuffix), | ||
} | ||
mysql.DB.Create(&myFile) | ||
} |
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,31 @@ | ||
package db | ||
|
||
import ( | ||
"mycloud/db/mysql" | ||
|
||
data "mycloud/meta" | ||
) | ||
|
||
//根据用户id获取仓库信息 | ||
func GetUserFileStore(userId int) (fileStore data.FileStore) { | ||
mysql.DB.Find(&fileStore, "user_id = ?", userId) | ||
return | ||
} | ||
|
||
//文件上传成功减去相应容量 | ||
func SubtractSize(size int64, fileStoreId int) { | ||
var fileStore data.FileStore | ||
mysql.DB.First(&fileStore, fileStoreId) | ||
|
||
fileStore.CurrentSize = fileStore.CurrentSize + size/1024 | ||
fileStore.MaxSize = fileStore.MaxSize - size/1024 | ||
mysql.DB.Save(&fileStore) | ||
} | ||
|
||
//判断用户容量是否足够 | ||
func CapacityIsEnough(fileSize int64, fileStoreId int) bool { | ||
var fileStore data.FileStore | ||
mysql.DB.First(&fileStore, fileStoreId) | ||
|
||
return fileStore.MaxSize-(fileSize/1024) >= 0 | ||
} |
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,92 @@ | ||
package db | ||
|
||
import ( | ||
"mycloud/db/mysql" | ||
data "mycloud/meta" | ||
"path" | ||
"strings" | ||
) | ||
|
||
// 获取用户文件 | ||
func GetUserFiles(parentId string, storeId int) (files []data.MyFile) { | ||
mysql.DB.Find(&files, "file_store_id = ? and parent_folder_id = ?", storeId, parentId) | ||
return | ||
} | ||
|
||
//获取用户文件数量 | ||
func GetUserFileCount(fileStoreId int) (fileCount int) { | ||
var file []data.MyFile | ||
mysql.DB.Find(&file, "file_store_id = ?", fileStoreId).Count(&fileCount) | ||
return | ||
} | ||
|
||
//获取用户文件使用明细情况 | ||
func GetFileDetailUse(fileStoreId int) map[string]int64 { | ||
var files []data.MyFile | ||
var ( | ||
docCount int64 | ||
imgCount int64 | ||
videoCount int64 | ||
musicCount int64 | ||
otherCount int64 | ||
) | ||
|
||
fileDetailUseMap := make(map[string]int64, 0) | ||
|
||
//文档类型 | ||
docCount = mysql.DB.Find(&files, "file_store_id = ? AND type = ?", fileStoreId, 1).RowsAffected | ||
fileDetailUseMap["docCount"] = docCount | ||
////图片类型 | ||
imgCount = mysql.DB.Find(&files, "file_store_id = ? and type = ?", fileStoreId, 2).RowsAffected | ||
fileDetailUseMap["imgCount"] = imgCount | ||
//视频类型 | ||
videoCount = mysql.DB.Find(&files, "file_store_id = ? and type = ?", fileStoreId, 3).RowsAffected | ||
fileDetailUseMap["videoCount"] = videoCount | ||
//音乐类型 | ||
musicCount = mysql.DB.Find(&files, "file_store_id = ? and type = ?", fileStoreId, 4).RowsAffected | ||
fileDetailUseMap["musicCount"] = musicCount | ||
//其他类型 | ||
otherCount = mysql.DB.Find(&files, "file_store_id = ? and type = ?", fileStoreId, 5).RowsAffected | ||
fileDetailUseMap["otherCount"] = otherCount | ||
|
||
return fileDetailUseMap | ||
} | ||
|
||
//根据文件类型获取文件 | ||
func GetTypeFile(fileType, fileStoreId int) (files []data.MyFile) { | ||
mysql.DB.Find(&files, "file_store_id = ? and type = ?", fileStoreId, fileType) | ||
return | ||
} | ||
|
||
//通过fileId获取文件信息 | ||
func GetFileInfo(fId string) (file data.MyFile) { | ||
mysql.DB.First(&file, fId) | ||
return | ||
} | ||
|
||
//删除数据库文件数据 | ||
func DeleteUserFile(fId, folderId string, storeId int) { | ||
mysql.DB.Where("id = ? and file_store_id = ? and parent_folder_id = ?", | ||
fId, storeId, folderId).Delete(data.MyFile{}) | ||
} | ||
|
||
//文件下载次数+1 | ||
func DownloadNumAdd(fId string) { | ||
var file data.MyFile | ||
mysql.DB.First(&file, fId) | ||
file.DownloadNum = file.DownloadNum + 1 | ||
mysql.DB.Save(&file) | ||
} | ||
|
||
//判断当前文件夹是否有同名文件 | ||
func CurrFileExists(fId, filename string) bool { | ||
var file data.MyFile | ||
//获取文件后缀 | ||
fileSuffix := strings.ToLower(path.Ext(filename)) | ||
//获取文件名 | ||
filePrefix := filename[0 : len(filename)-len(fileSuffix)] | ||
|
||
mysql.DB.Find(&file, "parent_folder_id = ? and file_name = ? and postfix = ?", fId, filePrefix, fileSuffix) | ||
|
||
return file.Size <= 0 | ||
} |
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,37 @@ | ||
package mysql | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"mycloud/lib" | ||
|
||
_ "github.com/go-sql-driver/mysql" | ||
"github.com/jinzhu/gorm" | ||
) | ||
|
||
var DB *gorm.DB | ||
|
||
func InitDB(conf lib.ServerConfig) { | ||
var err error | ||
dbParams := fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=Local", | ||
conf.User, | ||
conf.Password, | ||
conf.Host, | ||
conf.DbName, | ||
) | ||
DB, err = gorm.Open("mysql", dbParams) | ||
if err != nil { | ||
log.Fatal(2, err) | ||
} | ||
|
||
// 全局禁用表名复数 | ||
DB.SingularTable(true) | ||
|
||
gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string { | ||
return conf.TablePrefix + defaultTableName | ||
} | ||
|
||
DB.DB().SetMaxIdleConns(10) | ||
DB.DB().SetMaxOpenConns(100) | ||
fmt.Println("database init on port ", conf.Host) | ||
} |
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,35 @@ | ||
package db | ||
|
||
import ( | ||
"mycloud/db/mysql" | ||
data "mycloud/meta" | ||
"mycloud/util" | ||
"strings" | ||
"time" | ||
) | ||
|
||
//创建分享 | ||
func CreateShare(code, username string, fId int) string { | ||
share := data.Share{ | ||
Code: strings.ToLower(code), | ||
FileId: fId, | ||
Username: username, | ||
Hash: util.EncodeMd5(code + string(time.Now().Unix())), | ||
} | ||
mysql.DB.Create(&share) | ||
|
||
return share.Hash | ||
} | ||
|
||
//查询分享 | ||
func GetShareInfo(f string) (share data.Share) { | ||
mysql.DB.Find(&share, "hash = ?", f) | ||
return | ||
} | ||
|
||
//校验提取码 | ||
func VerifyShareCode(fId, code string) bool { | ||
var share data.Share | ||
mysql.DB.Find(&share, "file_id = ? and code = ?", fId, code) | ||
return share.Id != 0 | ||
} |
Oops, something went wrong.