Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
ppt_server
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Li Feifei
ppt_server
Commits
f012a199
Commit
f012a199
authored
Feb 27, 2020
by
Li Feifei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debug
parent
defe8ede
Pipeline
#8494
passed with stages
in 21 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
18 deletions
+10
-18
upload.go
upload/upload.go
+10
-18
No files found.
upload/upload.go
View file @
f012a199
...
@@ -3,7 +3,6 @@ package upload
...
@@ -3,7 +3,6 @@ package upload
import
(
import
(
"archive/zip"
"archive/zip"
"crypto/md5"
"crypto/md5"
"crypto/sha1"
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"errors"
"errors"
...
@@ -130,6 +129,9 @@ func Down(v *models.XyuSmallTempFiles) {
...
@@ -130,6 +129,9 @@ func Down(v *models.XyuSmallTempFiles) {
t
:=
time
.
Now
()
t
:=
time
.
Now
()
now
:=
fmt
.
Sprintf
(
"%02d-%02d-%02d %02d:%02d:%02d"
,
now
:=
fmt
.
Sprintf
(
"%02d-%02d-%02d %02d:%02d:%02d"
,
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
t
.
Hour
(),
t
.
Minute
(),
t
.
Second
())
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
t
.
Hour
(),
t
.
Minute
(),
t
.
Second
())
objectName
:=
v
.
Url
[
strings
.
Index
(
v
.
Url
,
"com/"
)
+
4
:
]
slice_path
:=
strings
.
Split
(
objectName
,
"/"
)
fmt
.
Println
(
slice_path
[
2
])
room_file
[
"room_id"
]
=
room
.
Id
room_file
[
"room_id"
]
=
room
.
Id
room_file
[
"id"
]
=
t
.
Unix
()
room_file
[
"id"
]
=
t
.
Unix
()
room_file
[
"is_courseware"
]
=
"1"
room_file
[
"is_courseware"
]
=
"1"
...
@@ -144,12 +146,8 @@ func Down(v *models.XyuSmallTempFiles) {
...
@@ -144,12 +146,8 @@ func Down(v *models.XyuSmallTempFiles) {
}
else
if
v
.
Type
==
3
{
}
else
if
v
.
Type
==
3
{
room_file
[
"is_titlebook"
]
=
1
room_file
[
"is_titlebook"
]
=
1
}
}
contentHash
:=
slice_path
[
2
]
contentHash
,
_
:=
fileContentHash
(
file
)
room_file
[
"file_name_hash"
]
=
slice_path
[
3
]
fileHash
:=
[]
byte
(
filename
)
fileHashName
:=
fmt
.
Sprintf
(
"%x"
,
sha1
.
Sum
(
fileHash
))
room_file
[
"file_name_hash"
]
=
fileHashName
room_file
[
"hash"
]
=
contentHash
room_file
[
"hash"
]
=
contentHash
//获取文件后缀
//获取文件后缀
...
@@ -177,8 +175,7 @@ func Down(v *models.XyuSmallTempFiles) {
...
@@ -177,8 +175,7 @@ func Down(v *models.XyuSmallTempFiles) {
}
}
defer
fd
.
Close
()
defer
fd
.
Close
()
//objectPath := "documents/" + v.RoomNum + "/" + contentHash + "/" + fileHashName + "/"
objectName
:=
v
.
Url
[
strings
.
Index
(
v
.
Url
,
"com/"
)
+
4
:
]
fmt
.
Println
(
"objectName == "
,
objectName
)
fmt
.
Println
(
"objectName == "
,
objectName
)
objectPath
:=
objectName
[
0
:
strings
.
LastIndex
(
objectName
,
"/"
)]
+
"/"
objectPath
:=
objectName
[
0
:
strings
.
LastIndex
(
objectName
,
"/"
)]
+
"/"
room_file
[
"path"
]
=
objectName
room_file
[
"path"
]
=
objectName
...
@@ -212,7 +209,7 @@ func Down(v *models.XyuSmallTempFiles) {
...
@@ -212,7 +209,7 @@ func Down(v *models.XyuSmallTempFiles) {
ch
:=
make
(
chan
bool
)
ch
:=
make
(
chan
bool
)
go
func
()
{
go
func
()
{
err
:=
downloadFile
(
downUrl
,
func
(
length
,
downLen
int64
)
{
err
:=
downloadFile
(
downUrl
,
contentHash
,
func
(
length
,
downLen
int64
)
{
})
})
if
err
==
nil
{
if
err
==
nil
{
...
@@ -521,7 +518,7 @@ func fileContentHash(file io.Reader) (string, []byte) {
...
@@ -521,7 +518,7 @@ func fileContentHash(file io.Reader) (string, []byte) {
return
fmt
.
Sprintf
(
"%s"
,
hex
.
EncodeToString
(
result
)),
b
return
fmt
.
Sprintf
(
"%s"
,
hex
.
EncodeToString
(
result
)),
b
}
}
func
downloadFile
(
url
string
,
fb
func
(
length
,
downLen
int64
))
error
{
func
downloadFile
(
url
,
contentHash
string
,
fb
func
(
length
,
downLen
int64
))
error
{
var
(
var
(
fsize
int64
fsize
int64
buf
=
make
([]
byte
,
32
*
1024
)
buf
=
make
([]
byte
,
32
*
1024
)
...
@@ -541,15 +538,10 @@ func downloadFile(url string, fb func(length, downLen int64)) error {
...
@@ -541,15 +538,10 @@ func downloadFile(url string, fb func(length, downLen int64)) error {
fmt
.
Println
(
err
)
fmt
.
Println
(
err
)
}
}
//创建文件
//创建文件
var
filenameWithSuffix
string
filenameWithSuffix
=
path
.
Base
(
url
)
//获取文件名带后缀
var
fileSuffix
string
fileSuffix
=
path
.
Ext
(
filenameWithSuffix
)
//获取文件后缀
var
filenameOnly
string
filenameOnly
=
strings
.
Replace
(
filenameWithSuffix
,
fileSuffix
,
".zip"
,
-
1
)
//获取文件名
file
,
err
:=
os
.
Create
(
"/data/files/"
+
contentHash
+
".zip"
)
file
,
err
:=
os
.
Create
(
"/data/files/"
+
filenameOnly
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment