sync: Handle remote challenge files

This commit is contained in:
nemunaire 2023-10-13 16:05:15 +02:00
commit 1d4b79bf90
5 changed files with 126 additions and 30 deletions

View file

@ -183,9 +183,13 @@ func GetFileContent(i Importer, URI string) (string, error) {
// getDestinationFilePath generates the destination path, from the URI.
// This function permits to obfusce to player the original URI.
// Theoricaly, changing the import method doesn't change destination URI.
func getDestinationFilePath(URI string) string {
func getDestinationFilePath(URI string, filename *string) string {
if filename == nil {
tmp := path.Base(URI)
filename = &tmp
}
hash := blake2b.Sum512([]byte(URI))
return path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), path.Base(URI))
return path.Join(fic.FilesDir, strings.ToLower(base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(hash[:])), *filename)
}
func importFile(i Importer, URI string, dest string) error {
@ -214,7 +218,7 @@ func importFile(i Importer, URI string, dest string) error {
// ImportFile imports the file at the given URI, using helpers of the given Importer.
// After import, next is called with relative path where the file has been saved and the original URI.
func ImportFile(i Importer, URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
dest := getDestinationFilePath(URI)
dest := getDestinationFilePath(URI, nil)
// If the present file is still valide, don't erase it
if _, err := os.Stat(dest); !os.IsNotExist(err) {