Hints can something else than text
This commit is contained in:
parent
ee8bb97057
commit
c2dea2f985
6 changed files with 69 additions and 25 deletions
|
|
@ -69,7 +69,7 @@ func (e Exercice) GetFiles() ([]EFile, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (e Exercice) ImportFile(filePath string, origin string, digest []byte) (EFile, error) {
|
||||
func (e Exercice) ImportFile(filePath string, origin string, digest []byte) (interface{}, error) {
|
||||
if digest == nil && !OptionalDigest {
|
||||
return EFile{}, errors.New("No digest given.")
|
||||
} else if fi, err := os.Stat(filePath); err != nil {
|
||||
|
|
@ -84,7 +84,6 @@ func (e Exercice) ImportFile(filePath string, origin string, digest []byte) (EFi
|
|||
if _, err := io.Copy(hash, reader); err != nil {
|
||||
return EFile{}, err
|
||||
}
|
||||
|
||||
result := hash.Sum(nil)
|
||||
|
||||
if len(digest) != len(result) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package fic
|
||||
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EHint struct {
|
||||
|
|
@ -11,11 +13,18 @@ type EHint struct {
|
|||
Cost int64 `json:"cost"`
|
||||
}
|
||||
|
||||
func treatHintContent(content *string) {
|
||||
if strings.HasPrefix(*content, "$FILES") {
|
||||
*content = "$FILES" + path.Join(FilesDir, strings.TrimPrefix(*content, "$FILES"))
|
||||
}
|
||||
}
|
||||
|
||||
func GetHint(id int64) (EHint, error) {
|
||||
var h EHint
|
||||
if err := DBQueryRow("SELECT id_hint, id_exercice, title, content, cost FROM exercice_hints WHERE id_hint = ?", id).Scan(&h.Id, &h.IdExercice, &h.Title, &h.Content, &h.Cost); err != nil {
|
||||
return h, err
|
||||
}
|
||||
treatHintContent(&h.Content)
|
||||
|
||||
return h, nil
|
||||
}
|
||||
|
|
@ -33,6 +42,7 @@ func (e Exercice) GetHints() ([]EHint, error) {
|
|||
if err := rows.Scan(&h.Id, &h.Title, &h.Content, &h.Cost); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
treatHintContent(&h.Content)
|
||||
hints = append(hints, h)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
|
|
|
|||
Reference in a new issue