<commit_before>package shutdown

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"os/exec"
	"strconv"

	"github.com/vblazhnov/RemoteControl/interfaces"
)

// Shutdown shutdown the local machine
type Shutdown struct {
}

// GetHandlers implemintation of interfaces.EndPointInfo
func (sh Shutdown) GetHandlers() []interfaces.EndPointInfo {
	handlers := []interfaces.EndPointInfo{
		interfaces.BaseEndPointInfo{
			"/api/v1/shutdown",
			apiServeRequest,
			interfaces.EndPointAPI},
		interfaces.BaseEndPointInfo{
			"/shutdown",
			contentServeRequest,
			interfaces.EndPointContent},
	}

	return handlers
}

func contentServeRequest(
	w http.ResponseWriter,
	r *http.Request) {
	f, e := ioutil.ReadFile(".\\plugins\\shutdown\\static\\index.html")
	if e != nil {
		fmt.Fprint(w, e)
	}
	w.Write(f)
}

func apiServeRequest(
	w http.ResponseWriter,
	r *http.Request) {
	secStr := r.FormValue("sec")

	sec, err := strconv.Atoi(secStr)
	if err != nil {
		sec = 0
	}
	abort()
	if sec != 0 {
		start(sec)
	}
	fmt.Fprint(w, sec)
}

func abort() {
	run("/a")
}

func start(sec int) {
	run("/s", "/t", strconv.Itoa(sec))
}

func run(args ...string) {
	cmd := exec.Command("shutdown", args...)
	err := cmd.Run()
	if err != nil {
		log.Println("error: " + err.Error())<commit_msg>Fix error when incorrect parameter aborting shutdown<commit_after>package shutdown

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"os/exec"
	"strconv"

	"github.com/vblazhnov/RemoteControl/interfaces"
)

// Shutdown shutdown the local machine
type Shutdown struct {
}

// GetHandlers implemintation of interfaces.EndPointInfo
func (sh Shutdown) GetHandlers() []interfaces.EndPointInfo {
	handlers := []interfaces.EndPointInfo{
		interfaces.BaseEndPointInfo{
			"/api/v1/shutdown",
			apiServeRequest,
			interfaces.EndPointAPI},
		interfaces.BaseEndPointInfo{
			"/shutdown",
			contentServeRequest,
			interfaces.EndPointContent},
	}

	return handlers
}

func contentServeRequest(
	w http.ResponseWriter,
	r *http.Request) {
	f, e := ioutil.ReadFile(".\\plugins\\shutdown\\static\\index.html")
	if e != nil {
		fmt.Fprint(w, e)
	}
	w.Write(f)
}

func apiServeRequest(
	w http.ResponseWriter,
	r *http.Request) {
	secStr := r.FormValue("sec")

	sec, err := strconv.Atoi(secStr)
	if err != nil {
		sec = 0
	}
	if sec != 0 {
		abort()
		start(sec)
		fmt.Fprint(w, sec)
	} else {
		http.Error(w, http.StatusText(500), 500)
	}
}

func abort() {
	run("/a")
}

func start(sec int) {
	run("/s", "/t", strconv.Itoa(sec))
}

func run(args ...string) {
	cmd := exec.Command("shutdown", args...)
	err := cmd.Run()
	if err != nil {
		log.Println("error: " + err.Error())
{'fraction_non_alphanumeric': 0.1613394216133942, 'fraction_numerical': 0.0045662100456621, 'mean_word_length': 3.7974452554744524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1978513', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1023, 'n_words': 207}