Added /api/types route
This commit is contained in:
parent
816ec3f591
commit
34cf83b1ac
@ -27,7 +27,7 @@ func load() {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
// Manifest
|
// Manifest
|
||||||
Manifest, err = manifest.FromFile("manifest.json")
|
Manifest, err = manifest.FromFile("assets/manifest.json")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Couldn't load manifest.json")
|
panic("Couldn't load manifest.json")
|
||||||
@ -43,7 +43,7 @@ func load() {
|
|||||||
ServiceWorker = unsafe.BytesToString(data)
|
ServiceWorker = unsafe.BytesToString(data)
|
||||||
|
|
||||||
// Organization
|
// Organization
|
||||||
data, err = ioutil.ReadFile("organization.json")
|
data, err = ioutil.ReadFile("assets/organization.json")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Couldn't load organization.json")
|
panic("Couldn't load organization.json")
|
||||||
|
@ -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()
|
|
||||||
// }
|
|
||||||
// }
|
|
21
pages/database/types.go
Normal file
21
pages/database/types.go
Normal file
@ -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)
|
||||||
|
}
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/pages/apiview"
|
"github.com/animenotifier/notify.moe/pages/apiview"
|
||||||
"github.com/animenotifier/notify.moe/pages/apiview/apidocs"
|
"github.com/animenotifier/notify.moe/pages/apiview/apidocs"
|
||||||
"github.com/animenotifier/notify.moe/pages/character"
|
"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/editor/jobs"
|
||||||
"github.com/animenotifier/notify.moe/pages/me"
|
"github.com/animenotifier/notify.moe/pages/me"
|
||||||
"github.com/animenotifier/notify.moe/pages/notifications"
|
"github.com/animenotifier/notify.moe/pages/notifications"
|
||||||
@ -50,6 +51,9 @@ func Register(app *aero.Application) {
|
|||||||
// Post
|
// Post
|
||||||
app.Get("/api/post/:id/reply/ui", post.ReplyUI)
|
app.Get("/api/post/:id/reply/ui", post.ReplyUI)
|
||||||
|
|
||||||
|
// Post
|
||||||
|
app.Get("/api/types", database.Types)
|
||||||
|
|
||||||
// SoundTrack
|
// SoundTrack
|
||||||
app.Post("/api/soundtrack/:id/download", soundtrack.Download)
|
app.Post("/api/soundtrack/:id/download", soundtrack.Download)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user