fix: metadata mismatch if file name contains %
while uploading to OneDrive/SharePoint (#1301)
This commit is contained in:
parent
644a326580
commit
f431eb0cbd
3 changed files with 12 additions and 33 deletions
|
@ -37,19 +37,13 @@ const (
|
|||
|
||||
// GetSourcePath 获取文件的绝对路径
|
||||
func (info *FileInfo) GetSourcePath() string {
|
||||
res, err := url.PathUnescape(
|
||||
strings.TrimPrefix(
|
||||
path.Join(
|
||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
||||
info.Name,
|
||||
),
|
||||
"/",
|
||||
return strings.TrimPrefix(
|
||||
path.Join(
|
||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
||||
info.Name,
|
||||
),
|
||||
"/",
|
||||
)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// Error 实现error接口
|
||||
|
|
|
@ -138,28 +138,13 @@ func TestRequest(t *testing.T) {
|
|||
|
||||
func TestFileInfo_GetSourcePath(t *testing.T) {
|
||||
asserts := assert.New(t)
|
||||
|
||||
// 成功
|
||||
{
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
}
|
||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
||||
}
|
||||
|
||||
// 失败
|
||||
{
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8g.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
}
|
||||
asserts.Equal("", fileInfo.GetSourcePath())
|
||||
fileInfo := FileInfo{
|
||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||
ParentReference: parentReference{
|
||||
Path: "/drive/root:/123/321",
|
||||
},
|
||||
}
|
||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
||||
}
|
||||
|
||||
func TestClient_GetRequestURL(t *testing.T) {
|
||||
|
|
|
@ -239,7 +239,7 @@ func (service *S3Callback) PreProcess(c *gin.Context) serializer.Response {
|
|||
return ProcessCallback(service, c)
|
||||
}
|
||||
|
||||
// PreProcess 对OneDrive客户端回调进行预处理验证
|
||||
// PreProcess 对从机客户端回调进行预处理验证
|
||||
func (service *UploadCallbackService) PreProcess(c *gin.Context) serializer.Response {
|
||||
// 创建文件系统
|
||||
fs, err := filesystem.NewFileSystemFromCallback(c)
|
||||
|
|
Loading…
Add table
Reference in a new issue