Skip to content

Commit

Permalink
import: gitbook: some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
hayzamjs committed Nov 26, 2024
1 parent d2bd2f6 commit 089ed5d
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 870 deletions.
91 changes: 0 additions & 91 deletions handlers/Import.go

This file was deleted.

36 changes: 36 additions & 0 deletions handlers/import.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package handlers

import (
"encoding/json"
"net/http"

"git.difuse.io/Difuse/kalmia/config"
"git.difuse.io/Difuse/kalmia/services"
)

func ImportGitbook(services *services.ServiceRegistry, w http.ResponseWriter, r *http.Request, cfg *config.Config) {
var request struct {
URL string `json:"url"`
Username string `json:"username"`
Password string `json:"password"`
}

if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
SendJSONResponse(http.StatusBadRequest, w, map[string]string{"status": "error", "message": "invalid_url", "error": err.Error()})
return
}

if request.URL == "" {
SendJSONResponse(http.StatusBadRequest, w, map[string]string{"status": "error", "message": "url_required"})
return
}

jsonString, err := services.DocService.ImportGitbook(request.URL, request.Username, request.Password, cfg)

if err != nil {
SendJSONResponse(http.StatusInternalServerError, w, map[string]string{"status": "error", "message": "gitbook_proccessing_failed", "error": err.Error()})
return
}

SendJSONResponse(http.StatusOK, w, jsonString)
}
Loading

0 comments on commit 089ed5d

Please sign in to comment.