diff --git a/assets/assets.go b/assets/assets.go index 97bdc2cc..9c4411fa 100644 --- a/assets/assets.go +++ b/assets/assets.go @@ -27,7 +27,7 @@ func load() { var err error // Manifest - Manifest, err = manifest.FromFile("manifest.json") + Manifest, err = manifest.FromFile("assets/manifest.json") if err != nil { panic("Couldn't load manifest.json") @@ -43,7 +43,7 @@ func load() { ServiceWorker = unsafe.BytesToString(data) // Organization - data, err = ioutil.ReadFile("organization.json") + data, err = ioutil.ReadFile("assets/organization.json") if err != nil { panic("Couldn't load organization.json") diff --git a/manifest.json b/assets/manifest.json similarity index 100% rename from manifest.json rename to assets/manifest.json diff --git a/organization.json b/assets/organization.json similarity index 100% rename from organization.json rename to assets/organization.json diff --git a/middleware/Firewall.go b/middleware/Firewall.go deleted file mode 100644 index a8e3ebf1..00000000 --- a/middleware/Firewall.go +++ /dev/null @@ -1,79 +0,0 @@ -package middleware - -// import ( -// "strings" -// "time" - -// "github.com/aerogo/aero" -// "github.com/akyoto/cache" -// "github.com/animenotifier/notify.moe/utils" -// ) - -// const requestThreshold = 10 - -// var ipToStats = cache.New(15 * time.Minute) - -// // IPStats captures the statistics for a single IP. -// type IPStats struct { -// Requests []string -// } - -// // Firewall middleware detects malicious requests. -// func Firewall() aero.Middleware { -// return func(ctx aero.Context, next func()) { -// var stats *IPStats - -// ip := ctx.IP() - -// // Allow localhost -// if ip == "127.0.0.1" { -// next() -// return -// } - -// statsObj, found := ipToStats.Get(ip) - -// if found { -// stats = statsObj.(*IPStats) -// } else { -// stats = &IPStats{ -// Requests: []string{}, -// } - -// ipToStats.Set(ip, stats, 15*time.Minute) -// } - -// // Add requested URI to the list of requests -// stats.Requests = append(stats.Requests, ctx.Path()) - -// if len(stats.Requests) > requestThreshold { -// stats.Requests = stats.Requests[len(stats.Requests)-requestThreshold:] - -// for _, uri := range stats.Requests { -// // Allow request -// if strings.Contains(uri, "/_/") || strings.Contains(uri, "/api/") || strings.Contains(uri, "/scripts") || strings.Contains(uri, "/service-worker") || strings.Contains(uri, "/images/") || strings.Contains(uri, "/favicon.ico") || strings.Contains(uri, "/extension/embed") { -// next() -// return -// } -// } - -// // Allow logged in users -// if ctx.HasSession() { -// user := utils.GetUser(ctx) - -// if user != nil { -// // Allow request -// next() -// return -// } -// } - -// // Disallow request -// request.Error("[guest]", ip, "BLOCKED BY FIREWALL", ctx.Path()) -// return -// } - -// // Allow the request if the number of requests done by the IP is below the threshold -// next() -// } -// } diff --git a/pages/database/types.go b/pages/database/types.go new file mode 100644 index 00000000..6ad20668 --- /dev/null +++ b/pages/database/types.go @@ -0,0 +1,21 @@ +package database + +import ( + "sort" + + "github.com/aerogo/aero" + "github.com/animenotifier/notify.moe/arn" +) + +// Types shows which types are available in the database. +func Types(ctx aero.Context) error { + typeMap := arn.DB.Types() + types := make([]string, 0, len(typeMap)) + + for typeName := range typeMap { + types = append(types, typeName) + } + + sort.Strings(types) + return ctx.JSON(types) +} diff --git a/pages/index/apiroutes/apiroutes.go b/pages/index/apiroutes/apiroutes.go index bdb01d63..0b9f40cb 100644 --- a/pages/index/apiroutes/apiroutes.go +++ b/pages/index/apiroutes/apiroutes.go @@ -9,6 +9,7 @@ import ( "github.com/animenotifier/notify.moe/pages/apiview" "github.com/animenotifier/notify.moe/pages/apiview/apidocs" "github.com/animenotifier/notify.moe/pages/character" + "github.com/animenotifier/notify.moe/pages/database" "github.com/animenotifier/notify.moe/pages/editor/jobs" "github.com/animenotifier/notify.moe/pages/me" "github.com/animenotifier/notify.moe/pages/notifications" @@ -50,6 +51,9 @@ func Register(app *aero.Application) { // Post app.Get("/api/post/:id/reply/ui", post.ReplyUI) + // Post + app.Get("/api/types", database.Types) + // SoundTrack app.Post("/api/soundtrack/:id/download", soundtrack.Download)