Kaynağa Gözat

added some modifs

Christian Marian - Work Dell 4 hafta önce
ebeveyn
işleme
15e42abd98

+ 4 - 0
cmds/webservice/bin/notite/notita-2026-03-05-142949.071361.json

@@ -0,0 +1,4 @@
+{
+  "titlu": "GPT",
+  "continut": "In Go, the layout you used:\r\n\r\n```go\r\ntime.Now().Format(\"2006-01-02-150405.666666\")\r\n```\r\n\r\ndoes **not show nanoseconds**, it shows **microseconds (6 digits)**.\r\n\r\n### Go time formatting rule\r\n\r\nGo uses the reference time:\r\n\r\n```\r\nMon Jan 2 15:04:05 MST 2006\r\n```\r\n\r\nFractional seconds are controlled by the number of `9` or `0` digits.\r\n\r\n### Nanoseconds (9 digits)\r\n\r\nUse **9 digits**:\r\n\r\n```go\r\ntime.Now().Format(\"2006-01-02-150405.000000000\")\r\n```\r\n\r\nExample output:\r\n\r\n```\r\n2026-03-05-143512.123456789\r\n```\r\n\r\n### Recommended way (auto trim zeros)\r\n\r\nBetter is using `9` instead of `0`:\r\n\r\n```go\r\ntime.Now().Format(\"2006-01-02-150405.999999999\")\r\n```\r\n\r\nExample outputs:\r\n\r\n```\r\n2026-03-05-143512.1\r\n2026-03-05-143512.12345\r\n2026-03-05-143512.123456789\r\n```\r\n\r\nTrailing zeros are removed.\r\n\r\n### If you want guaranteed nanoseconds\r\n\r\nUse:\r\n\r\n```go\r\ntime.Now().Format(\"2006-01-02-150405.000000000\")\r\n```\r\n\r\n### Alternative (manual)\r\n\r\nYou can also append them:\r\n\r\n```go\r\nt := time.Now()\r\nfmt.Printf(\"%s.%09d\\n\", t.Format(\"2006-01-02-150405\"), t.Nanosecond())\r\n```\r\n\r\nOutput:\r\n\r\n```\r\n2026-03-05-143512.123456789\r\n```\r\n\r\n---\r\n\r\n✅ **Summary**\r\n\r\n| Format       | Result              |\r\n| ------------ | ------------------- |\r\n| `.666666`    | microseconds        |\r\n| `.000000000` | nanoseconds fixed   |\r\n| `.999999999` | nanoseconds trimmed |\r\n\r\n---\r\n\r\nIf you're using this for **unique filenames**, I can show a **better collision-safe timestamp format used in high-performance Go systems**.\r\n"
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 2 - 0
cmds/webservice/bin/notite/notita-2026-03-05-144330.586623.json


BIN
cmds/webservice/bin/templates/favicon.ico


+ 53 - 0
cmds/webservice/bin/templates/index.html

@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+
+<html lang="en">
+
+<head>
+  <title>Site Fain </title>
+  <script src="https://cdn.tailwindcss.com"></script>
+
+</head>
+
+<body>
+  <div class="min-h-screen bg-[#0f0f0f] flex items-center justify-center p-6 font-sans">
+
+    <div class="w-full max-w-md bg-[#1a1a1a] border border-[#303030] rounded-xl shadow-2xl p-8">
+
+      <div class="mb-8">
+        <h2 class="text-[#9974d0] text-2xl font-bold tracking-tight">Notă Nouă</h2>
+        <p class="text-gray-500 text-sm mt-1">Salvare în arhiva locală .md</p>
+      </div>
+
+      <form class="space-y-6" method="POST" action="api/save_note">
+        <div>
+          <label class="block text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Titlu Fișier</label>
+          <input type="text" name="titlu" placeholder="ex: Plan de idei 2026"
+            class="w-full bg-[#202020] border border-[#3e3e3e] text-gray-200 text-sm rounded-lg focus:ring-2 focus:ring-[#7b58ad] focus:border-transparent outline-none p-3 transition-all placeholder:text-gray-600">
+        </div>
+
+        <div>
+          <label class="block text-xs font-semibold text-gray-400 uppercase tracking-wider mb-2">Conținut Notita</label>
+          <textarea rows="5" name="notita" placeholder="Începe să scrii..."
+            class="w-full bg-[#202020] border border-[#3e3e3e] text-gray-200 text-sm rounded-lg focus:ring-2 focus:ring-[#7b58ad] focus:border-transparent outline-none p-3 transition-all placeholder:text-gray-600 resize-none"></textarea>
+        </div>
+
+        <button type="submit"
+          class="w-full bg-[#7b58ad] hover:bg-[#9974d0] text-white font-bold py-3 px-4 rounded-lg transition-colors duration-200 shadow-lg shadow-purple-900/20">
+          Creează Notă
+        </button>
+      </form>
+
+      <div
+        class="mt-6 pt-6 border-t border-[#303030] flex justify-between items-center text-[10px] text-gray-600 uppercase tracking-widest">
+        <span>Status: Ready</span>
+        <span class="flex items-center gap-1">
+          <span class="w-1.5 h-1.5 bg-green-500 rounded-full"></span> Linked
+        </span>
+      </div>
+
+    </div>
+  </div>
+
+</body>
+
+</html>

+ 0 - 11
cmds/webservice/bin/templates/index.tmpl

@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-
-<html lang = "en">
-    <head>
-    <title>Site Fain </title>
-    </head>
-    <body>
-    <form action = "/testul" method = "get"><button type = "submit">Apasa-ma</button></form>
-    </body>
-
-</html>

+ 79 - 0
cmds/webservice/bin/templates/notita.tmpl

@@ -0,0 +1,79 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Obsidian Style Fixed</title>
+    <script src="https://cdn.tailwindcss.com"></script>
+    <style>
+        :root {
+            --bg-main: #161616;
+            --bg-card: #1c1c1c;
+            --border: #303030;
+            --text-muted: #a3a3a3;
+            --text-faint: #666666;
+            --accent: #9974d0;
+            --code-bg: #000000;
+        }
+
+        body {
+            background-color: var(--bg-main);
+            color: #dcddde;
+            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
+            line-height: 1.6;
+        }
+
+        /* Scoping everything inside a container to avoid global mess */
+        .obsidian-content {
+            max-width: 850px;
+            margin: 40px auto;
+            background: var(--bg-card);
+            padding: 4rem;
+            border-radius: 8px;
+            border: 1px solid var(--border);
+            box-shadow: 0 20px 50px rgba(0,0,0,0.3);
+        }
+
+        /* Direct Tag Styling */
+        h1 { color: var(--accent); font-size: 4rem!important; font-weight: 700; margin-bottom: 1.5rem; }
+        h2 { color: var(--accent); font-size: 1.5rem; border-bottom: 1px solid var(--border); padding-bottom: 8px; margin-top: 2.5rem; margin-bottom: 1rem; }
+        h3 { color: var(--text-muted); font-size: 1.1rem; text-transform: uppercase; letter-spacing: 1px; margin-top: 1.5rem; }
+        
+        p { margin-bottom: 1.2rem; color: #bdbdbd; }
+        strong { color: #fff; font-weight: 600; }
+        
+        hr { border: 0; border-top: 1px solid var(--border); margin: 3rem 0; }
+
+        /* Code Block Styling */
+        pre {
+            background-color: var(--code-bg) !important;
+            padding: 1.5rem;
+            border-radius: 6px;
+            border: 1px solid var(--border);
+            overflow-x: auto;
+            margin: 1.5rem 0;
+        }
+
+        code {
+            font-family: 'Consolas', 'Monaco', monospace;
+            font-size: 0.95rem;
+            color: #e0e0e0;
+        }
+
+        /* List Styling */
+        ul { list-style: none; padding-left: 0; }
+        li::before { content: "•"; color: var(--accent); font-weight: bold; display: inline-block; width: 1em; margin-left: 0; }
+
+        /* Table Styling */
+        table { width: 100%; border-collapse: collapse; margin: 2rem 0; font-size: 0.9rem; }
+        th { text-align: left; padding: 12px; background: #252525; border: 1px solid var(--border); color: var(--accent); }
+        td { padding: 12px; border: 1px solid var(--border); }
+    </style>
+</head>
+<body class="p-4 md:p-12">
+
+<div class="obsidian-content">
+    <h1>{{.Titlu}}</h1>
+    {{.HTML}}
+</body>
+</html>

+ 41 - 0
cmds/webservice/bin/templates/test.css

@@ -0,0 +1,41 @@
+/* ASTA E CSS-ul */
+.obsidian-form {
+    background-color: #1a1a1a; /* Fundalul clasic Obsidian */
+    color: #dcddde;
+    padding: 25px;
+    border-radius: 8px;
+    font-family: 'Inter', sans-serif;
+    border: 1px solid #303030;
+    max-width: 400px;
+  }
+
+  h2 { color: #9974d0; margin-top: 0; } /* Accent mov */
+
+  .input-group { margin-bottom: 15px; }
+
+  label { display: block; margin-bottom: 5px; font-size: 0.9em; color: #a3a3a3; }
+
+  input, textarea {
+    width: 100%;
+    background: #202020;
+    border: 1px solid #3e3e3e;
+    border-radius: 4px;
+    padding: 10px;
+    color: white;
+    outline: none;
+  }
+
+  input:focus, textarea:focus { border-color: #7b58ad; }
+
+  button {
+    background-color: #7b58ad;
+    color: white;
+    border: none;
+    padding: 10px 20px;
+    border-radius: 4px;
+    cursor: pointer;
+    font-weight: bold;
+    width: 100%;
+  }
+
+  button:hover { background-color: #9974d0; }

+ 7 - 0
cmds/webservice/types/types.go

@@ -0,0 +1,7 @@
+package types
+
+type Notita struct {
+	Titlu    string `json:"titlu"`
+	Continut string `json:"continut"`
+	HTML     string `json:"-"`
+}

+ 2 - 2
lib/inout/file.go

@@ -6,7 +6,7 @@ import (
 )
 
 func SaveObjToFile(filename string, data []byte) error {
-	return os.WriteFile("mynotes_cfg.json", data, os.ModePerm)
+	return os.WriteFile(filename, data, os.ModePerm)
 
 }
 
@@ -17,7 +17,7 @@ func ReadFile(filename string) ([]byte, error) {
 func FileToBytes(filename string) []byte {
 	data, err := os.ReadFile(filename)
 	if err != nil {
-		return []byte(fmt.Sprintf("%+v", err))
+		return fmt.Appendf(nil, "%+v", err)
 
 	}
 	return data

+ 5 - 0
lib/server/consts.go

@@ -0,0 +1,5 @@
+package server
+
+const (
+	WEB_ERR = "ASTA E TOT CE STIM"
+)

+ 2 - 0
lib/server/go.mod

@@ -1,3 +1,5 @@
 module git.linuxit.ro/turos.robert/mynotes/lib/server
 
 go 1.25.0
+
+require github.com/yuin/goldmark v1.7.16

+ 2 - 0
lib/server/go.sum

@@ -0,0 +1,2 @@
+github.com/yuin/goldmark v1.7.16 h1:n+CJdUxaFMiDUNnWC3dMWCIQJSkxH4uz3ZwQBkAlVNE=
+github.com/yuin/goldmark v1.7.16/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=

+ 81 - 1
lib/server/handlers.go

@@ -1,19 +1,27 @@
 package server
 
 import (
+	"bytes"
+	"fmt"
 	"net/http"
 	"os"
 	"path/filepath"
 	"strings"
+	"text/template"
+	"time"
 
+	"git.linuxit.ro/turos.robert/mynotes/cmds/webservice/types"
 	"git.linuxit.ro/turos.robert/mynotes/lib/inout"
+	"github.com/yuin/goldmark"
 )
 
 func Wildcard(w http.ResponseWriter, r *http.Request) {
 
 	if r.Method == "GET" {
+		base_dir := "./templates/"
 		endpoint := strings.TrimPrefix(r.URL.Path, "/")
-		if endpoint == "" {
+		fmt.Println(endpoint)
+		/*if endpoint == "" {
 			//in cazul in care apelam root
 			endpoint = "index"
 		}
@@ -23,9 +31,81 @@ func Wildcard(w http.ResponseWriter, r *http.Request) {
 			w.WriteHeader(http.StatusNotFound)
 			w.Write(inout.FileToBytes("templates/error.tmpl"))
 			return
+		}*/
+		path := filepath.Join(base_dir, endpoint)
+		_, err := os.Stat(path)
+		if err != nil {
+			w.WriteHeader(http.StatusInternalServerError)
+			w.Write(inout.FileToBytes("templates/error.tmpl"))
 		}
 		w.Write(inout.FileToBytes(path))
 		return
 	}
 
 }
+
+func API(w http.ResponseWriter, r *http.Request, notesFolder string) {
+	action := strings.TrimPrefix(r.URL.Path, "/api/")
+	if r.Method == "POST" {
+		//w.WriteHeader(http.StatusNotImplemented)
+		//w.Write(fmt.Appendf(nil, "action not implemented: %s", action))
+		switch action {
+		case "save_note":
+			r.ParseForm()
+			fisier := fmt.Sprintf("notita-%s.json", time.Now().Format("2006-01-02-150405.999999"))
+			//fmt.Println(fisier, r.Form)
+			//return
+			n := types.Notita{}
+			n.Titlu = r.Form.Get("titlu")
+			n.Continut = r.Form.Get("notita")
+			err := inout.ObjToFile(filepath.Join(notesFolder, fisier), n, true)
+			if err != nil {
+				w.WriteHeader(http.StatusInternalServerError)
+				fmt.Fprintf(w, "%+v", err)
+				return
+			}
+			referinta := r.Referer()
+			if referinta != "" {
+				http.Redirect(w, r, referinta, http.StatusSeeOther)
+			} else {
+				http.Redirect(w, r, "/index.html", http.StatusSeeOther)
+			}
+		}
+	}
+	w.WriteHeader(http.StatusMethodNotAllowed)
+	w.Write([]byte("methoda nepermisa"))
+}
+
+func Notes(w http.ResponseWriter, r *http.Request, fisier string) {
+	var buf bytes.Buffer
+	notita := types.Notita{}
+	err := inout.FileToObj(fisier, &notita)
+	if err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		w.Write([]byte(WEB_ERR))
+		fmt.Printf("%+v\n", err)
+		return
+	}
+	if err := goldmark.Convert([]byte(notita.Continut), &buf); err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		w.Write([]byte(WEB_ERR))
+		fmt.Printf("%+v\n", err)
+		return
+	}
+	notita.HTML = buf.String()
+	tmpl := template.New("notita")
+	_, err = tmpl.ParseFiles("./templates/notita.tmpl")
+	if err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		w.Write([]byte(WEB_ERR))
+		fmt.Printf("%+v\n", err)
+		return
+	}
+	err = tmpl.ExecuteTemplate(w, "notita.tmpl", notita)
+	if err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		w.Write([]byte(WEB_ERR))
+		fmt.Printf("%+v\n", err)
+		return
+	}
+}

+ 8 - 8
lib/server/srv.go

@@ -18,17 +18,17 @@ func NewServer(filename string) *Server {
 
 }
 
-func Ceva(s *Server) http.HandlerFunc {
-	return func(w http.ResponseWriter, r *http.Request) {
-		//s.Err = fmt.Errorf("bla")
-		s_json := inout.ObjToJson(s)
-		w.Write([]byte(s_json))
-	}
-}
 func (s *Server) Run() {
+	fmt.Println(s.Port, s.Host)
 	// adding endpoints to the server
 	http.HandleFunc("/", Wildcard)
-	http.Handle("/dada", Ceva(s))
+	http.HandleFunc("/api/", func(w http.ResponseWriter, r *http.Request) {
+		API(w, r, "notes")
+	})
+	http.HandleFunc("/notes/", func(w http.ResponseWriter, r *http.Request) {
+		note := r.URL.Query().Get("note")
+		Notes(w, r, note)
+	})
 
 	//running server
 	fmt.Printf("Server running at http://%s:%s/\n", s.Host, s.Port)

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor