|
1 | | -package assemblyopt |
2 | | - |
3 | | -import ( |
4 | | - "Orca_Master/cli/cmdopt/fileopt" |
5 | | - "Orca_Master/cli/common" |
6 | | - "Orca_Master/define/colorcode" |
7 | | - "Orca_Master/define/config" |
8 | | - "Orca_Master/tools/crypto" |
9 | | - "Orca_Master/tools/util" |
10 | | - "encoding/json" |
11 | | - "fmt" |
12 | | - "github.com/tj/go-spin" |
13 | | - "io" |
14 | | - "os" |
15 | | - "path/filepath" |
16 | | - "time" |
17 | | -) |
18 | | - |
19 | | -const SliceBytes = 40 * 1024 // 分片大小 |
20 | | - |
21 | | -type AssemblyMetaInfo struct { |
22 | | - Fid string // 操作文件ID,随机生成的UUID |
23 | | - FileName string // 程序名 |
24 | | - SliceNum int // 基础分片数量 |
25 | | - SliceSize int64 // 基础分片大小 |
26 | | - RemainSize int64 // 剩余分片大小 |
27 | | -} |
28 | | - |
29 | | -// 获取程序集元信息,并加密 |
30 | | -func GetAssemblyMetaInfo(uploadFile string) string { |
31 | | - sliceNum, remainSize := fileopt.GetFileSliceInfo(uploadFile) |
32 | | - _, filename := filepath.Split(uploadFile) |
33 | | - sliceSize := int64(SliceBytes) |
34 | | - assemblyMetaInfo := AssemblyMetaInfo{ |
35 | | - Fid: util.GenUUID(), |
36 | | - FileName: filename, |
37 | | - SliceNum: sliceNum, |
38 | | - SliceSize: sliceSize, |
39 | | - RemainSize: remainSize, |
40 | | - } |
41 | | - metaInfo, err := json.Marshal(assemblyMetaInfo) |
42 | | - if err != nil { |
43 | | - return "" |
44 | | - } |
45 | | - data, _ := crypto.Encrypt(metaInfo, []byte(config.AesKey)) |
46 | | - return data |
47 | | -} |
48 | | - |
49 | | -// 发送程序集元信息 |
50 | | -func SendAssemblyMetaMsg(clientId, metaData string) common.HttpRetData { |
51 | | - sendUserId := common.ClientId |
52 | | - msg := "assemblyLoad" |
53 | | - data := metaData |
54 | | - retData := common.SendSuccessMsg(clientId, sendUserId, msg, data, "") |
55 | | - return retData |
56 | | -} |
57 | | - |
58 | | -// 发送程序集分片数据 |
59 | | -func SendAssemblySliceMsg(clientId string, sliceData []byte) common.HttpRetData { |
60 | | - sendUserId := common.ClientId |
61 | | - msg := "assemblySliceData" |
62 | | - data, _ := crypto.Encrypt(sliceData, []byte(config.AesKey)) |
63 | | - retData := common.SendSuccessMsg(clientId, sendUserId, msg, data, "") |
64 | | - return retData |
65 | | -} |
66 | | - |
67 | | -// 发送文件 |
68 | | -func SendFileData(clientId string, uploadFile string) { |
69 | | - sliceNum, remainSize := fileopt.GetFileSliceInfo(uploadFile) |
70 | | - sliceSize := int64(SliceBytes) |
71 | | - pUploadFile, _ := os.Open(uploadFile) |
72 | | - defer pUploadFile.Close() |
73 | | - s := spin.New() |
74 | | - s.Set(spin.Box2) |
75 | | - currentTime := time.Now().Format("2006/01/02 15:04:05") |
76 | | - timeSign := colorcode.COLOR_GREY + currentTime + colorcode.END |
77 | | - sign := fmt.Sprintf("%s %s", timeSign, colorcode.SIGN_NOTICE) |
78 | | - for i := 0; i < sliceNum; i++ { |
79 | | - fmt.Printf("\r%s%s assembly loading\033[m %s ", sign, colorcode.COLOR_CYAN, s.Next()) |
80 | | - sliceData := make([]byte, sliceSize) |
81 | | - _, err := pUploadFile.Read(sliceData) |
82 | | - if err != nil && err != io.EOF { |
83 | | - panic(err.Error()) |
84 | | - } |
85 | | - SendAssemblySliceMsg(clientId, sliceData) |
86 | | - } |
87 | | - // 处理最后一个分片 |
88 | | - sliceData := make([]byte, remainSize) |
89 | | - _, err := pUploadFile.Read(sliceData) |
90 | | - if err != nil && err != io.EOF { |
91 | | - panic(err.Error()) |
92 | | - } |
93 | | - SendAssemblySliceMsg(clientId, sliceData) |
94 | | - fmt.Println() |
95 | | - |
96 | | -} |
| 1 | +package assemblyopt |
| 2 | + |
| 3 | +import ( |
| 4 | + "Orca_Master/cli/cmdopt/fileopt" |
| 5 | + "Orca_Master/cli/common" |
| 6 | + "Orca_Master/define/colorcode" |
| 7 | + "Orca_Master/define/config" |
| 8 | + "Orca_Master/tools/crypto" |
| 9 | + "Orca_Master/tools/util" |
| 10 | + "encoding/json" |
| 11 | + "fmt" |
| 12 | + "github.com/tj/go-spin" |
| 13 | + "io" |
| 14 | + "os" |
| 15 | + "path/filepath" |
| 16 | + "time" |
| 17 | +) |
| 18 | + |
| 19 | +const SliceBytes = 40 * 1024 // 分片大小 |
| 20 | + |
| 21 | +type AssemblyMetaInfo struct { |
| 22 | + Fid string // 操作文件ID,随机生成的UUID |
| 23 | + FileName string // 程序名 |
| 24 | + SliceNum int // 基础分片数量 |
| 25 | + SliceSize int64 // 基础分片大小 |
| 26 | + RemainSize int64 // 剩余分片大小 |
| 27 | +} |
| 28 | + |
| 29 | +// 获取程序集元信息,并加密 |
| 30 | +func GetAssemblyMetaInfo(uploadFile string) string { |
| 31 | + sliceNum, remainSize := fileopt.GetFileSliceInfo(uploadFile) |
| 32 | + _, filename := filepath.Split(uploadFile) |
| 33 | + sliceSize := int64(SliceBytes) |
| 34 | + assemblyMetaInfo := AssemblyMetaInfo{ |
| 35 | + Fid: util.GenUUID(), |
| 36 | + FileName: filename, |
| 37 | + SliceNum: sliceNum, |
| 38 | + SliceSize: sliceSize, |
| 39 | + RemainSize: remainSize, |
| 40 | + } |
| 41 | + metaInfo, err := json.Marshal(assemblyMetaInfo) |
| 42 | + if err != nil { |
| 43 | + return "" |
| 44 | + } |
| 45 | + data, _ := crypto.Encrypt(metaInfo, []byte(config.AesKey)) |
| 46 | + return data |
| 47 | +} |
| 48 | + |
| 49 | +// 发送程序集元信息 |
| 50 | +func SendAssemblyMetaMsg(clientId, metaData string) common.HttpRetData { |
| 51 | + sendUserId := common.ClientId |
| 52 | + msg := "assemblyLoad" |
| 53 | + data := metaData |
| 54 | + retData := common.SendSuccessMsg(clientId, sendUserId, msg, data, "") |
| 55 | + return retData |
| 56 | +} |
| 57 | + |
| 58 | +// 发送程序集分片数据 |
| 59 | +func SendAssemblySliceMsg(clientId string, sliceData []byte) common.HttpRetData { |
| 60 | + sendUserId := common.ClientId |
| 61 | + msg := "assemblySliceData" |
| 62 | + data, _ := crypto.Encrypt(sliceData, []byte(config.AesKey)) |
| 63 | + retData := common.SendSuccessMsg(clientId, sendUserId, msg, data, "") |
| 64 | + return retData |
| 65 | +} |
| 66 | + |
| 67 | +// 发送文件 |
| 68 | +func SendFileData(clientId string, uploadFile string) { |
| 69 | + sliceNum, remainSize := fileopt.GetFileSliceInfo(uploadFile) |
| 70 | + sliceSize := int64(SliceBytes) |
| 71 | + pUploadFile, _ := os.Open(uploadFile) |
| 72 | + defer pUploadFile.Close() |
| 73 | + s := spin.New() |
| 74 | + s.Set(spin.Box2) |
| 75 | + currentTime := time.Now().Format("2006/01/02 15:04:05") |
| 76 | + timeSign := colorcode.COLOR_GREY + currentTime + colorcode.END |
| 77 | + sign := fmt.Sprintf("%s %s", timeSign, colorcode.SIGN_NOTICE) |
| 78 | + for i := 0; i < sliceNum; i++ { |
| 79 | + fmt.Printf("\r%s%s assembly loading\033[m %s ", sign, colorcode.COLOR_CYAN, s.Next()) |
| 80 | + sliceData := make([]byte, sliceSize) |
| 81 | + _, err := pUploadFile.Read(sliceData) |
| 82 | + if err != nil && err != io.EOF { |
| 83 | + panic(err.Error()) |
| 84 | + } |
| 85 | + SendAssemblySliceMsg(clientId, sliceData) |
| 86 | + } |
| 87 | + // 处理最后一个分片 |
| 88 | + sliceData := make([]byte, remainSize) |
| 89 | + _, err := pUploadFile.Read(sliceData) |
| 90 | + if err != nil && err != io.EOF { |
| 91 | + panic(err.Error()) |
| 92 | + } |
| 93 | + SendAssemblySliceMsg(clientId, sliceData) |
| 94 | + fmt.Println() |
| 95 | + |
| 96 | +} |
0 commit comments