admin: Implement sychronization backends

We are now able, depending on configuration, to retrieve files from either WebDAV or local file system.
This commit is contained in:
nemunaire 2017-11-27 02:45:33 +01:00 committed by Pierre-Olivier Mercier
commit 8f7de926d3
7 changed files with 281 additions and 160 deletions

View file

@ -135,7 +135,23 @@ func (e Exercice) ImportFile(filePath string, origin string, digest []byte) (int
}
}
return e.AddFile(strings.TrimPrefix(filePath, FilesDir), origin, path.Base(filePath), result512, fi.Size())
dPath := strings.TrimPrefix(filePath, FilesDir)
if f, err := e.GetFileByPath(dPath); err != nil {
return e.AddFile(dPath, origin, path.Base(filePath), result512, fi.Size())
} else {
// Don't need to update Path and Name, because they are related to dPath
f.IdExercice = e.Id
f.origin = origin
f.Checksum = result512
f.Size = fi.Size()
if _, err := f.Update(); err != nil {
return nil, err
} else {
return f, nil
}
}
}
}