<commit_before>package editor

import (
	"github.com/fxnn/gone/failer"
	"github.com/fxnn/gone/filer"
	"github.com/fxnn/gone/router"
	"github.com/fxnn/gone/templates"
	"log"
	"net/http"
	"net/url"
)

// The Editor is a HTTP Handler that serves the editor UI.
// While the UI itself is implemented in a HTML template, this type
// implements the logic behind the UI.
type Editor struct {
	filer    filer.Filer
	template templates.EditorTemplate
}

// Initializes a new instance ready to use.
// The instance includes a loaded and parsed template.
func New() Editor {
	var template = templates.LoadEditorTemplate()
	if err := template.Err(); err != nil {
		panic(err)
	}

	return Editor{filer.New(), template}
}

func (e *Editor) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	if !e.filer.HasWriteAccessForRequest(request) {
		log.Printf("%s %s: no write permissions", request.Method, request.URL)
		failer.ServeUnauthorized(writer, request)
		return
	}

	if request.Method == "POST" {
		e.servePOST(writer, request)
		return
	}

	if request.Method == "GET" {
		e.serveGET(writer, request)
		return
	}

	log.Printf("%s %s: method not allowed", request.Method, request.URL)
	failer.ServeMethodNotAllowed(writer, request)
}

func (e *Editor) servePOST(writer http.ResponseWriter, request *http.Request) {
	var content = request.FormValue("content")
	if content == "" {<commit_msg>Read permission for editor needed<commit_after>package editor

import (
	"github.com/fxnn/gone/failer"
	"github.com/fxnn/gone/filer"
	"github.com/fxnn/gone/router"
	"github.com/fxnn/gone/templates"
	"log"
	"net/http"
	"net/url"
)

// The Editor is a HTTP Handler that serves the editor UI.
// While the UI itself is implemented in a HTML template, this type
// implements the logic behind the UI.
type Editor struct {
	filer    filer.Filer
	template templates.EditorTemplate
}

// Initializes a new instance ready to use.
// The instance includes a loaded and parsed template.
func New() Editor {
	var template = templates.LoadEditorTemplate()
	if err := template.Err(); err != nil {
		panic(err)
	}

	return Editor{filer.New(), template}
}

func (e *Editor) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
	if !e.filer.HasWriteAccessForRequest(request) {
		log.Printf("%s %s: no write permissions", request.Method, request.URL)
		failer.ServeUnauthorized(writer, request)
		return
	}

	if request.Method == "POST" {
		e.servePOST(writer, request)
		return
	}

	if !e.filer.HasReadAccessForRequest(request) {
		log.Printf("%s %s: no read permissions", request.Method, request.URL)
		failer.ServeUnauthorized(writer, request)
		return
	}

	if request.Method == "GET" {
		e.serveGET(writer, request)
		return
	}

	log.Printf("%s %s: method not allowed", request.Method, request.URL)
	failer.ServeMethodNotAllowed(writer, request)
}

func (e *Editor) servePOST(writer http.ResponseWriter, request *http.Request) {
	var content = request.FormValue("content")
	if content == "" {
{'fraction_non_alphanumeric': 0.1251257967125126, 'fraction_numerical': 0.0, 'mean_word_length': 4.287234042553192, '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': '716169', 'n_tokens_mistral': 1004, 'n_tokens_neox': 979, 'n_words': 272}