151 lines
3.6 KiB
Go
Raw Normal View History

2017-06-17 01:12:28 +02:00
package main
import (
2017-07-13 17:56:14 +02:00
"io/ioutil"
2017-06-17 01:12:28 +02:00
"github.com/aerogo/aero"
2017-11-18 16:01:27 +01:00
"github.com/aerogo/sitemap"
"github.com/animenotifier/arn"
2017-11-28 21:48:12 +01:00
"github.com/animenotifier/notify.moe/components/css"
"github.com/animenotifier/notify.moe/components/js"
2017-06-17 01:12:28 +02:00
)
2017-10-02 02:09:05 +02:00
// configureAssets adds all the routes used for media assets.
func configureAssets(app *aero.Application) {
2017-10-02 00:31:44 +02:00
// Script bundle
scriptBundle := js.Bundle()
// Service worker
2018-04-17 21:21:03 +02:00
serviceWorkerBytes, err := ioutil.ReadFile("scripts/ServiceWorker/ServiceWorker.js")
2017-07-13 17:56:14 +02:00
serviceWorker := string(serviceWorkerBytes)
2017-11-28 21:48:12 +01:00
// CSS bundle
cssBundle := css.Bundle()
2017-07-13 17:56:14 +02:00
if err != nil {
panic("Couldn't load service worker")
}
2017-06-21 02:02:30 +02:00
app.Get("/scripts", func(ctx *aero.Context) string {
2017-10-02 00:31:44 +02:00
return ctx.JavaScript(scriptBundle)
2017-06-21 02:02:30 +02:00
})
2017-11-28 21:48:12 +01:00
app.Get("/styles", func(ctx *aero.Context) string {
return ctx.CSS(cssBundle)
2017-06-23 13:28:54 +02:00
})
2017-07-13 17:56:14 +02:00
app.Get("/service-worker", func(ctx *aero.Context) string {
2017-10-02 00:31:44 +02:00
return ctx.JavaScript(serviceWorker)
2017-07-13 17:56:14 +02:00
})
2017-06-18 13:50:53 +02:00
// Web manifest
app.Get("/manifest.json", func(ctx *aero.Context) string {
return ctx.JSON(app.Config.Manifest)
2017-06-17 01:12:28 +02:00
})
2017-06-18 13:50:53 +02:00
// Favicon
app.Get("/favicon.ico", func(ctx *aero.Context) string {
2018-02-20 10:44:47 +01:00
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
2017-11-15 14:41:51 +01:00
return ctx.File("images/brand/64.png")
2017-06-18 13:50:53 +02:00
})
2017-11-11 18:08:56 +01:00
// Images
app.Get("/images/*file", func(ctx *aero.Context) string {
2018-02-20 10:44:47 +01:00
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
2018-05-31 23:20:32 +09:00
return ctx.File("images/" + ctx.Get("file"))
2017-06-17 01:12:28 +02:00
})
2017-11-13 18:07:25 +01:00
// Videos
app.Get("/videos/*file", func(ctx *aero.Context) string {
2018-02-20 10:44:47 +01:00
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
2018-05-31 23:20:32 +09:00
return ctx.File("videos/" + ctx.Get("file"))
2017-11-13 18:07:25 +01:00
})
2018-03-11 02:20:30 +01:00
// Audio
app.Get("/audio/*file", func(ctx *aero.Context) string {
ctx.Response().Header().Set("Access-Control-Allow-Origin", "*")
2018-05-31 23:20:32 +09:00
return ctx.File("audio/" + ctx.Get("file"))
2018-03-11 02:20:30 +01:00
})
2017-11-18 16:01:27 +01:00
// Anime sitemap
app.Get("/sitemap/anime.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for anime := range arn.StreamAnime() {
sitemap.Add(prefix + anime.Link())
}
return ctx.Text(sitemap.Text())
})
// Character sitemap
app.Get("/sitemap/character.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for character := range arn.StreamCharacters() {
sitemap.Add(prefix + character.Link())
}
return ctx.Text(sitemap.Text())
})
// User sitemap
app.Get("/sitemap/user.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for user := range arn.StreamUsers() {
if !user.HasNick() {
continue
}
2017-11-18 16:01:27 +01:00
sitemap.Add(prefix + user.Link())
}
return ctx.Text(sitemap.Text())
})
2017-11-18 16:11:54 +01:00
// SoundTrack sitemap
app.Get("/sitemap/soundtrack.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for soundTrack := range arn.StreamSoundTracks() {
sitemap.Add(prefix + soundTrack.Link())
}
return ctx.Text(sitemap.Text())
})
// Thread sitemap
app.Get("/sitemap/thread.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for thread := range arn.StreamThreads() {
sitemap.Add(prefix + thread.Link())
}
return ctx.Text(sitemap.Text())
})
// Post sitemap
app.Get("/sitemap/post.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for post := range arn.StreamPosts() {
sitemap.Add(prefix + post.Link())
}
return ctx.Text(sitemap.Text())
})
2017-06-17 01:12:28 +02:00
// For benchmarks
app.Get("/hello", func(ctx *aero.Context) string {
return ctx.Text("Hello World")
})
}