diff --git a/flutter/clipboard/lib/main.dart b/flutter/clipboard/lib/main.dart index a86707935..920ac6798 100644 --- a/flutter/clipboard/lib/main.dart +++ b/flutter/clipboard/lib/main.dart @@ -727,20 +727,6 @@ class _HomePageState extends State { if (fileCount == 0) { throw Exception('No file to copy'); } - if (fileCount == 1) { - final fileName = - utf8.decode(response.headers['file-name']![0].codeUnits); - // var file = File('$downloadDir/$fileName'); - String filePath; - if (hasImageExtension(fileName)) { - filePath = '$imageDir/$fileName'; - } else { - filePath = '$downloadDir/$fileName'; - } - var file = File(filePath); - await response.pipe(file.openWrite()); - return "已保存到: $filePath"; - } var body = await response.transform(utf8.decoder).join(); var fileNames = body.split('\n'); return await _downloadFiles(serverConfig, fileNames); @@ -761,9 +747,11 @@ class _HomePageState extends State { continue; } final url = Uri.parse(serverConfig.downloadUrl); - final request = await client.postUrl(url); + final request = await client.getUrl(url); request.headers.set('time-ip', serverConfig.generateTimeipHeadHex()); - request.add(utf8.encode(winFilePath)); + final body = utf8.encode(winFilePath); + request.headers.add('Content-Length', body.length); + request.add(body); String filePath; winFilePath = winFilePath.replaceAll('\\', '/'); var fileName = winFilePath.split('/').last; diff --git a/go/main.go b/go/main.go index faa0f57e5..7a697e0db 100644 --- a/go/main.go +++ b/go/main.go @@ -43,7 +43,7 @@ func main() { route.POST("/copy", copyHandler) route.POST("/paste", pasteHandler) route.POST("/ping", pingHandler) - route.POST("/download", downloadHandler) + route.GET("/download", downloadHandler) go func() { err := route.RunTLS(":"+GloballCnf.ServerPort, certFile, keyFile) if err != nil { diff --git a/go/route.go b/go/route.go index c3f7f2fe2..d103e42a0 100644 --- a/go/route.go +++ b/go/route.go @@ -82,8 +82,6 @@ func commonAuth(c *gin.Context) bool { } else { myipv4 = c.Request.Host } - fmt.Println("myipv4: ", myipv4) - fmt.Println("ip: ", ip) if ip != myipv4 { logrus.Error("ip not match: ", ip) c.String(401, ErrorInvalidAuthData+": ip not match, "+ip+" != "+myipv4) @@ -96,13 +94,6 @@ func sendFiles(c *gin.Context) error { c.Header("data-type", "files") c.Header("file-count", fmt.Sprintf("%d", len(SelectedFiles))) //c.Header("Content-Type", "application/octet-stream") - if len(SelectedFiles) == 1 { - fileName := filepath.Base(SelectedFiles[0]) - c.Writer.Header().Add("file-name", fileName) - c.File(SelectedFiles[0]) - return nil - } - // 多个文件 body := strings.Join(SelectedFiles, "\n") c.String(200, body) return nil @@ -121,6 +112,10 @@ func downloadHandler(c *gin.Context) { c.String(500, ErrorInternal+": "+err.Error()) return } + if len(filePath) == 0 { + c.String(400, ErrorInvalidData+": file path is empty") + return + } filename := filepath.Base(string(filePath)) c.Header("file-name", filename) c.File(string(filePath))