Example #1
0
func InstallDepsSync(resp http.ResponseWriter, req *http.Request) {
	validated, _, enc, body := routeinit.InitHandling(req, resp, []string{
		"language",
		"uid",
		"sid",
		"snippet"})
	if !validated {
		return
	}

	// 1. Set the container context
	sidDetails := setContainerContext(body)
	sidDetails["op"] = "install-deps"

	// 2. Run the container
	status := sidDetails["status"].(int)
	var results []string
	var fstatus int = status
	if status == 1 {
		results, fstatus = executeContainer(sidDetails["uid"].(string), sidDetails, 0)
	}

	enc.Encode(routeinit.ApiResponse{sidDetails["msg"].(string), "", results, fstatus})
	return
}
Example #2
0
func FilterSnippetsByTag(resp http.ResponseWriter, req *http.Request) {
	validated, _, enc, _ := routeinit.InitHandling(req, resp, []string{})
	tag := req.FormValue("tag")
	if !validated {
		return
	}
	snippets, err := models.FindSnippetsByTag(tag)
	snippetArray := SnippetsArrayResponse{&snippets}
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: false})
	} else {
		enc.Encode(routeinit.ApiResponse{Result: &snippetArray, Status: true})
	}
	return
}
Example #3
0
func FilterSnippetsByUser(resp http.ResponseWriter, req *http.Request) {
	validated, _, enc, _ := routeinit.InitHandling(req, resp, []string{})
	session, _ := globalStore.Get(req, "session-name")
	sessionUser := session.ID
	if !validated {
		return
	}
	snippets, err := models.FindSnippetsByUser(sessionUser)
	snippetArray := SnippetsArrayResponse{&snippets}
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: false})
	} else {
		enc.Encode(routeinit.ApiResponse{Result: &snippetArray, Status: true})
	}
	return
}
Example #4
0
func DeleteSnippetById(resp http.ResponseWriter, req *http.Request) {
	validated, urlParams, enc, _ := routeinit.InitHandling(req, resp, []string{})
	if !validated {
		return
	}
	snippetId, ok := urlParams["snippet_id"]
	if ok != true {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: "Invalid URL", Status: false})
		return
	}
	_, err := models.DeleteSnippetById(snippetId)
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: false})
	} else {
		enc.Encode(routeinit.ApiResponse{Status: true})
	}
	return
}
Example #5
0
func FilterSnippetById(resp http.ResponseWriter, req *http.Request) {
	validated, urlParams, enc, _ := routeinit.InitHandling(req, resp, []string{})
	if !validated {
		return
	}
	snippetId, ok := urlParams["snippet_id"]
	session, _ := globalStore.Get(req, "session-name")
	session.Save(req, resp)
	resp = setSessionIDAsCookie(resp, session.ID)
	if ok != true {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: "Invalid URL", Status: false})
		return
	}
	snippet, err := models.FindSnippetById(snippetId)
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: ok})
	} else {
		enc.Encode(routeinit.ApiResponse{Result: &snippet, Status: true})
	}
	return
}
Example #6
0
func InstallDepsAsync(resp http.ResponseWriter, req *http.Request) {
	validated, _, enc, body := routeinit.InitHandling(req, resp, []string{
		"language",
		"uid",
		"sid",
		"snippet"})
	if !validated {
		return
	}

	sid := body["sid"].(string)
	if furywebsockets.SidToOperation[sid] == "" {
		sidDetails := setContainerContext(body)
		sidDetails["op"] = "install-deps"
		executeContainerAsync(sidDetails)
		furywebsockets.SidToOperation[sid] = "install-deps"
		enc.Encode(routeinit.ApiResponse{sidDetails["msg"].(string), "", nil, sidDetails["status"].(int)})
	} else {
		enc.Encode(routeinit.ApiResponse{"A " + furywebsockets.SidToOperation[sid] + " operation already running for current session", "", nil, 0})
	}
	return
}
Example #7
0
func CreateNewSnippet(resp http.ResponseWriter, req *http.Request) {
	validated, _, enc, body := routeinit.InitHandling(req, resp, []string{
		"language_code",
	})
	if !validated {
		return
	}
	session, _ := globalStore.Get(req, "session-name")
	session.Save(req, resp)
	resp = setSessionIDAsCookie(resp, session.ID)
	language := body["language_code"].(string)
	templateSnippet, _ := template.GetTemplateByLanguage(language)
	templateSnippet.Tags = []string{language}
	templateSnippet.SessionId = session.ID
	snippetId, ok, err := models.CreateSnippet(templateSnippet)
	if err != nil {
		enc.Encode(routeinit.ApiResponse{ErrorMessage: err.Error(), Status: ok})
	} else {
		ResponseResult := SnippetCreationResponse{snippetId}
		enc.Encode(routeinit.ApiResponse{Result: &ResponseResult, Status: ok})
	}
	return
}