admin: Handle exercice path given to auto-sync
This commit is contained in:
parent
75eae43f60
commit
20c41ec573
1 changed files with 13 additions and 7 deletions
|
@ -203,7 +203,7 @@ func declareSyncExercicesRoutes(router *gin.RouterGroup) {
|
||||||
// It'll sync most of modified things, and will delete out of sync data.
|
// It'll sync most of modified things, and will delete out of sync data.
|
||||||
// Avoid using it in a production environment.
|
// Avoid using it in a production environment.
|
||||||
func autoSync(c *gin.Context) {
|
func autoSync(c *gin.Context) {
|
||||||
p := strings.TrimPrefix(c.Params.ByName("p"), "/")
|
p := strings.Split(strings.TrimPrefix(c.Params.ByName("p"), "/"), "/")
|
||||||
|
|
||||||
themes, err := fic.GetThemes()
|
themes, err := fic.GetThemes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -212,7 +212,8 @@ func autoSync(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if p == "" {
|
// No argument, do a deep sync
|
||||||
|
if len(p) == 0 {
|
||||||
if !IsProductionEnv {
|
if !IsProductionEnv {
|
||||||
for _, theme := range themes {
|
for _, theme := range themes {
|
||||||
theme.DeleteDeep()
|
theme.DeleteDeep()
|
||||||
|
@ -226,8 +227,9 @@ func autoSync(c *gin.Context) {
|
||||||
|
|
||||||
var theTheme *fic.Theme
|
var theTheme *fic.Theme
|
||||||
|
|
||||||
|
// Find the given theme
|
||||||
for _, theme := range themes {
|
for _, theme := range themes {
|
||||||
if theme.Path == p {
|
if theme.Path == p[0] {
|
||||||
theTheme = theme
|
theTheme = theme
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -238,24 +240,26 @@ func autoSync(c *gin.Context) {
|
||||||
rThemes, err := sync.GetThemes(sync.GlobalImporter)
|
rThemes, err := sync.GetThemes(sync.GlobalImporter)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, theme := range rThemes {
|
for _, theme := range rThemes {
|
||||||
if theme == p {
|
if theme == p[0] {
|
||||||
sync.SyncThemes(sync.GlobalImporter)
|
sync.SyncThemes(sync.GlobalImporter)
|
||||||
|
|
||||||
themes, err := fic.GetThemes()
|
themes, err := fic.GetThemes()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, theme := range themes {
|
for _, theme := range themes {
|
||||||
if theme.Path == p {
|
if theme.Path == p[0] {
|
||||||
theTheme = theme
|
theTheme = theme
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if theTheme == nil {
|
if theTheme == nil {
|
||||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Theme not found %q", p)})
|
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": fmt.Sprintf("Theme not found %q", p[0])})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,10 +268,12 @@ func autoSync(c *gin.Context) {
|
||||||
exercices, err := theTheme.GetExercices()
|
exercices, err := theTheme.GetExercices()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, exercice := range exercices {
|
for _, exercice := range exercices {
|
||||||
|
if len(p) <= 1 || exercice.Path == path.Join(p[0], p[1]) {
|
||||||
exercice.DeleteDeep()
|
exercice.DeleteDeep()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exceptions := sync.LoadException(sync.GlobalImporter, theTheme)
|
exceptions := sync.LoadException(sync.GlobalImporter, theTheme)
|
||||||
|
|
||||||
|
|
Reference in a new issue