@Resource("/")
class Root : ResourceHandler, ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
- call.request.cookies[ErrorMessageCookieName]?.let { call.attributes.put(ErrorMessageAttributeKey, it) }
+ override suspend fun ApplicationCall.filterCall() {
+ request.cookies[ErrorMessageCookieName]?.let { attributes.put(ErrorMessageAttributeKey, it) }
}
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- filterCall()
+ call.filterCall()
call.respondHtml(HttpStatusCode.OK, call.loreIntroPage())
}
@Resource("assets/{path...}")
class AssetFile(val path: List<String>, val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondAsset(StoragePath.assetDir / path)
}
@Resource("lore/{path...}")
class LorePage(val path: List<String>, val format: LoreArticleFormat = LoreArticleFormat.HTML, val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.loreArticlePage(path, format))
}
@Resource("map")
class GalaxyMap(val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondStoredFile(call.galaxyMapPage())
}
@Resource("quote")
class RandomQuote(val format: QuoteFormat = QuoteFormat.HTML, val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
with(format) { call.respondQuote(randomQuote()) }
}
@Resource("robots.txt")
class RobotsTxt(val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondStoredFile(StoragePath.Root / "robots.txt")
}
@Resource("sitemap.xml")
class SitemapXml(val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
val sitemap = buildSitemap(call)
call.respondXml(contentType = ContentType.Application.Xml) {
@Resource("edits.rss")
class RecentEditsRss(val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondRss(generateRecentPageEdits(call))
}
@Resource("comments.rss")
class RecentCommentsRss(val limit: Int = 10, val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondRss(call.recentCommentsRssFeedGenerator(limit))
}
@Resource("preferences")
class ClientPreferences(val root: Root = Root()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(root) { filterCall() }
+ with(root) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.clientSettingsPage())
}
@Resource("auth")
class Auth(val root: Root = Root()) : ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(root) { filterCall() }
}
@Resource("login")
class LoginPage(val auth: Auth = Auth()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(auth) { filterCall() }
+ with(auth) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.loginPage())
}
@Resource("login")
class LoginPost(val auth: Auth = Auth()) : ResourceReceiver<LoginPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: LoginPayload) {
- with(auth) { filterCall() }
+ with(auth) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.loginRoute(payload.nation, payload.checksum, payload.tokenId)
@Resource("logout")
class LogoutPost(val auth: Auth = Auth()) : ResourceReceiver<LogoutPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: LogoutPayload) {
- with(auth) { filterCall() }
+ with(auth) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.logoutRoute()
}
@Resource("nuke")
- class Nuke(val root: Root = Root()) : ResourceHandler {
- override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
+ class Nuke(val root: Root = Root()) : ResourceFilter, ResourceHandler {
+ override suspend fun ApplicationCall.filterCall() {
with(root) { filterCall() }
-
+ }
+
+ override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
+ call.filterCall()
call.respondHtml(HttpStatusCode.OK, call.robotPage())
}
@Resource("ws")
class WS(val csrfToken: String? = null, val nuke: Nuke = Nuke()) : ResourceListener {
override suspend fun DefaultWebSocketServerSession.handleCall() {
+ with(nuke) { call.filterCall() }
+
robotConversation(csrfToken)
}
}
@Resource("comment")
class Comments(val root: Root = Root()) : ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(root) { filterCall() }
}
@Resource("help")
class HelpPage(val comments: Comments = Comments()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.commentHelpPage())
}
@Resource("recent")
class RecentPage(val limit: Int? = null, val comments: Comments = Comments()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.recentCommentsPage(limit))
}
@Resource("new/{path...}")
class NewPost(val path: List<String>, val comments: Comments = Comments()) : ResourceReceiver<NewCommentPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: NewCommentPayload) {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.newCommentRoute(path, payload.comment)
@Resource("view/{id}")
class ViewPage(val id: Id<Comment>, val comments: Comments = Comments()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
call.viewCommentRoute(id)
}
@Resource("edit/{id}")
class EditPost(val id: Id<Comment>, val comments: Comments = Comments()) : ResourceReceiver<EditCommentPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: EditCommentPayload) {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.editCommentRoute(id, payload.comment)
@Resource("delete/{id}")
class DeleteConfirmPage(val id: Id<Comment>, val comments: Comments = Comments()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.deleteCommentPage(id))
}
@Resource("delete/{id}")
class DeleteConfirmPost(val id: Id<Comment>, val comments: Comments = Comments()) : ResourceReceiver<DeleteCommentPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: DeleteCommentPayload) {
- with(comments) { filterCall() }
+ with(comments) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.deleteCommentRoute(id)
@Resource("user")
class User(val root: Root = Root()) : ResourceHandler, ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(root) { filterCall() }
}
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- filterCall()
+ call.filterCall()
call.currentUserPage()
}
@Resource("{id}")
class ById(val id: Id<NationData>, val user: User = User()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(user) { filterCall() }
+ with(user) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.userPage(id))
}
@Resource("admin")
class Admin(val root: Root = Root()) : ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(root) { filterCall() }
- call.ownerNationOnly()
+ ownerNationOnly()
}
@Resource("ban/{id}")
class Ban(val id: Id<NationData>, val admin: Admin = Admin()) : ResourceReceiver<AdminBanUserPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminBanUserPayload) {
- with(admin) { filterCall() }
+ with(admin) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.adminBanUserRoute(id)
@Resource("unban/{id}")
class Unban(val id: Id<NationData>, val admin: Admin = Admin()) : ResourceReceiver<AdminUnbanUserPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminUnbanUserPayload) {
- with(admin) { filterCall() }
+ with(admin) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.adminUnbanUserRoute(id)
@Resource("nuke")
class NukeManagement(val admin: Admin = Admin()) : ResourceFilter, ResourceHandler {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(admin) { filterCall() }
}
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- filterCall()
+ call.filterCall()
call.respondHtml(HttpStatusCode.OK, call.robotManagementPage())
}
@Resource("update")
class Update(val nukeManagement: NukeManagement = NukeManagement()) : ResourceReceiver<AdminNukeUpdatePayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminNukeUpdatePayload) {
- with(nukeManagement) { filterCall() }
+ with(nukeManagement) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
RobotService.getInstance()?.performMaintenance()
@Resource("reset")
class Reset(val nukeManagement: NukeManagement = NukeManagement()) : ResourceReceiver<AdminNukeResetPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminNukeResetPayload) {
- with(nukeManagement) { filterCall() }
+ with(nukeManagement) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
RobotService.getInstance()?.reset()
@Resource("vfs")
class Vfs(val admin: Admin = Admin()) : ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(admin) { filterCall() }
}
@Resource("inline/{path...}")
class Inline(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.response.header(HttpHeaders.ContentDisposition, "inline")
call.adminPreviewFile(StoragePath(path))
@Resource("download/{path...}")
class Download(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.response.header(HttpHeaders.ContentDisposition, "attachment; filename=\"${path.last()}\"")
call.adminPreviewFile(StoragePath(path))
@Resource("view/{path...}")
class View(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.adminViewVfs(StoragePath(path)))
}
@Resource("webdav-token")
class WebDavTokenPage(val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.adminRequestWebDavToken())
}
@Resource("webdav-token")
class WebDavTokenPost(val vfs: Vfs = Vfs()) : ResourceReceiver<AdminVfsRequestWebDavTokenPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminVfsRequestWebDavTokenPayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.respondHtml(HttpStatusCode.Created, call.adminObtainWebDavToken())
@Resource("copy/{path...}")
class CopyPage(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.respondHtml(HttpStatusCode.OK, call.adminShowCopyFile(StoragePath(path)))
}
@Resource("copy/{path...}")
class CopyPost(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceReceiver<AdminVfsCopyFilePayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminVfsCopyFilePayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.adminDoCopyFile(StoragePath(payload.from), StoragePath(path))
@Resource("upload/{path...}")
class Upload(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceReceiver<CsrfProtectedMultiPartPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: CsrfProtectedMultiPartPayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
val fileItem = payload.payload.filterIsInstance<PartData.FileItem>().singleOrNull()
@Resource("overwrite/{path...}")
class Overwrite(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceReceiver<CsrfProtectedMultiPartPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: CsrfProtectedMultiPartPayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
val fileItem = payload.payload.filterIsInstance<PartData.FileItem>().singleOrNull()
@Resource("delete/{path...}")
class DeleteConfirmPage(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.adminConfirmDeleteFile(StoragePath(path))
}
@Resource("delete/{path...}")
class DeleteConfirmPost(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceReceiver<AdminVfsDeleteFilePayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminVfsDeleteFilePayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.adminDeleteFile(StoragePath(path))
@Resource("mkdir/{path...}")
class MkDir(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceReceiver<AdminVfsMkDirPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminVfsMkDirPayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.adminMakeDirectory(StoragePath(path), payload.directory)
@Resource("rmdir/{path...}")
class RmDirConfirmPage(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceHandler {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall() {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
call.adminConfirmRemoveDirectory(StoragePath(path))
}
@Resource("rmdir/{path...}")
class RmDirConfirmPost(val path: List<String>, val vfs: Vfs = Vfs()) : ResourceReceiver<AdminVfsRmDirPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: AdminVfsRmDirPayload) {
- with(vfs) { filterCall() }
+ with(vfs) { call.filterCall() }
with(payload) { call.verifyCsrfToken() }
call.adminRemoveDirectory(StoragePath(path))
@Resource("utils")
class Utils(val root: Root = Root()) : ResourceFilter {
- override suspend fun PipelineContext<Unit, ApplicationCall>.filterCall() {
+ override suspend fun ApplicationCall.filterCall() {
with(root) { filterCall() }
delay(250L)
@Resource("mechyrdia-sans")
class MechyrdiaSans(val utils: Utils = Utils()) : ResourceReceiver<MechyrdiaSansPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: MechyrdiaSansPayload) {
- with(utils) { filterCall() }
+ with(utils) { call.filterCall() }
val svgDoc = MechyrdiaSansFont.renderTextToSvg(payload.lines.joinToString(separator = "\n") { it.trim() }, payload.bold, payload.italic, payload.align)
call.respondXml(contentType = ContentType.Image.SVG) {
@Resource("tylan-lang")
class TylanLanguage(val utils: Utils = Utils()) : ResourceReceiver<TylanLanguagePayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: TylanLanguagePayload) {
- with(utils) { filterCall() }
+ with(utils) { call.filterCall() }
call.respondText(TylanAlphabetFont.tylanToFontAlphabet(payload.lines.joinToString(separator = "\n")))
}
@Resource("pokhwal-lang")
class PokhwalishLanguage(val utils: Utils = Utils()) : ResourceReceiver<PokhwalishLanguagePayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: PokhwalishLanguagePayload) {
- with(utils) { filterCall() }
+ with(utils) { call.filterCall() }
call.respondText(PokhwalishAlphabetFont.pokhwalToFontAlphabet(payload.lines.joinToString(separator = "\n")))
}
@Resource("preview-comment")
class PreviewComment(val utils: Utils = Utils()) : ResourceReceiver<PreviewCommentPayload> {
override suspend fun PipelineContext<Unit, ApplicationCall>.handleCall(payload: PreviewCommentPayload) {
- with(utils) { filterCall() }
+ with(utils) { call.filterCall() }
call.respondText(
text = payload.lines.joinToString(separator = "\n").parseAs(ParserTree::toCommentHtml).toFragmentString(),