New scripts to get files
This commit is contained in:
parent
09e726564f
commit
a8031452f7
|
@ -59,6 +59,18 @@ func exportThemes() (interface{}, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func bindingFiles() (string, error) {
|
||||
if files, err := fic.GetFiles(); err != nil {
|
||||
return "", err
|
||||
} else {
|
||||
ret := ""
|
||||
for _, file := range files {
|
||||
ret += fmt.Sprintf("%s;%s\n", file.GetOrigin(), file.Path)
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
}
|
||||
|
||||
func getTheme(args []string) (fic.Theme, error) {
|
||||
if tid, err := strconv.Atoi(string(args[0])); err != nil {
|
||||
return fic.Theme{}, err
|
||||
|
@ -99,7 +111,9 @@ func listTheme(args []string, body []byte) (interface{}, error) {
|
|||
return getExercice(args)
|
||||
}
|
||||
} else if len(args) == 1 {
|
||||
if args[0] == "themes.json" {
|
||||
if args[0] == "files-bindings" {
|
||||
return bindingFiles()
|
||||
} else if args[0] == "themes.json" {
|
||||
return exportThemes()
|
||||
} else {
|
||||
return getTheme(args)
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/sh
|
||||
|
||||
BASEURL="http://localhost:8081"
|
||||
BASEURI="https://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016"
|
||||
CLOUDUSER='fic'
|
||||
CLOUDPASS='f>t\nV33R|(+?$i*'
|
||||
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
WHERE=$1
|
||||
else
|
||||
WHERE="files"
|
||||
fi
|
||||
|
||||
curl -q -f ${BASEURL}/api/themes/files-bindings | while read l
|
||||
do
|
||||
FROM=$(echo "$l" | cut -d ";" -f 1)
|
||||
DEST=$(echo "$l" | cut -d ";" -f 2)
|
||||
|
||||
mkdir -p $(dirname "${WHERE}${DEST}")
|
||||
|
||||
wget -O "${WHERE}${DEST}" --user "${CLOUDUSER}" --password "${CLOUDPASS}" "${BASEURI}${FROM}"
|
||||
done
|
|
@ -21,6 +21,28 @@ type EFile struct {
|
|||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func GetFiles() ([]EFile, error) {
|
||||
if rows, err := DBQuery("SELECT id_file, id_exercice, origin, path, name, sha1, size FROM exercice_files"); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer rows.Close()
|
||||
|
||||
var files = make([]EFile, 0)
|
||||
for rows.Next() {
|
||||
var f EFile
|
||||
if err := rows.Scan(&f.Id, &f.IdExercice, &f.origin, &f.Path, &f.Name, &f.Checksum, &f.Size); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files = append(files, f)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return files, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e Exercice) GetFiles() ([]EFile, error) {
|
||||
if rows, err := DBQuery("SELECT id_file, origin, path, name, sha1, size FROM exercice_files WHERE id_exercice = ?", e.Id); err != nil {
|
||||
return nil, err
|
||||
|
@ -92,3 +114,7 @@ func (f EFile) Delete() (int64, error) {
|
|||
return nb, err
|
||||
}
|
||||
}
|
||||
|
||||
func (f EFile) GetOrigin() (string) {
|
||||
return f.origin
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue