-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support: Continue an incomplete download:
- Loading branch information
李聪
committed
Apr 8, 2022
1 parent
61c7b71
commit e124b58
Showing
4 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
dl-talebook.exe | ||
dl-talebook | ||
dl-talebook | ||
*.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/url" | ||
"os" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const ( | ||
logfile = `.dl-download.log` | ||
) | ||
|
||
func saveDownloadHistory(tb TaleBook) { | ||
u, _ := url.Parse(tb.api) | ||
|
||
if err := os.WriteFile(logfile, []byte(fmt.Sprintf("%s %d", u.Host, tb.index)), 0644); err != nil { | ||
log.Printf("warning: can not write dl-download infromat to .dl-download.log %s", err) | ||
} | ||
} | ||
|
||
func tryReadHistoryIndex(api string) (int, error) { | ||
content, err := os.ReadFile(logfile) | ||
if err != nil { | ||
return 0, err | ||
} | ||
u, err := url.Parse(api) | ||
if err != nil { | ||
return 0, nil | ||
} | ||
result := strings.Split(string(content), " ") | ||
if len(result) >= 2 && result[0] == u.Host { | ||
return strconv.Atoi(result[1]) | ||
} | ||
return 0, fmt.Errorf("prase .dl-download.log failed , content: %s", string(content)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters