add the apps

This commit is contained in:
sewn 2024-03-18 19:47:24 +03:00
parent 8161b52b1c
commit 37021f9c14
No known key found for this signature in database
3 changed files with 81 additions and 2 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
xftc
xfts
/xftc
/xfts

68
cmd/xftc/main.go Normal file
View File

@ -0,0 +1,68 @@
package main
import (
"encoding/json"
"errors"
"fmt"
"net"
"os"
"github.com/apprehensions/xfts/internal/server"
)
func main() {
if len(os.Args) != 3 {
fmt.Fprintln(os.Stderr, "usage: %s src dest", os.Args[0])
os.Exit(1)
}
fi, err := os.Stat(os.Args[1])
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// xfiles sends EVERYTHING and ALL files to xfilesthumb
if fi.IsDir() || fi.Size() < 1 {
fmt.Println("skipping")
os.Exit(1)
}
err = send(server.Request{
Source: os.Args[1],
Destination: os.Args[2],
})
if err != nil {
fmt.Fprintf(os.Stderr, "send: %s\n", err)
os.Exit(1)
}
}
func send(r server.Request) error {
if _, err := os.Stat(r.Source); err != nil {
return err
}
conn, err := net.Dial("unix", server.Socket)
if err != nil {
return err
}
defer conn.Close()
if err := json.NewEncoder(conn).Encode(r); err != nil {
return err
}
buf := make([]byte, 1024)
n, err := conn.Read(buf)
if err != nil {
return err
}
resp := string(buf[:n])
if _, err := os.Stat(r.Destination); err != nil {
return errors.New(resp)
}
return nil
}

11
cmd/xfts/main.go Normal file
View File

@ -0,0 +1,11 @@
package main
import (
"log"
"github.com/apprehensions/xfts/internal/server"
)
func main() {
log.Fatal(server.Serve())
}