2016-11-09 20:32:19 +09:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-09 22:11:49 +09:00
|
|
|
"github.com/aerogo/aero"
|
2017-10-28 03:53:12 +02:00
|
|
|
"github.com/aerogo/session-store-nano"
|
2017-06-08 23:26:58 +02:00
|
|
|
"github.com/animenotifier/arn"
|
2017-06-17 01:32:47 +02:00
|
|
|
"github.com/animenotifier/notify.moe/auth"
|
2017-06-25 13:13:47 +02:00
|
|
|
"github.com/animenotifier/notify.moe/components/css"
|
2017-06-15 23:03:55 +02:00
|
|
|
"github.com/animenotifier/notify.moe/layout"
|
2017-06-17 01:12:28 +02:00
|
|
|
"github.com/animenotifier/notify.moe/middleware"
|
2017-06-18 17:16:40 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/admin"
|
2017-07-22 15:04:54 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/amvs"
|
2016-11-19 23:54:31 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/anime"
|
2017-06-19 22:16:01 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/animelist"
|
2017-06-19 20:59:02 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/animelistitem"
|
2017-07-01 14:03:10 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/apiview"
|
2017-07-22 15:04:54 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/artworks"
|
2017-07-01 02:14:14 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/best"
|
2017-07-13 08:23:20 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/character"
|
2017-10-04 08:12:12 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/charge"
|
2017-10-21 19:16:11 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/compare"
|
2017-10-02 06:29:58 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/dashboard"
|
2017-10-19 21:43:42 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/database"
|
2017-06-28 17:55:08 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/editanime"
|
2017-10-06 22:07:12 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/editor"
|
2017-06-24 21:07:45 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/embed"
|
2017-07-01 01:16:25 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/explore"
|
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"
|
2017-10-17 23:17:04 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/group"
|
|
|
|
"github.com/animenotifier/notify.moe/pages/groups"
|
2017-07-22 15:04:54 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/home"
|
2017-10-04 08:12:12 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/inventory"
|
2017-07-03 19:33:52 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/listimport"
|
|
|
|
"github.com/animenotifier/notify.moe/pages/listimport/listimportanilist"
|
2017-07-12 08:24:26 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/listimport/listimportkitsu"
|
2017-07-08 01:18:21 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/listimport/listimportmyanimelist"
|
2017-06-21 03:05:34 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/login"
|
2017-07-19 03:22:50 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/me"
|
2017-06-27 04:15:52 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/newthread"
|
2017-07-14 23:50:34 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/notifications"
|
2017-07-16 07:50:57 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/paypal"
|
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"
|
2017-06-18 17:16:40 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/settings"
|
2017-10-03 15:26:29 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/shop"
|
2017-10-02 06:29:58 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/soundtrack"
|
|
|
|
"github.com/animenotifier/notify.moe/pages/soundtracks"
|
2017-07-07 02:07:34 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/statistics"
|
2016-11-19 23:54:31 +09:00
|
|
|
"github.com/animenotifier/notify.moe/pages/threads"
|
2017-06-20 14:16:23 +02:00
|
|
|
"github.com/animenotifier/notify.moe/pages/user"
|
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() {
|
2017-06-22 16:08:34 +02:00
|
|
|
// Configure and start
|
|
|
|
configure(app).Run()
|
|
|
|
}
|
|
|
|
|
|
|
|
func configure(app *aero.Application) *aero.Application {
|
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
|
2017-06-25 13:13:47 +02:00
|
|
|
app.SetStyle(css.Bundle())
|
2017-06-11 11:13:59 +02:00
|
|
|
|
2017-06-17 22:19:26 +02:00
|
|
|
// Sessions
|
2017-07-14 04:58:21 +02:00
|
|
|
app.Sessions.Duration = 3600 * 24 * 30 * 6
|
2017-10-27 09:11:56 +02:00
|
|
|
|
|
|
|
// TODO: ...
|
|
|
|
// app.Sessions.Store = aerospikestore.New(arn.DB, "Session", app.Sessions.Duration)
|
2017-10-31 12:12:21 +01:00
|
|
|
app.Sessions.Store = nanostore.New(arn.DB.Collection("Session"))
|
2017-06-08 23:26:58 +02:00
|
|
|
|
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
|
|
|
|
2016-11-29 01:06:00 +09:00
|
|
|
// Ajax routes
|
2017-07-22 15:04:54 +02:00
|
|
|
app.Ajax("/", home.Get)
|
2017-10-02 06:29:58 +02:00
|
|
|
app.Ajax("/dashboard", dashboard.Get)
|
2016-11-19 23:54:31 +09:00
|
|
|
app.Ajax("/anime/:id", anime.Get)
|
2017-10-20 16:52:07 +02:00
|
|
|
app.Ajax("/anime/:id/episodes", anime.Episodes)
|
|
|
|
app.Ajax("/anime/:id/characters", anime.Characters)
|
|
|
|
app.Ajax("/anime/:id/tracks", anime.Tracks)
|
2017-06-28 17:55:08 +02:00
|
|
|
app.Ajax("/anime/:id/edit", editanime.Get)
|
2017-07-01 14:03:10 +02:00
|
|
|
app.Ajax("/api", apiview.Get)
|
2017-07-01 02:14:14 +02:00
|
|
|
app.Ajax("/best/anime", best.Get)
|
|
|
|
app.Ajax("/explore", explore.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)
|
2017-07-10 16:58:34 +02:00
|
|
|
app.Ajax("/thread/:id", threads.Get)
|
|
|
|
app.Ajax("/post/:id", posts.Get)
|
2017-07-13 08:23:20 +02:00
|
|
|
app.Ajax("/character/:id", character.Get)
|
2017-07-08 21:11:03 +02:00
|
|
|
app.Ajax("/new/thread", newthread.Get)
|
|
|
|
app.Ajax("/settings", settings.Get)
|
2017-07-22 15:04:54 +02:00
|
|
|
app.Ajax("/artworks", artworks.Get)
|
|
|
|
app.Ajax("/amvs", amvs.Get)
|
2017-07-19 13:08:12 +02:00
|
|
|
app.Ajax("/users", users.Active)
|
|
|
|
app.Ajax("/users/osu", users.Osu)
|
|
|
|
app.Ajax("/users/staff", users.Staff)
|
2017-10-02 14:56:51 +02:00
|
|
|
app.Ajax("/statistics", statistics.Get)
|
|
|
|
app.Ajax("/statistics/anime", statistics.Anime)
|
2017-07-08 21:11:03 +02:00
|
|
|
app.Ajax("/login", login.Get)
|
|
|
|
|
2017-10-09 15:47:40 +02:00
|
|
|
// Soundtracks
|
|
|
|
app.Ajax("/soundtracks", soundtracks.Get)
|
2017-10-16 11:53:47 +02:00
|
|
|
app.Ajax("/soundtracks/from/:index", soundtracks.From)
|
2017-10-09 15:47:40 +02:00
|
|
|
app.Ajax("/soundtrack/:id", soundtrack.Get)
|
|
|
|
app.Ajax("/soundtrack/:id/edit", soundtrack.Edit)
|
|
|
|
|
2017-10-17 23:17:04 +02:00
|
|
|
// Groups
|
|
|
|
app.Ajax("/groups", groups.Get)
|
|
|
|
app.Ajax("/group/:id", group.Get)
|
|
|
|
app.Ajax("/group/:id/edit", group.Edit)
|
2017-10-18 23:17:54 +02:00
|
|
|
app.Ajax("/group/:id/forum", group.Forum)
|
2017-10-17 23:17:04 +02:00
|
|
|
|
2017-07-08 21:11:03 +02:00
|
|
|
// User profiles
|
2017-06-20 14:16:23 +02:00
|
|
|
app.Ajax("/user", user.Get)
|
2016-11-20 19:26:11 +09:00
|
|
|
app.Ajax("/user/:nick", profile.Get)
|
2017-06-17 01:25:02 +02:00
|
|
|
app.Ajax("/user/:nick/threads", profile.GetThreadsByUser)
|
2017-06-22 11:21:26 -03:00
|
|
|
app.Ajax("/user/:nick/posts", profile.GetPostsByUser)
|
2017-07-16 07:50:57 +02:00
|
|
|
app.Ajax("/user/:nick/soundtracks", profile.GetSoundTracksByUser)
|
2017-07-13 02:32:36 +02:00
|
|
|
app.Ajax("/user/:nick/stats", profile.GetStatsByUser)
|
2017-07-21 11:01:34 +02:00
|
|
|
app.Ajax("/user/:nick/followers", profile.GetFollowers)
|
2017-06-19 22:16:01 +02:00
|
|
|
app.Ajax("/user/:nick/animelist", animelist.Get)
|
2017-07-05 16:52:24 +02:00
|
|
|
app.Ajax("/user/:nick/animelist/watching", animelist.FilterByStatus(arn.AnimeListStatusWatching))
|
|
|
|
app.Ajax("/user/:nick/animelist/completed", animelist.FilterByStatus(arn.AnimeListStatusCompleted))
|
|
|
|
app.Ajax("/user/:nick/animelist/planned", animelist.FilterByStatus(arn.AnimeListStatusPlanned))
|
|
|
|
app.Ajax("/user/:nick/animelist/hold", animelist.FilterByStatus(arn.AnimeListStatusHold))
|
|
|
|
app.Ajax("/user/:nick/animelist/dropped", animelist.FilterByStatus(arn.AnimeListStatusDropped))
|
|
|
|
app.Ajax("/user/:nick/animelist/anime/:id", animelistitem.Get)
|
2017-07-08 21:11:03 +02:00
|
|
|
|
2017-09-22 17:23:22 +02:00
|
|
|
// Anime list
|
|
|
|
app.Ajax("/animelist/watching", home.FilterByStatus(arn.AnimeListStatusWatching))
|
|
|
|
app.Ajax("/animelist/completed", home.FilterByStatus(arn.AnimeListStatusCompleted))
|
|
|
|
app.Ajax("/animelist/planned", home.FilterByStatus(arn.AnimeListStatusPlanned))
|
|
|
|
app.Ajax("/animelist/hold", home.FilterByStatus(arn.AnimeListStatusHold))
|
|
|
|
app.Ajax("/animelist/dropped", home.FilterByStatus(arn.AnimeListStatusDropped))
|
|
|
|
|
2017-10-21 19:16:11 +02:00
|
|
|
// Compare
|
|
|
|
app.Ajax("/compare/animelist/:nick-1/:nick-2", compare.AnimeList)
|
|
|
|
|
2017-07-08 21:11:03 +02:00
|
|
|
// Search
|
|
|
|
app.Ajax("/search", search.Get)
|
|
|
|
app.Ajax("/search/:term", search.Get)
|
|
|
|
|
2017-10-04 08:12:12 +02:00
|
|
|
// Shop
|
|
|
|
app.Ajax("/shop", shop.Get)
|
|
|
|
app.Ajax("/inventory", inventory.Get)
|
|
|
|
app.Ajax("/charge", charge.Get)
|
2017-10-06 12:44:55 +02:00
|
|
|
app.Ajax("/shop/history", shop.PurchaseHistory)
|
2017-10-05 13:48:16 +02:00
|
|
|
app.Post("/api/shop/buy/:item/:quantity", shop.BuyItem)
|
2017-10-04 08:12:12 +02:00
|
|
|
|
2017-07-08 21:11:03 +02:00
|
|
|
// Admin
|
|
|
|
app.Ajax("/admin", admin.Get)
|
2017-10-02 14:56:51 +02:00
|
|
|
app.Ajax("/admin/webdev", admin.WebDev)
|
2017-10-07 23:24:09 +02:00
|
|
|
app.Ajax("/admin/purchases", admin.PurchaseHistory)
|
2017-07-08 21:11:03 +02:00
|
|
|
|
2017-10-06 22:07:12 +02:00
|
|
|
// Editor
|
|
|
|
app.Ajax("/editor", editor.Get)
|
|
|
|
app.Ajax("/editor/anilist", editor.AniList)
|
|
|
|
app.Ajax("/editor/shoboi", editor.Shoboi)
|
|
|
|
|
2017-10-19 21:43:42 +02:00
|
|
|
// Mixed
|
|
|
|
app.Ajax("/database", database.Get)
|
|
|
|
app.Get("/api/select/:data-type/where/:field/is/:field-value", database.Select)
|
|
|
|
|
2017-07-08 21:11:03 +02:00
|
|
|
// Import
|
2017-07-03 19:33:52 +02:00
|
|
|
app.Ajax("/import", listimport.Get)
|
2017-07-05 00:40:03 +02:00
|
|
|
app.Ajax("/import/anilist/animelist", listimportanilist.Preview)
|
|
|
|
app.Ajax("/import/anilist/animelist/finish", listimportanilist.Finish)
|
2017-07-08 01:18:21 +02:00
|
|
|
app.Ajax("/import/myanimelist/animelist", listimportmyanimelist.Preview)
|
|
|
|
app.Ajax("/import/myanimelist/animelist/finish", listimportmyanimelist.Finish)
|
2017-07-12 08:24:26 +02:00
|
|
|
app.Ajax("/import/kitsu/animelist", listimportkitsu.Preview)
|
|
|
|
app.Ajax("/import/kitsu/animelist/finish", listimportkitsu.Finish)
|
2017-07-08 21:11:03 +02:00
|
|
|
|
|
|
|
// Genres
|
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-07-08 21:11:03 +02:00
|
|
|
// Browser extension
|
|
|
|
app.Ajax("/extension/embed", embed.Get)
|
|
|
|
|
2017-07-14 23:50:34 +02:00
|
|
|
// API
|
2017-07-19 03:22:50 +02:00
|
|
|
app.Get("/api/me", me.Get)
|
2017-07-14 23:50:34 +02:00
|
|
|
app.Get("/api/test/notification", notifications.Test)
|
2017-07-16 20:29:10 +02:00
|
|
|
|
|
|
|
// PayPal
|
|
|
|
app.Ajax("/paypal/success", paypal.Success)
|
|
|
|
app.Ajax("/paypal/cancel", paypal.Cancel)
|
2017-10-05 12:36:26 +02:00
|
|
|
app.Post("/api/paypal/payment/create", paypal.CreatePayment)
|
2017-07-14 23:50:34 +02:00
|
|
|
|
2017-10-02 02:09:05 +02:00
|
|
|
// Assets
|
|
|
|
configureAssets(app)
|
|
|
|
|
2017-10-02 00:31:44 +02:00
|
|
|
// Rewrite
|
2017-10-02 02:09:05 +02:00
|
|
|
app.Rewrite(rewrite)
|
2017-10-02 00:31:44 +02:00
|
|
|
|
2017-06-17 01:12:28 +02:00
|
|
|
// Middleware
|
2017-10-14 17:18:32 +02:00
|
|
|
app.Use(
|
|
|
|
middleware.Firewall(),
|
|
|
|
middleware.Log(),
|
|
|
|
middleware.Session(),
|
2017-10-15 20:19:45 +02:00
|
|
|
middleware.UserInfo(),
|
2017-10-14 17:18:32 +02:00
|
|
|
)
|
2017-06-12 21:11:20 +02:00
|
|
|
|
2017-06-17 01:12:28 +02:00
|
|
|
// API
|
2017-10-05 07:22:14 +02:00
|
|
|
arn.API.Install(app)
|
2017-06-12 21:11:20 +02:00
|
|
|
|
2017-06-17 01:12:28 +02:00
|
|
|
// Domain
|
2017-06-23 19:22:39 +02:00
|
|
|
if arn.IsDevelopment() {
|
2017-06-17 01:12:28 +02:00
|
|
|
app.Config.Domain = "beta.notify.moe"
|
|
|
|
}
|
2017-06-04 01:17:00 +02:00
|
|
|
|
2017-06-15 19:56:09 +02:00
|
|
|
// Authentication
|
2017-06-17 01:32:47 +02:00
|
|
|
auth.Install(app)
|
2017-06-15 19:56:09 +02:00
|
|
|
|
2017-11-02 04:08:45 +01:00
|
|
|
// Close the database node on shutdown
|
|
|
|
app.OnShutdown(arn.Node.Close)
|
|
|
|
|
|
|
|
// Prefetch data from all collections
|
|
|
|
arn.DB.PrefetchData()
|
|
|
|
|
2017-10-02 00:31:44 +02:00
|
|
|
// Specify test routes
|
|
|
|
for route, examples := range routeTests {
|
|
|
|
app.Test(route, examples)
|
|
|
|
}
|
|
|
|
|
2017-06-22 16:08:34 +02:00
|
|
|
return app
|
2016-11-09 20:32:19 +09:00
|
|
|
}
|