💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › 0d6637827c33bb123bc5a63f8b… captured on 2023-07-22 at 16:48:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-03-20)

➡️ Next capture (2023-09-08)

-=-=-=-=-=-=-

0 package repo

1

2 import (

3 "errors"

4 "gemigit/config"

5

6 "github.com/pitr/gig"

7

8 "bufio"

9 "crypto/tls"

10 "strconv"

11 "strings"

12 )

13

14 func request(url string) error {

15 conn, err := tls.Dial("tcp", config.Cfg.Git.Remote.Address + ":1965",

16 &tls.Config{InsecureSkipVerify: true})

17 if err != nil {

18 return err

19 }

20 defer conn.Close()

21 conn.Write([]byte("gemini://" + config.Cfg.Git.Remote.Address + "/" +

22 url + "\r\n"))

23

24 reader := bufio.NewReader(conn)

25 responseHeader, err := reader.ReadString('\n')

26 parts := strings.Fields(responseHeader)

27 status, err := strconv.Atoi(parts[0][0:2])

28 meta := strings.Join(parts[1:], " ")

29 if status == 20 {

30 return nil

31 }

32 return errors.New(meta)

33 }

34

35 func ApiInit(c gig.Context) error {

36 if c.Param("key") != config.Cfg.Git.Remote.Key {

37 return c.NoContent(gig.StatusBadRequest, "Invalid key")

38 }

39 err := InitRepo(c.Param("repo"), c.Param("username"))

40 if err != nil {

41 return c.NoContent(gig.StatusBadRequest, err.Error())

42 }

43 return c.Gemini("success")

44 }

45

46 func ApiRemove(c gig.Context) error {

47 if c.Param("key") != config.Cfg.Git.Remote.Key {

48 return c.NoContent(gig.StatusBadRequest, "Invalid key")

49 }

50 err := RemoveRepo(c.Param("repo"), c.Param("username"))

51 if err != nil {

52 return c.NoContent(gig.StatusBadRequest, err.Error())

53 }

54 return c.Gemini("success")

55 }

56

57 func ApiRename(c gig.Context) error {

58 if c.Param("key") != config.Cfg.Git.Remote.Key {

59 return c.NoContent(gig.StatusBadRequest, "Invalid key")

60 }

61 err := ChangeRepoDir(c.Param("repo"), c.Param("username"),

62 c.Param("newname"))

63 if err != nil {

64 return c.NoContent(gig.StatusBadRequest, err.Error())

65 }

66 return c.Gemini("success")

67 }

68