diff --git a/INSTALL.md b/INSTALL.md deleted file mode 100644 index e24d44e..0000000 --- a/INSTALL.md +++ /dev/null @@ -1,11 +0,0 @@ -# Installation - -```shell -$ git clone git://git.chaotic.ninja/yakumo_izuru/mai -$ cd mai -$ make -# make PREFIX=/usr/local install -``` -* Read the [mai.ini(5)](mai.ini.5) manual page -* Use any web server than is able to reverse proxy, like [Apache](https://httpd.apache.org), [h2o](https://h2o.examp1e.net), or [NGINX](https://www.nginx.com). - * Examples are provided on the repository diff --git a/INSTANCES.md b/INSTANCES.md deleted file mode 100644 index 65cefa3..0000000 --- a/INSTANCES.md +++ /dev/null @@ -1,6 +0,0 @@ -# List of known instances - -| Name | Cloudflare? | Country | URL | Engines supported | -|---------------------------------------------|-------------|---------|--------------------------|-------------------| -| Chaotic Ninja Communication Network Limited | No | Germany | https://tr.chaotic.ninja | Google, Reverso | -| | | | | | diff --git a/LEGAL.md b/LEGAL.md deleted file mode 100644 index 4c35c76..0000000 --- a/LEGAL.md +++ /dev/null @@ -1,9 +0,0 @@ -Mai does not host any content. All content shown on any Mai instances is from [Google Translate](https://translate.google.com), [Reverso](https://www.reverso.net/), and [LibreTranslate](https://libretranslate.com) - -Mai is not affiliated with none of the above, which this program relays. - -Trademarks belong to their respective owners. -Google Translate is a trademark of [Google LLC](https://www.google.com). Reverso is a trademark of Reverso, et cetera. - -The creators and maintainers of this repository assume no liability for the accuracy and timeliness of any information provided above. Trademark owner information was researched to the best of the author's knowledge at the time of curation and may be outdated or incorrect. - diff --git a/Makefile b/Makefile index 6297a7c..55e284a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ +GO ?= go PREFIX ?= /usr/local -GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=${VERSION} -X `go list`.Commit=${COMMIT}" -VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "VERSION"` -COMMIT = `git rev-parse --short HEAD || echo "COMMIT"` +GOFLAGS ?= -v -ldflags "-w -X `${GO} list`.Version=${VERSION}" +VERSION ?= 2025.04.17 build: - go build ${GOFLAGS} ./cmd/mai + ${GO} build ${GOFLAGS} ./cmd/mai clean: rm -f mai install: diff --git a/cmd/mai/main.go b/cmd/mai/main.go index 247c933..9ea2f4c 100644 --- a/cmd/mai/main.go +++ b/cmd/mai/main.go @@ -12,8 +12,8 @@ import ( "strings" "syscall" - "marisa.chaotic.ninja/mai" - "marisa.chaotic.ninja/mai/engines" + "mahou-no-mori.yakumo.dev/mai" + "mahou-no-mori.yakumo.dev/mai/engines" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/favicon" @@ -24,36 +24,38 @@ import ( ) var ( configfile string - groupname string - username string + verbose bool ) var conf struct { - danmaku int + group string listen string - staticpath string - tmplpath string + requests int + static string + templates string + user string } func MaiSkipLimiter(c *fiber.Ctx) bool { // Paths listed here are not considered for rate limiting path := c.Path() - return strings.HasPrefix(path, "/static") || - strings.HasPrefix(path, "/docs") + return strings.HasPrefix(path, "/static") } func main() { parseFlags() + conf.listen = "127.0.0.1:5000" + conf.requests = 5 + conf.static = "./static" + conf.templates = "./views" + if configfile != "" { + if verbose { + log.Printf("Reading configuration from %s", configfile) + } readConf(configfile) } - // Default settings - conf.danmaku = 10 - conf.listen = "127.0.0.1:5000" - conf.staticpath = "./static" - conf.tmplpath = "./views" - - if username != "" { - uid, gid, err := usergroupids(username, groupname) + if conf.user != "" { + uid, gid, err := usergroupids(conf.user, conf.group) if err != nil { log.Fatal(err) } @@ -61,7 +63,7 @@ func main() { syscall.Setgid(gid) } - engine := html.New(conf.tmplpath, ".html") + engine := html.New(conf.templates, ".html") engine.AddFunc("inc", func(i int) int { return i + 1 }) server := fiber.New( @@ -85,7 +87,7 @@ func main() { server.Use(favicon.New( favicon.Config{ - File: conf.staticpath + "/favicon.ico", + File: conf.static + "/favicon.ico", }, )) @@ -100,7 +102,7 @@ func main() { server.Use(limiter.New(limiter.Config{ Next: MaiSkipLimiter, - Max: conf.danmaku, + Max: conf.requests, Expiration: 30 * time.Second, LimiterMiddleware: limiter.SlidingWindow{}, LimitReached: func(c *fiber.Ctx) error { @@ -296,7 +298,7 @@ func main() { }) server.Get("/toomanyrequests", func(c *fiber.Ctx) error { - return c.SendFile(conf.tmplpath + "/429.html") + return c.SendFile(conf.templates + "/429.html") return c.SendStatus(429) }) @@ -325,13 +327,10 @@ func main() { } return c.Redirect("/") }) - server.Static("/static", conf.staticpath, fiber.Static{ - Compress: true, + server.Static("/static", conf.static, fiber.Static{ ByteRange: true, Browse: true, }) - server.Static("/docs", "./docs", fiber.Static{}) - server.Listen(conf.listen) } diff --git a/cmd/mai/parseflags.go b/cmd/mai/parseflags.go index 4969f9e..bd57bc6 100644 --- a/cmd/mai/parseflags.go +++ b/cmd/mai/parseflags.go @@ -7,7 +7,6 @@ import ( func parseFlags() { flag.StringVar(&configfile, "f", "", "Configuration file") - flag.StringVar(&username, "u", "", "Sets the user to which privilege dropping is done") - flag.StringVar(&groupname, "g", "", "Sets the group to which privilege dropping is done") + flag.BoolVar(&verbose, "v", false, "Be verbose") flag.Parse() } diff --git a/cmd/mai/readconf.go b/cmd/mai/readconf.go index e7b03ba..94ae923 100644 --- a/cmd/mai/readconf.go +++ b/cmd/mai/readconf.go @@ -10,11 +10,13 @@ func readConf(file string) error { if err != nil { return err } - conf.danmaku, _ = cfg.Section("mai").Key("danmaku").Int() - conf.listen = cfg.Section("mai").Key("listen").String() - conf.staticpath = cfg.Section("mai").Key("static").String() - conf.tmplpath = cfg.Section("mai").Key("templates").String() + conf.group = cfg.Section("mai").Key("group").String() + conf.listen = cfg.Section("http").Key("listen").String() + conf.requests, _ = cfg.Section("http").Key("requests").Int() + conf.static = cfg.Section("paths").Key("static").String() + conf.templates = cfg.Section("paths").Key("templates").String() + conf.user = cfg.Section("mai").Key("user").String() return nil } diff --git a/docs/api/index.html b/docs/api/index.html deleted file mode 100644 index 4a96142..0000000 --- a/docs/api/index.html +++ /dev/null @@ -1,74 +0,0 @@ - - -
- - - -
- [GET] /api/translate-[POST] /api/translate-Description-Translation endpoint, input must be URL-encoded (e.g. multi-byte characters, words separated by space) -Arguments-
|
-
- [GET] /api/source_languages-[GET] /api/target_languages-Description-Get a JSON array of supported source and target languages for a particular engine -Arguments-
|
-
- [GET] /api/tts-Description-Obtain text-to-speech audio files from an engine, provided said engine supports them -Arguments-
|
-
- [GET] /robots.txt- |
-
- [POST] /switchlanguages-Description-Switch between source and target languages, as long as the source language isn't "auto" -Must only be called inside the form interface - |
-
- [GET] /version-Description-Return the software version as a JSON array - |
-
-
| |
-
|