2016-11-09 20:32:19 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-06-12 21:11:20 +02:00
|
|
|
"errors"
|
|
|
|
"net/http"
|
2017-06-15 19:56:09 +02:00
|
|
|
"os"
|
2017-06-12 21:11:20 +02:00
|
|
|
|
2016-11-09 22:11:49 +09:00
|
|
|
"github.com/aerogo/aero"
|
2017-06-08 23:26:58 +02:00
|
|
|
"github.com/animenotifier/arn"
|
2016-11-13 01:40:16 +09:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
2017-06-15 23:03:55 +02:00
|
|
|
"github.com/animenotifier/notify.moe/layout"
|
2016-11-23 12:44:28 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/airing"
|
2016-11-19 23:54:31 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/anime"
|
2017-06-08 11:51:34 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/awards"
|
2017-06-02 16:17:58 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/dashboard"
|
2016-11-19 23:54:31 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/forum"
|
2016-11-20 03:02:33 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/forums"
|
2016-11-22 12:34:59 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/posts"
|
2016-11-20 19:26:11 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/profile"
|
2016-11-22 12:34:59 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/search"
|
2016-11-19 23:54:31 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/threads"
|
2016-12-06 12:36:31 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/users"
|
2016-11-09 20:32:19 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
var app = aero.New()
|
|
|
|
|
|
|
|
func main() {
|
2016-12-03 00:23:05 +09:00
|
|
|
// HTTPS
|
2016-12-06 12:36:31 +09:00
|
|
|
app.Security.Load("security/fullchain.pem", "security/privkey.pem")
|
2016-12-03 00:23:05 +09:00
|
|
|
|
2017-06-11 11:13:59 +02:00
|
|
|
// CSS
|
|
|
|
app.SetStyle(components.CSS())
|
|
|
|
|
2017-06-08 23:26:58 +02:00
|
|
|
// Session store
|
|
|
|
app.Sessions.Store = arn.NewAerospikeStore("Session")
|
|
|
|
|
2016-11-29 01:06:00 +09:00
|
|
|
// Layout
|
2017-06-15 23:03:55 +02:00
|
|
|
app.Layout = layout.Render
|
2016-11-09 20:32:19 +09:00
|
|
|
|
2017-06-15 19:56:09 +02:00
|
|
|
// Production or Development mode
|
|
|
|
host, _ := os.Hostname()
|
|
|
|
isProduction := host != "home"
|
|
|
|
|
|
|
|
if !isProduction {
|
|
|
|
app.Config.Domain = "beta.notify.moe"
|
|
|
|
}
|
|
|
|
|
2016-11-29 01:06:00 +09:00
|
|
|
// Ajax routes
|
2017-06-02 16:17:58 +02:00
|
|
|
app.Ajax("/", dashboard.Get)
|
2016-11-22 12:34:59 +09:00
|
|
|
app.Ajax("/anime", search.Get)
|
2016-11-19 23:54:31 +09:00
|
|
|
app.Ajax("/anime/:id", anime.Get)
|
2016-11-20 03:02:33 +09:00
|
|
|
app.Ajax("/forum", forums.Get)
|
2016-11-19 23:54:31 +09:00
|
|
|
app.Ajax("/forum/:tag", forum.Get)
|
|
|
|
app.Ajax("/threads/:id", threads.Get)
|
2016-11-22 12:34:59 +09:00
|
|
|
app.Ajax("/posts/:id", posts.Get)
|
2016-11-20 19:26:11 +09:00
|
|
|
app.Ajax("/user/:nick", profile.Get)
|
2017-06-08 14:46:38 +02:00
|
|
|
app.Ajax("/user/:nick/threads", threads.GetByUser)
|
2016-12-06 12:36:31 +09:00
|
|
|
app.Ajax("/users", users.Get)
|
2017-06-10 02:19:31 +02:00
|
|
|
app.Ajax("/airing", airing.Get)
|
2017-06-08 11:51:34 +02:00
|
|
|
app.Ajax("/awards", awards.Get)
|
2017-06-11 11:13:59 +02:00
|
|
|
// app.Ajax("/genres", genres.Get)
|
|
|
|
// app.Ajax("/genres/:name", genre.Get)
|
2017-06-06 16:59:04 +02:00
|
|
|
|
2017-06-06 13:07:42 +02:00
|
|
|
// Favicon
|
|
|
|
app.Get("/favicon.ico", func(ctx *aero.Context) string {
|
2017-06-15 23:03:55 +02:00
|
|
|
return ctx.Image("images/icons/favicon", ".png")
|
2017-06-01 15:38:08 +02:00
|
|
|
})
|
|
|
|
|
2017-06-11 11:13:59 +02:00
|
|
|
// Scripts
|
|
|
|
app.Get("/scripts.js", func(ctx *aero.Context) string {
|
|
|
|
return ctx.File("temp/scripts.js")
|
|
|
|
})
|
|
|
|
|
2017-06-06 13:07:42 +02:00
|
|
|
// Web manifest
|
|
|
|
app.Get("/manifest.json", func(ctx *aero.Context) string {
|
|
|
|
return ctx.JSON(app.Config.Manifest)
|
2017-06-05 20:21:06 +02:00
|
|
|
})
|
|
|
|
|
2017-06-16 18:12:18 +02:00
|
|
|
// SVG icons
|
|
|
|
app.Get("/icons/:file", func(ctx *aero.Context) string {
|
|
|
|
return ctx.File("images/icons/svg/" + ctx.Get("file") + ".svg")
|
|
|
|
})
|
|
|
|
|
2017-06-11 11:13:59 +02:00
|
|
|
// Cover image
|
|
|
|
app.Get("/images/cover/:file", func(ctx *aero.Context) string {
|
2017-06-15 23:03:55 +02:00
|
|
|
return ctx.Image("images/cover/"+ctx.Get("file"), ".jpg")
|
|
|
|
})
|
2017-06-11 11:13:59 +02:00
|
|
|
|
2017-06-15 23:03:55 +02:00
|
|
|
// Login buttons
|
|
|
|
app.Get("/images/login/:file", func(ctx *aero.Context) string {
|
|
|
|
return ctx.File("images/login/" + ctx.Get("file") + ".png")
|
2017-06-06 15:51:22 +02:00
|
|
|
})
|
|
|
|
|
2017-06-12 21:11:20 +02:00
|
|
|
// Avatars
|
|
|
|
app.Get("/user/:nick/avatar", func(ctx *aero.Context) string {
|
|
|
|
nick := ctx.Get("nick")
|
|
|
|
user, err := arn.GetUserByNick(nick)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "User not found", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.CanUseWebP() {
|
2017-06-13 13:23:54 +02:00
|
|
|
return ctx.File("images/avatars/large/webp/" + user.ID + ".webp")
|
2017-06-12 21:11:20 +02:00
|
|
|
}
|
|
|
|
|
2017-06-13 15:08:10 +02:00
|
|
|
original := arn.FindFileWithExtension(
|
|
|
|
user.ID,
|
|
|
|
"images/avatars/large/original/",
|
|
|
|
arn.OriginalImageExtensions,
|
|
|
|
)
|
|
|
|
|
|
|
|
if original == "" {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Avatar not found", errors.New("Image not found for user: "+user.ID))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.File(original)
|
2017-06-12 21:11:20 +02:00
|
|
|
})
|
|
|
|
|
2017-06-13 00:06:35 +02:00
|
|
|
// Avatars
|
|
|
|
app.Get("/user/:nick/avatar/small", func(ctx *aero.Context) string {
|
|
|
|
nick := ctx.Get("nick")
|
|
|
|
user, err := arn.GetUserByNick(nick)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "User not found", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.CanUseWebP() {
|
2017-06-13 13:23:54 +02:00
|
|
|
return ctx.File("images/avatars/small/webp/" + user.ID + ".webp")
|
2017-06-13 00:06:35 +02:00
|
|
|
}
|
|
|
|
|
2017-06-13 15:08:10 +02:00
|
|
|
original := arn.FindFileWithExtension(
|
|
|
|
user.ID,
|
|
|
|
"images/avatars/small/original/",
|
|
|
|
arn.OriginalImageExtensions,
|
|
|
|
)
|
|
|
|
|
|
|
|
if original == "" {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Avatar not found", errors.New("Image not found for user: "+user.ID))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ctx.File(original)
|
2017-06-13 00:06:35 +02:00
|
|
|
})
|
|
|
|
|
2017-06-12 21:11:20 +02:00
|
|
|
// Elements
|
2017-06-12 20:06:31 +02:00
|
|
|
app.Get("/images/elements/:file", func(ctx *aero.Context) string {
|
|
|
|
return ctx.File("images/elements/" + ctx.Get("file"))
|
|
|
|
})
|
|
|
|
|
2017-06-05 20:21:06 +02:00
|
|
|
// For benchmarks
|
|
|
|
app.Get("/hello", func(ctx *aero.Context) string {
|
|
|
|
return ctx.Text("Hello World")
|
2017-06-04 01:17:00 +02:00
|
|
|
})
|
|
|
|
|
2017-06-15 19:56:09 +02:00
|
|
|
// Authentication
|
|
|
|
EnableLogin(app)
|
|
|
|
|
2016-11-29 01:06:00 +09:00
|
|
|
// Let's go
|
2016-11-09 20:32:19 +09:00
|
|
|
app.Run()
|
|
|
|
}
|