Hints can something else than text

This commit is contained in:
nemunaire 2017-01-05 02:21:32 +01:00
commit c2dea2f985
6 changed files with 69 additions and 25 deletions

View file

@ -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) {

View file

@ -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 {