Skip to content

Commit

Permalink
/download change to GET request
Browse files Browse the repository at this point in the history
  • Loading branch information
doraemonkeys committed Jun 26, 2023
1 parent d51c632 commit ffcaec8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
20 changes: 4 additions & 16 deletions flutter/clipboard/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -727,20 +727,6 @@ class _HomePageState extends State<HomePage> {
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);
Expand All @@ -761,9 +747,11 @@ class _HomePageState extends State<HomePage> {
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;
Expand Down
2 changes: 1 addition & 1 deletion go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 4 additions & 9 deletions go/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit ffcaec8

Please sign in to comment.