implement writing general content file

This commit is contained in:
Jonas Große Sundrup 2023-12-29 21:34:04 +01:00
parent d1fe37662a
commit 119b33f538
No known key found for this signature in database
GPG key ID: 5B587ADC0531D442

29
main.go
View file

@ -4,22 +4,23 @@
package main
import (
"bufio"
"flag"
"fmt"
"io"
"net"
"os"
"os/exec"
"bufio"
"strings"
"io"
"flag"
"github.com/google/uuid"
"time"
"github.com/google/uuid"
)
var (
CONN_HOST = "0.0.0.0"
CONN_PORT = "9100"
LOG_LEVEL = "error"
CONN_HOST = "0.0.0.0"
CONN_PORT = "9100"
LOG_LEVEL = "error"
XOCHITL_DIR = "/home/root/.local/share/remarkable/xochitl/"
)
@ -37,6 +38,11 @@ const METADATA_TEMPLATE = `{
}
`
//const CONTENT_TEMPLATE = `{
// "fileType": "pdf"
//}
//`
const CONTENT_TEMPLATE = "{}"
func main() {
@ -97,7 +103,6 @@ func check(e error) {
}
}
// Handles incoming requests.
func handleRequest(conn net.Conn) {
u, _ := uuid.NewRandom()
@ -160,5 +165,13 @@ func handleRequest(conn net.Conn) {
f.WriteString(fmt.Sprintf(METADATA_TEMPLATE, time.Now().Unix(), title))
f.Close()
// ----- Create .content -----
cont_path := XOCHITL_DIR + u.String() + ".content"
fmt.Println("Saving content file to", cont_path)
f, err = os.Create(cont_path)
f.WriteString(fmt.Sprintf(CONTENT_TEMPLATE))
f.Close()
conn.Close()
}