mirror of https://github.com/cloudreve/Cloudreve
fix: metadata mismatch if file name contains `%` while uploading to OneDrive/SharePoint (#1301)
parent
644a326580
commit
f431eb0cbd
|
@ -37,19 +37,13 @@ const (
|
||||||
|
|
||||||
// GetSourcePath 获取文件的绝对路径
|
// GetSourcePath 获取文件的绝对路径
|
||||||
func (info *FileInfo) GetSourcePath() string {
|
func (info *FileInfo) GetSourcePath() string {
|
||||||
res, err := url.PathUnescape(
|
return strings.TrimPrefix(
|
||||||
strings.TrimPrefix(
|
|
||||||
path.Join(
|
path.Join(
|
||||||
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
strings.TrimPrefix(info.ParentReference.Path, "/drive/root:"),
|
||||||
info.Name,
|
info.Name,
|
||||||
),
|
),
|
||||||
"/",
|
"/",
|
||||||
),
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error 实现error接口
|
// Error 实现error接口
|
||||||
|
|
|
@ -138,9 +138,6 @@ func TestRequest(t *testing.T) {
|
||||||
|
|
||||||
func TestFileInfo_GetSourcePath(t *testing.T) {
|
func TestFileInfo_GetSourcePath(t *testing.T) {
|
||||||
asserts := assert.New(t)
|
asserts := assert.New(t)
|
||||||
|
|
||||||
// 成功
|
|
||||||
{
|
|
||||||
fileInfo := FileInfo{
|
fileInfo := FileInfo{
|
||||||
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
Name: "%e6%96%87%e4%bb%b6%e5%90%8d.jpg",
|
||||||
ParentReference: parentReference{
|
ParentReference: parentReference{
|
||||||
|
@ -148,18 +145,6 @@ func TestFileInfo_GetSourcePath(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
asserts.Equal("123/321/文件名.jpg", fileInfo.GetSourcePath())
|
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())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClient_GetRequestURL(t *testing.T) {
|
func TestClient_GetRequestURL(t *testing.T) {
|
||||||
|
|
|
@ -239,7 +239,7 @@ func (service *S3Callback) PreProcess(c *gin.Context) serializer.Response {
|
||||||
return ProcessCallback(service, c)
|
return ProcessCallback(service, c)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreProcess 对OneDrive客户端回调进行预处理验证
|
// PreProcess 对从机客户端回调进行预处理验证
|
||||||
func (service *UploadCallbackService) PreProcess(c *gin.Context) serializer.Response {
|
func (service *UploadCallbackService) PreProcess(c *gin.Context) serializer.Response {
|
||||||
// 创建文件系统
|
// 创建文件系统
|
||||||
fs, err := filesystem.NewFileSystemFromCallback(c)
|
fs, err := filesystem.NewFileSystemFromCallback(c)
|
||||||
|
|
Loading…
Reference in New Issue