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:
parent
6237f7755a
commit
8f7de926d3
7 changed files with 281 additions and 160 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue