Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
624f7046af | ||
|
|
8b3d642104 | ||
|
|
46369f84bd | ||
|
|
68f3effa8d | ||
|
|
4657ae2aec | ||
|
|
f134d57b79 | ||
|
|
9b4da98ac4 | ||
|
|
599ca83f0f | ||
|
|
b952007f3b | ||
|
|
c0e74f4756 | ||
|
|
68a8e7ef97 | ||
|
|
5b81f7ff0d | ||
|
|
78a14ae86b | ||
|
|
c28f17abdd | ||
|
|
de3bae3353 | ||
|
|
fcf2361fbf | ||
|
|
7c1623493a | ||
|
|
013c50d4f4 | ||
|
|
f236d35974 | ||
|
|
55379fcfe3 | ||
|
|
c4636cf843 | ||
|
|
8fd9b19bd0 | ||
|
|
5a5dfea774 | ||
|
|
c157f5f592 |
@@ -0,0 +1,4 @@
|
||||
.git
|
||||
**/*.marko.js
|
||||
.cache
|
||||
.static
|
||||
@@ -11,6 +11,7 @@ prebuild.run({
|
||||
"./marko/page/logs/list.marko",
|
||||
"./marko/page/data/channels.marko",
|
||||
"./marko/page/data/characters.marko",
|
||||
"./marko/page/data/changes.marko",
|
||||
"./marko/page/story-content/view.marko",
|
||||
"./marko/page/logs-content/view.marko",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
const {charactersApi} = require("../../../rpdata/api/Character")
|
||||
|
||||
module.exports = class {
|
||||
onCreate() {
|
||||
this.state = {
|
||||
nicks: [],
|
||||
}
|
||||
}
|
||||
|
||||
onMount() {
|
||||
charactersApi.unknownNicks(100).then(unknowns => {
|
||||
this.state.nicks = unknowns.map(u => u.nick)
|
||||
}).catch(err => {
|
||||
console.warn("Failed to get unknown nicks:", err)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<div class="unknown-nick-list">
|
||||
<div for(nick in state.nicks) on-click("emit", "select", nick) key=nick class="nick">${nick}</div>
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
div.unknown-nick-list {
|
||||
padding: 0.5em 0;
|
||||
|
||||
div.nick {
|
||||
display: inline-block;
|
||||
padding: 0.25em 0.5ch;
|
||||
margin: 2px;
|
||||
background-color: #111;
|
||||
color: #881;
|
||||
}
|
||||
div.nick:hover {
|
||||
cursor: pointer;
|
||||
background-color: #222;
|
||||
color: #CC2;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<include("../layout", {title: "Data", site: "data"})>
|
||||
<@body>
|
||||
<background src="/assets/images/bg.png" opacity=0.25 />
|
||||
<changes-page user=input.user changes=input.changes selected=input.selected />
|
||||
</@body>
|
||||
</include>
|
||||
@@ -17,8 +17,6 @@
|
||||
onDesc="Log new posts in this channel."
|
||||
offDesc="The logbot will not monitor this channel."
|
||||
on-change("change", "logged") />
|
||||
|
||||
<p class="color-danger" if(state.values.logged)>The logbot is not yet available, so this does nothing right now.</p>
|
||||
|
||||
|
||||
<button disabled=state.loading on-click("save")>Save</button>
|
||||
</modal>
|
||||
@@ -33,6 +33,14 @@ module.exports = class {
|
||||
this.emit("close")
|
||||
}
|
||||
|
||||
selectUnknown(nick) {
|
||||
this.state.values = Object.assign({}, this.state.values, {
|
||||
nick: nick,
|
||||
name: nick.replace(/_/g, " ").replace(/`/g, "'"),
|
||||
shortName: (!nick.includes("_") && nick.includes("`")) ? nick.split("`")[0] : "",
|
||||
})
|
||||
}
|
||||
|
||||
save() {
|
||||
if (this.state.loading) {
|
||||
return
|
||||
|
||||
@@ -21,4 +21,12 @@
|
||||
<textarea key="description" placeholder="Description" on-change("change", "description") value=state.values.description />
|
||||
|
||||
<button disabled=state.loading on-click("save")>Save</button>
|
||||
|
||||
<h2>Unknown Nicks</h2>
|
||||
<p>After you're done adding the one you're here for, why not take a look at the unknown nicks discovered in the last log character updates?</p>
|
||||
<p>Clicking one will change the nick in the form above, and add a guess for what the full name is.</p>
|
||||
<if-permitted not user=input.user permission="character.add">
|
||||
<p class="color-danger">You don't have permission to set a different author on characters, so only add your own.</p>
|
||||
</if-permitted>
|
||||
<unknown-nick-list on-select("selectUnknown") />
|
||||
</modal>
|
||||
@@ -0,0 +1,119 @@
|
||||
const moment = require("moment")
|
||||
|
||||
module.exports = class {
|
||||
onCreate() {
|
||||
this.state = {
|
||||
operation: "",
|
||||
links: [],
|
||||
parentLink: null,
|
||||
}
|
||||
}
|
||||
|
||||
onInput(input) {
|
||||
if (input.data) {
|
||||
this.refresh(input.data)
|
||||
}
|
||||
}
|
||||
|
||||
refresh(data) {
|
||||
this.state.links = []
|
||||
this.state.operation = opText[data.op]
|
||||
this.state.parentLink = null
|
||||
|
||||
switch (data.model) {
|
||||
case "Channel": {
|
||||
const key = data.keys.find(k => k.id !== "*")
|
||||
|
||||
this.state.operation += " channel"
|
||||
this.state.links = [{
|
||||
text: key.id,
|
||||
href: `/data/channels/`,
|
||||
}]
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Character": {
|
||||
const character = data.objects.find(o => o.type === "Character")
|
||||
|
||||
this.state.operation += " character"
|
||||
this.state.links = [{
|
||||
text: `${character.name} (${character.id})`,
|
||||
href: `/data/characters/`,
|
||||
}]
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Story": {
|
||||
const key = data.keys.find(k => k.model === "Story" && k.id !== "*")
|
||||
const story = data.objects.find(o => o.type === "Story")
|
||||
|
||||
this.state.operation += " story"
|
||||
this.state.links = [{
|
||||
text: story.name,
|
||||
href: `/story/${key.id}`,
|
||||
}]
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Chapter": {
|
||||
const storyKey = data.keys.find(k => k.model === "Story")
|
||||
const chapterKey = data.keys.find(k => k.model === "Chapter")
|
||||
const chapter = data.objects.find(o => o.type === "Chapter")
|
||||
|
||||
this.state.operation += " chapter"
|
||||
this.state.links = [{
|
||||
text: chapter.title || `Untitled chapter (${chapterKey.id})`,
|
||||
href: `/story/${storyKey.id}#${chapterKey.id}`,
|
||||
}]
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Log": {
|
||||
const key = data.keys.find(k => k.id !== "*")
|
||||
|
||||
this.state.operation += " log"
|
||||
this.state.links = [{
|
||||
text: key.id,
|
||||
href: `/logs/${key.id}`,
|
||||
}]
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Post": {
|
||||
const logKey = data.keys.find(k => k.model === "Log")
|
||||
const postKeys = data.keys.filter(k => k.model === "Post")
|
||||
const postObjs = data.objects.filter(o => o.type === "Post")
|
||||
|
||||
this.state.operation += (postKeys.length > 1) ? " posts" : " post"
|
||||
this.state.links = postObjs.map(po => ({
|
||||
text: `[${moment(po.time).format("HH:mm")}] ${po.nick}`,
|
||||
href: `/logs/${logKey.id}#${po.id}`,
|
||||
}))
|
||||
this.state.parentLink = {
|
||||
prefix: "in log",
|
||||
text: `${logKey.id}`,
|
||||
href: `/logs/${logKey.id}`,
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const opText = {
|
||||
add: "added",
|
||||
remove: "removed",
|
||||
move: "moved",
|
||||
edit: "edited",
|
||||
import: "imported",
|
||||
tag: "tagged",
|
||||
untag: "untagged",
|
||||
"move-in": "moved in",
|
||||
"move-out": "moved out",
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import moment from "moment";
|
||||
|
||||
<div class="change">
|
||||
<span class="change-id color-menu">[${moment(input.data.date).format("MMM D HH:mm:ss")}] * </span>
|
||||
<span class="author color-text">${input.data.author} </span>
|
||||
<span class="text color-text">${state.operation} </span>
|
||||
<span for(link in state.links | status-var=loop) key=link.href class="link">
|
||||
<a class="color-primary" href=link.href>${link.text}</a>
|
||||
<span if(loop.getIndex() < state.links.length - 1) class="comma">, </span>
|
||||
</span>
|
||||
<if (state.parentLink != null)>
|
||||
<span class="text"> ${state.parentLink.prefix} </span>
|
||||
<a class="color-primary" href=state.parentLink.href>${state.parentLink.text}</a>
|
||||
</if>
|
||||
</div>
|
||||
@@ -0,0 +1,8 @@
|
||||
div.change {
|
||||
text-indent: -2ch;
|
||||
margin-left: 2ch;
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
characters: input.characters,
|
||||
modal: null,
|
||||
}
|
||||
}
|
||||
|
||||
open(modal) {
|
||||
this.state.modal = modal
|
||||
}
|
||||
|
||||
close() {
|
||||
this.state.modal = null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<data-menu categories=input.categories selected=(input.selected || {}) user=input.user on-open("open") />
|
||||
<main>
|
||||
<div class="changes-page">
|
||||
<h1 class="color-primary">Changes</h1>
|
||||
<p>All changes to <em>listed</em> resources is stored for 90 days for transparency reasons. The current state of an object after each change exists, but is only available through the GraphQL API at this time.</p>
|
||||
<for (change in input.changes)>
|
||||
<change data=change />
|
||||
</for>
|
||||
</div>
|
||||
</main>
|
||||
<add-character-modal enabled=(state.modal === "character.add") user=input.user on-added("characterAdded") on-close("close") />
|
||||
<add-channel-modal enabled=(state.modal === "channel.add") user=input.user on-close("close") />
|
||||
@@ -0,0 +1,36 @@
|
||||
.changes-page {
|
||||
width: 90%;
|
||||
max-width: 95ch;
|
||||
margin: auto;
|
||||
|
||||
> p {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-weight: 200;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
margin-bottom: 1em;
|
||||
|
||||
h1 {
|
||||
display: block;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
a {
|
||||
vertical-align: middle;
|
||||
display: inline-block;
|
||||
padding: 0.5em 0.5ch 0.5em 0.5ch;
|
||||
opacity: 0.5;
|
||||
}
|
||||
a:hover {
|
||||
cursor: pointer;
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,24 @@ module.exports = class {
|
||||
}).catch(errs => {
|
||||
console.warn("Failed to add nick:", errs)
|
||||
|
||||
this.state.error = "Failed to add nick: " + errs[0].message
|
||||
this.state.error = errs[0].message
|
||||
}).then(() => {
|
||||
this.state.loading = false
|
||||
})
|
||||
}
|
||||
|
||||
selectUnknown(nick) {
|
||||
if (this.state.loading) {
|
||||
return
|
||||
}
|
||||
|
||||
const input = {id: this.input.character.id, nick}
|
||||
|
||||
this.state.loading = true
|
||||
charactersApi.addNick(input).then((res) => {
|
||||
this.emit("nicks", res.nicks)
|
||||
}).catch(errs => {
|
||||
this.state.error = errs[0].message
|
||||
}).then(() => {
|
||||
this.state.loading = false
|
||||
})
|
||||
|
||||
@@ -10,9 +10,12 @@
|
||||
</div>
|
||||
|
||||
<label>Current Nicks</label>
|
||||
<div for(nick in input.character.nicks) class="existing-nick-row" >
|
||||
<div for(nick in input.character.nicks) class="existing-nick-row" key=nick >
|
||||
<div class="content color-text">${nick}</div>
|
||||
<button disabled=state.loading on-click("removeNick", nick)>Remove</button>
|
||||
</div>
|
||||
|
||||
<h2>Unknown Nicks</h2>
|
||||
<p>These are the 100 most common nicks in the logs, maybe one of these belongs to <strong>${input.character.name}</strong>?</p>
|
||||
<unknown-nick-list key="un-list" on-select("selectUnknown") />
|
||||
</modal>
|
||||
@@ -2,6 +2,7 @@
|
||||
<menu-header>List</menu-header>
|
||||
<menu-link key="characters" selected=input.selected.characters icon="C" href="/data/characters/">Characters</menu-link>
|
||||
<menu-link key="channels" selected=input.selected.channels icon="#" href="/data/channels/">Channels</menu-link>
|
||||
<menu-link key="history" selected=input.selected.changes icon="H" href="/data/changes/">History</menu-link>
|
||||
<if-permitted user=input.user permission=["member", "character.add", "channel.add"]>
|
||||
<menu-gap />
|
||||
<menu-header>Add</menu-header>
|
||||
|
||||
@@ -15,7 +15,5 @@
|
||||
offDesc="The logbot will not monitor this channel."
|
||||
on-change("change", "logged") />
|
||||
|
||||
<p class="color-danger" if(state.values.logged)>The logbot is not yet available, so this does nothing right now.</p>
|
||||
|
||||
<button disabled=state.loading on-click("save")>Save</button>
|
||||
</modal>
|
||||
@@ -19,15 +19,11 @@ module.exports = class {
|
||||
}
|
||||
|
||||
onInput(input) {
|
||||
if (input.log && !this.first) {
|
||||
this.state.values = {
|
||||
title: input.log.title,
|
||||
event: input.log.eventName,
|
||||
description: input.log.description,
|
||||
open: input.log.open,
|
||||
}
|
||||
|
||||
this.first = true
|
||||
this.state.values = {
|
||||
title: input.log.title,
|
||||
event: input.log.eventName,
|
||||
description: input.log.description,
|
||||
open: input.log.open,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
const moment = require("moment")
|
||||
|
||||
const {postApi} = require("../../../../../rpdata/api/Post")
|
||||
const {logsApi} = require("../../../../../rpdata/api/Log")
|
||||
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
@@ -9,6 +10,22 @@ module.exports = class {
|
||||
modal: null,
|
||||
removed: false,
|
||||
}
|
||||
}
|
||||
|
||||
onMount() {
|
||||
this.sub = logsApi.subscribeChanges(this.state.log.id)
|
||||
|
||||
this.sub.on("data", data => {
|
||||
this.handleChange(data.changes)
|
||||
})
|
||||
|
||||
this.sub.connect()
|
||||
}
|
||||
|
||||
onUnmount() {
|
||||
if (this.sub != null) {
|
||||
this.sub.disconnect()
|
||||
}
|
||||
}
|
||||
|
||||
open(modal) {
|
||||
@@ -30,8 +47,6 @@ module.exports = class {
|
||||
for (const patch of patches) {
|
||||
const index = posts.findIndex(p => p.id === patch.id)
|
||||
if (index == -1) {
|
||||
console.warn("Post not found for patch:", patch)
|
||||
// TODO: Force full refresh
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -42,8 +57,7 @@ module.exports = class {
|
||||
posts.sort((a, b) => a.position - b.position)
|
||||
for (let i = 1; i < posts.length; ++i) {
|
||||
if (posts[i].position !== posts[i - 1].position + 1) {
|
||||
console.warn("Discontinuity detected!")
|
||||
// TODO: Force full refresh
|
||||
console.warn("Discontinuity detected:", i, posts)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,15 +79,7 @@ module.exports = class {
|
||||
|
||||
removePost(post) {
|
||||
postApi.remove({id: post.id}).then(() => {
|
||||
this.state.log.posts = this.state.log.posts.filter(p => p.id !== post.id)
|
||||
|
||||
for (const p of this.state.log.posts) {
|
||||
if (p.position > post.position) {
|
||||
p.position--
|
||||
}
|
||||
}
|
||||
|
||||
this.state.log = Object.assign({}, this.state.log)
|
||||
this.postRemoved(post)
|
||||
}).catch(errs => {
|
||||
console.warn("Failed to delete:", errs)
|
||||
this.state.error = "Failed to delete: " + (errs.message || errs[0].message)
|
||||
@@ -88,11 +94,69 @@ module.exports = class {
|
||||
this.state.log = Object.assign(Object.assign({}, this.state.log), patch)
|
||||
}
|
||||
|
||||
postRemoved(post) {
|
||||
if (this.state.log.posts.find(p => p.id === post.id) == null) {
|
||||
return
|
||||
}
|
||||
|
||||
const posts = this.state.log.posts.filter(p => p.id !== post.id).map(p => {
|
||||
if (p.position > post.position) {
|
||||
return Object.assign({}, p, {position: p.position - 1})
|
||||
}
|
||||
|
||||
return p
|
||||
})
|
||||
|
||||
this.state.log = Object.assign({}, this.state.log, {posts: posts})
|
||||
}
|
||||
|
||||
postAdded(post) {
|
||||
this.state.log.posts = this.state.log.posts.concat([post])
|
||||
this.state.log = Object.assign({}, this.state.log)
|
||||
}
|
||||
|
||||
handleChange(change) {
|
||||
switch (`${change.model}.${change.op}`) {
|
||||
case "Post.add": {
|
||||
for (const post of change.objects.filter(o => o.type === "Post")) {
|
||||
this.postAdded(post)
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Post.move":
|
||||
case "Post.edit": {
|
||||
this.patch(change.objects.filter(o => o.type === "Post"))
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Post.remove": {
|
||||
for (const post of change.objects.filter(o => o.type === "Post")) {
|
||||
this.postRemoved(post)
|
||||
}
|
||||
}
|
||||
|
||||
case "Log.edit": {
|
||||
const patch = change.objects.find(o => o.type === "Log")
|
||||
if (patch == null) {
|
||||
break
|
||||
}
|
||||
|
||||
this.logEdited(patch)
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case "Log.remove": {
|
||||
this.logRemoved()
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
logRemoved() {
|
||||
this.state.removed = true
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<if(state.text != null && state.text != "")>
|
||||
<div class=["post-meta", input.kind, state.color, input.weak ? "weak" : null] title=state.tooltip>
|
||||
<div class=["post-meta", input.kind, state.color, input.weak ? "weak" : null, input.class] title=state.tooltip>
|
||||
<a if(state.href != null) href=state.href>${state.text}</a>
|
||||
<span else>${state.text}</span>
|
||||
</div>
|
||||
|
||||
@@ -17,4 +17,14 @@ div.post-meta {
|
||||
|
||||
div.post-meta.weak {
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
div.post-meta.nick.pk-text {
|
||||
color: #AAA;
|
||||
}
|
||||
div.post-meta.nick.pk-action {
|
||||
color: #A64;
|
||||
}
|
||||
div.post-meta.nick.pk-scene {
|
||||
color: #68A;
|
||||
}
|
||||
@@ -1,3 +1,7 @@
|
||||
const EventEmitter = require("events");
|
||||
|
||||
let linkSignal = null;
|
||||
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
@@ -8,8 +12,12 @@ module.exports = class {
|
||||
modal: null,
|
||||
removed: false,
|
||||
multipart: false,
|
||||
anchored: false,
|
||||
prevWasText: false,
|
||||
}
|
||||
|
||||
this.mounted = false;
|
||||
|
||||
this.updatePost(input)
|
||||
}
|
||||
|
||||
@@ -41,19 +49,56 @@ module.exports = class {
|
||||
|
||||
const timediff = Date.parse(input.post.time) - Date.parse(input.prev.time)
|
||||
this.state.multipart = (input.post.nick == input.prev.nick && input.prev.multipart !== false) && (Math.abs(timediff) < 60000);
|
||||
this.state.prevWasText = (input.prev.kind === "text");
|
||||
|
||||
this.updatePost(input)
|
||||
}
|
||||
|
||||
onMount() {
|
||||
this.linkSignalCallback = () => {
|
||||
this.state.anchored = false
|
||||
}
|
||||
if (linkSignal == null) {
|
||||
linkSignal = new EventEmitter()
|
||||
linkSignal.setMaxListeners(10000)
|
||||
}
|
||||
linkSignal.on("signal", this.linkSignalCallback)
|
||||
|
||||
this.state.anchored = window.location.hash.slice(1) === this.input.post.id;
|
||||
}
|
||||
|
||||
onUnmount() {
|
||||
linkSignal.removeListener("signal", this.linkSignalCallback)
|
||||
}
|
||||
|
||||
link() {
|
||||
linkSignal.emit("signal")
|
||||
this.state.anchored = true
|
||||
}
|
||||
|
||||
updatePost(input) {
|
||||
this.state.shortName = input.post.nick.split("_").shift()
|
||||
this.state.name = input.post.nick
|
||||
this.state.nameSuffix = ""
|
||||
|
||||
this.state.text = input.post.text.replace(/\x02/g, "**").replace(/\x1D/g, "_")
|
||||
this.state.text = input.post.text.replace(/\x02/g, "**").replace(/\x1D/g, "*").replace(/\`/g, "\\`").trim();
|
||||
|
||||
if (input.post.kind === "text" && !this.state.text.includes("\"")) {
|
||||
this.state.text = '"' + this.state.text + '"'
|
||||
if (this.state.text.startsWith("|")) {
|
||||
this.state.name = ""
|
||||
this.state.text = this.state.text.slice(1).trim();
|
||||
}
|
||||
|
||||
if (input.post.kind === "text" && !this.state.text.includes("\"") && !this.state.text.includes("\''") && !this.state.text.includes("|")) {
|
||||
const colonIndex = this.state.text.indexOf(": ");
|
||||
if (colonIndex != -1 && colonIndex < this.state.text.indexOf(" ")) {
|
||||
this.state.text = this.state.text.replace(": ", ": \"") + "\"";
|
||||
} else {
|
||||
this.state.text = '"' + this.state.text + '"'
|
||||
}
|
||||
}
|
||||
|
||||
if (this.state.text.charAt(0) == this.state.text.charAt(0).toUpperCase()) {
|
||||
this.state.name = ""
|
||||
}
|
||||
|
||||
if (!input.post.nick.startsWith("=")) {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<div if(!state.removed) class=["post", component.kindClass("post-type"), state.multipart ? "multipart" : null]>
|
||||
<div if(!state.removed) class=["post", component.kindClass("pk-"), state.multipart ? "multipart" : null, state.anchored ? "anchored" : null]>
|
||||
<a class="anchor" id=input.post.id />
|
||||
<div class="post-meta-row">
|
||||
<div class="options color-menu">
|
||||
<a on-click("link") href=("#" + input.post.id) class="color-menu">Link</a>
|
||||
<if-permitted user=input.user permission="post.move">
|
||||
<a on-click("move", -1, true)>Up</a>
|
||||
<a on-click("move", +1, true)>Down</a>
|
||||
@@ -13,7 +15,7 @@
|
||||
</if-permitted>
|
||||
</div>
|
||||
<post-meta kind="timestamp" value=input.post.time />
|
||||
<post-meta kind="nick" value=input.post.nick />
|
||||
<post-meta kind="nick" class=("pk-"+input.post.kind) value=input.post.nick />
|
||||
</div>
|
||||
<div if(input.post.kind.startsWith("annotation.")) class="post-body" >
|
||||
<annotation level=(input.post.kind.substring(11))>
|
||||
@@ -24,7 +26,7 @@
|
||||
<markdown class="post-content post-scene" source=state.text />
|
||||
</div>
|
||||
<div if(input.post.kind === "action") class="post-body color-text">
|
||||
$ const prefix = (!state.multipart ? state.shortName + state.nameSuffix + " " : "");
|
||||
$ const prefix = ((!state.multipart || state.prevWasText) ? state.shortName + state.nameSuffix + " " : "");
|
||||
<markdown class="post-content post-action" source=(prefix + state.text) />
|
||||
</div>
|
||||
<div if(input.post.kind === "text") class="post-body color-text">
|
||||
|
||||
@@ -1,11 +1,23 @@
|
||||
div.post {
|
||||
margin-top: 1em;
|
||||
margin-bottom: 1ch;
|
||||
margin-left: -12px;
|
||||
padding-left: 12px;
|
||||
padding-right: 0.5ch;
|
||||
|
||||
transition: background-color 0.333s linear;
|
||||
|
||||
div.post-meta-row {
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
a.anchor {
|
||||
display: block;
|
||||
position: relative;
|
||||
top: -4em;
|
||||
}
|
||||
|
||||
div.options {
|
||||
position: absolute;
|
||||
text-align: right;
|
||||
@@ -24,6 +36,10 @@ div.post {
|
||||
a:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 700px) {
|
||||
width: calc(100% - 6.5ch);
|
||||
}
|
||||
}
|
||||
|
||||
div.post-body {
|
||||
@@ -48,15 +64,34 @@ div.post {
|
||||
div.annotation {
|
||||
margin-top: 0.33em;
|
||||
}
|
||||
}
|
||||
div.post-body p:first-of-type {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
|
||||
p:first-of-type {
|
||||
margin-top: 0;
|
||||
padding-top: 0;
|
||||
}
|
||||
p:last-of-type {
|
||||
padding-bottom: 0.1em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
div.post.pk-scene {
|
||||
margin-left: -14px;
|
||||
border-left: 2px solid #68A;
|
||||
}
|
||||
|
||||
div.post.pk-scene.anchored {
|
||||
background-color: rgba(102, 136, 170, 0.25);
|
||||
}
|
||||
div.post.pk-action.anchored {
|
||||
background-color: rgba(170, 102, 68, 0.25);
|
||||
}
|
||||
div.post.pk-text.anchored {
|
||||
background-color: rgba(170, 170, 170, 0.25);
|
||||
}
|
||||
|
||||
div.post.multipart {
|
||||
margin-top: -1.25em;
|
||||
margin-top: -0.9em;
|
||||
|
||||
div.post-meta {
|
||||
span {
|
||||
|
||||
@@ -49,9 +49,9 @@ module.exports = class {
|
||||
|
||||
const search = this.state.search.toLocaleLowerCase()
|
||||
|
||||
this.state.characters = input.characters.filter(c => !this.state.activeMap.characters[c.id]).filter(c => this.matches(c.name, search)).sort((a,b) => a.name.localeCompare(b.name))
|
||||
this.state.channels = input.channels.filter(c => !this.state.activeMap.channels[c.name]).filter(c => this.matches(c.name, search)).sort((a,b) => a.name.localeCompare(b.name))
|
||||
this.state.eventNames = input.eventNames.filter(e => !this.state.activeMap.events[e]).filter(e => this.matches(e, search)).sort((a,b) => a.localeCompare(b))
|
||||
this.state.characters = input.characters.filter(c => !this.state.activeMap.characters[c.id]).filter(c => this.matches(c.name, search)).sort((a,b) => compareFilters(a.name, b.name, search))
|
||||
this.state.channels = input.channels.filter(c => !this.state.activeMap.channels[c.name]).filter(c => this.matches(c.name, search)).sort((a,b) => compareFilters(a.name, b.name, search))
|
||||
this.state.eventNames = input.eventNames.filter(e => !this.state.activeMap.events[e]).filter(e => this.matches(e, search)).sort((a,b) => compareFilters(a, b, search))
|
||||
}
|
||||
|
||||
updateActive({filter, characters, channels, eventNames}) {
|
||||
@@ -126,4 +126,29 @@ module.exports = class {
|
||||
|
||||
return str.toLowerCase().indexOf(search) !== -1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} a
|
||||
* @param {string} b
|
||||
* @param {string} search
|
||||
*/
|
||||
function compareFilters(a, b, search) {
|
||||
if (search != "") {
|
||||
if (search.charAt(0) != "#" && a.charAt(0) == "#" && b.charAt(0) == "#") {
|
||||
search = '#' + search
|
||||
}
|
||||
|
||||
const aStarts = a.toLocaleLowerCase().startsWith(search)
|
||||
const bStarts = b.toLocaleLowerCase().startsWith(search)
|
||||
|
||||
if (aStarts && !bStarts) {
|
||||
return -1
|
||||
} else if (bStarts && !aStarts) {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
return a.localeCompare(b)
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
const {tz} = require("moment-timezone")
|
||||
|
||||
const {logsApi} = require("../../../../../rpdata/api/Log")
|
||||
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
this.state = {
|
||||
error: null,
|
||||
loading: false,
|
||||
imported: null,
|
||||
values: {
|
||||
importer: "MircLike",
|
||||
timezone: tz.guess() || "UTC",
|
||||
channelName: "",
|
||||
date: "",
|
||||
data: "",
|
||||
},
|
||||
timezones: tz.names(),
|
||||
}
|
||||
|
||||
this.first = false
|
||||
}
|
||||
|
||||
change(key, ev) {
|
||||
this.state.values[key] = ev.target.value
|
||||
this.state.values = Object.assign({}, this.state.values)
|
||||
}
|
||||
|
||||
open() {
|
||||
this.state.loading = false
|
||||
}
|
||||
|
||||
close() {
|
||||
this.emit("close")
|
||||
|
||||
this.state.values = {
|
||||
importer: "MircLike",
|
||||
timezone: tz.guess() || "UTC",
|
||||
channelName: "",
|
||||
date: "",
|
||||
data: "",
|
||||
}
|
||||
this.state.imported = null
|
||||
this.state.loading = false
|
||||
}
|
||||
|
||||
save() {
|
||||
if (this.state.loading) {
|
||||
return
|
||||
}
|
||||
this.state.error = null;
|
||||
|
||||
const input = Object.assign({}, this.state.values)
|
||||
if (input.date != "" && input.importer !== "ForumLog") {
|
||||
input.date = new Date(input.date)
|
||||
if (Number.isNaN(input.date)) {
|
||||
this.state.error = "Invalid date"
|
||||
return
|
||||
}
|
||||
} else if (input.importer === "MircLike") {
|
||||
this.state.error = "Date is required for mIRC-like logs"
|
||||
return
|
||||
} else {
|
||||
input.date = null;
|
||||
}
|
||||
|
||||
if (input.channelName.length < 2 || input.channelName.includes(" ") || input.channelName.includes(" ") || input.channelName.charAt(0) !== "#") {
|
||||
this.state.error = "A valid channelName name is required"
|
||||
return
|
||||
}
|
||||
|
||||
this.state.loading = true
|
||||
logsApi.import(input).then(logs => {
|
||||
this.state.imported = logs
|
||||
}).catch(errs => {
|
||||
console.warn("Import failed:", errs)
|
||||
|
||||
this.state.error = "Import failed: " + errs[0].message
|
||||
}).then(() => {
|
||||
this.state.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import moment from "moment"
|
||||
|
||||
<modal class="modal color-text nolabel" key="modal" enabled=(input.enabled) closable on-close("close") on-open("open") >
|
||||
<if(state.imported == null)>
|
||||
<h1>Import Log</h1>
|
||||
|
||||
<p key="error" class="color-error">${state.error}</p>
|
||||
|
||||
<label>Type</label>
|
||||
<select key="importer" autofocus class="big" placeholder="Kind" on-change("change", "importer") value=state.values.importer>
|
||||
<option value="MircLike" selected=(state.values.importer === "MircLike")>mIRC-Like log</option>
|
||||
<option value="ForumLog" selected=(state.values.importer === "ForumLog")>Forum Log</option>
|
||||
</select>
|
||||
|
||||
<label>Timezone</label>
|
||||
<select key="timezone" class="big" placeholder="Kind" on-change("change", "timezone") value=state.values.timezone>
|
||||
<option for(tz in state.timezones) value=tz selected=(state.values.timezone === tz)>${tz}</option>
|
||||
</select>
|
||||
|
||||
<label>Channel</label>
|
||||
<input key="channelName" placeholder="(Required)" class="big" on-change("change", "channelName") value=state.values.channelName />
|
||||
|
||||
<if(state.values.importer === "MircLike")>
|
||||
<label>Date</label>
|
||||
<input key="date" class="big" placeholder="(Required)" on-change("change", "date") value=state.values.date />
|
||||
</if>
|
||||
|
||||
<label>Content</label>
|
||||
<textarea key="data" placeholder="(Required)" class="tall" on-change("change", "data") value=state.values.data />
|
||||
|
||||
<button disabled=state.loading on-click("save")>Import</button>
|
||||
</if>
|
||||
<else>
|
||||
<h1>Import Successful</h1>
|
||||
|
||||
<p>The following logs were imported.</p>
|
||||
|
||||
<ol class="imported-log-list">
|
||||
<for (log in state.imported)>
|
||||
<li><a class="color-primary" href=("/logs/" + log.id)>${log.id} (${moment(log.date).format("MMMM D, YYYY")})</a></li>
|
||||
</for>
|
||||
</ol>
|
||||
</else>
|
||||
</modal>
|
||||
@@ -0,0 +1,9 @@
|
||||
ol.imported-log-list {
|
||||
color: #777;
|
||||
|
||||
li {
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,5 +3,6 @@
|
||||
<menu-link key="logs" selected=(input.selected.index && !state.filtered) icon="L" href="/logs/">All</menu-link>
|
||||
<if-permitted key="if-permitted" user=input.user permission="log.add">
|
||||
<menu-link key="add_log" dark on-click("select", "log.add") icon="+">Add Log</menu-link>
|
||||
<menu-link key="import_log" dark on-click("select", "log.import") icon="+">Import Log</menu-link>
|
||||
</if-permitted>
|
||||
</menu>
|
||||
@@ -1,4 +1,4 @@
|
||||
const {logHeaderApi} = require("../../../../../rpdata/api/LogHeader")
|
||||
const { logHeaderApi } = require("../../../../../rpdata/api/LogHeader")
|
||||
|
||||
module.exports = class {
|
||||
onCreate(input) {
|
||||
@@ -24,11 +24,12 @@ module.exports = class {
|
||||
} else {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {search: null})
|
||||
}
|
||||
|
||||
} else {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {[type]: (this.state.filter[type] || []).filter(f => f !== filter).concat(filter)})
|
||||
}
|
||||
|
||||
this.state.filter = Object.assign({}, this.state.filter, {limit: 0})
|
||||
|
||||
this.updateQuery(this.state.filter)
|
||||
|
||||
this.refresh()
|
||||
@@ -67,6 +68,9 @@ module.exports = class {
|
||||
if (filter.search) {
|
||||
queries.push("search=" + encodeURIComponent(filter.search))
|
||||
}
|
||||
if (filter.limit) {
|
||||
queries.push("limit=" + encodeURIComponent(filter.limit.toString()))
|
||||
}
|
||||
|
||||
if (queries.length > 0) {
|
||||
history.replaceState("", "", `/logs/?${queries.join("&")}`)
|
||||
@@ -75,6 +79,13 @@ module.exports = class {
|
||||
}
|
||||
}
|
||||
|
||||
clearLimit() {
|
||||
this.state.filter = Object.assign({}, this.state.filter, {limit: 0})
|
||||
|
||||
this.refresh()
|
||||
this.updateQuery(this.state.filter)
|
||||
}
|
||||
|
||||
refresh() {
|
||||
logHeaderApi.list(this.state.filter).then(logs => {
|
||||
this.state.logs = logs
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
<background src="/assets/images/bg.png" opacity=0.25 />
|
||||
<logs-menu key="menu" on-select("open") selected=(input.selected || {}) user=input.user filter=state.filter characters=input.characters />
|
||||
<filter-menu on-add("addFilter") on-remove("removeFilter") filter=state.filter characters=input.characters channels=input.channels eventNames=input.eventNames />
|
||||
<main class="with-right">
|
||||
<main class="logs-page with-right">
|
||||
<logs-table logs=state.logs on-addfilter("addFilter") />
|
||||
<if(state.filter.limit > 0)>
|
||||
<div class="show-more-button" on-click("clearLimit")>
|
||||
<span>Show All</span>
|
||||
</div>
|
||||
</if>
|
||||
</main>
|
||||
<add-log-modal enabled=(state.modal === "log.add") on-close("close") />
|
||||
<import-log-modal enabled=(state.modal === "log.import") on-close("close") />
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
main.logs-page {
|
||||
div.show-more-button {
|
||||
margin: 1em 0;
|
||||
padding: 0.5em 2em;
|
||||
font-size: 2em;
|
||||
text-align: center;
|
||||
user-select: none;
|
||||
|
||||
color: #DA1;
|
||||
}
|
||||
|
||||
div.show-more-button:hover {
|
||||
cursor: pointer;
|
||||
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<div class="story-chapter">
|
||||
<a class="anchor" id=input.chapter.id />
|
||||
<h1 if(input.chapter.title) class="title color-primary">${input.chapter.title}</h1>
|
||||
<h1 if(input.chapter.title && !input.hideTitle) class="title color-primary">${input.chapter.title}</h1>
|
||||
<div class="metadata">
|
||||
<div class="options color-menu">
|
||||
<if-permitted user=input.user author=input.chapter.author permission="chapter.edit">
|
||||
|
||||
@@ -40,6 +40,10 @@
|
||||
a:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 700px) {
|
||||
width: calc(100% - 6.5ch);
|
||||
}
|
||||
}
|
||||
|
||||
div.chapter-content {
|
||||
|
||||
@@ -8,18 +8,22 @@
|
||||
<a on-click("open", "story.edit") class="color-menu">Edit</a>
|
||||
</if-permitted>
|
||||
<if-permitted user=input.user author=state.story.author permission="story.remove">
|
||||
<a on-click("open", "story.remove") class="color-menu">Remove</a>
|
||||
<a on-click("open", "story.remove") class="color-menu">Remove</a>
|
||||
</if-permitted>
|
||||
</if>
|
||||
</div>
|
||||
<story-tags tags=state.story.tags author=state.story.author user=(!state.removed ? input.user : null) on-select("open", "story.tags")/>
|
||||
<story-tags tags=state.story.tags open=state.story.open author=state.story.author user=(!state.removed ? input.user : null) on-select("open", "story.tags")/>
|
||||
<annotation if(state.removed) level="error">
|
||||
<p>
|
||||
This story has been removed. Your browser has not refreshed the page yet,
|
||||
so you can still read it (or back it up) before leaving the page.
|
||||
</p>
|
||||
</annotation>
|
||||
<chapter for(chapter in state.story.chapters) key=chapter.id chapter=chapter user=(!state.removed ? input.user : null) on-edit("updateChapter", chapter.id) on-remove("removeChapter", chapter.id) on-move("moveChapter", chapter) />
|
||||
<chapter for(chapter in state.story.chapters) key=chapter.id
|
||||
chapter=chapter
|
||||
user=(!state.removed ? input.user : null)
|
||||
hideTitle=(state.story.chapters[0] === chapter && chapter.title === state.story.name)
|
||||
on-edit("updateChapter", chapter.id) on-remove("removeChapter", chapter.id) on-move("moveChapter", chapter) />
|
||||
</div>
|
||||
|
||||
<create-chapter-modal storyId=state.story.id enabled=(state.modal === "chapter.add") chapter=input.chapter on-close("close") on-add("addChapter") />
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
<div class="story-tags">
|
||||
<a for(tag in input.tags) href=("/story/by-tag/" + tag.kind + "/" + encodeURIComponent(tag.name)) class=["tag", "color-tag-" + tag.kind.toLowerCase()]>${tag.name}</a>
|
||||
<if-permitted user=input.user author=input.author permission="story.edit">
|
||||
<a on-click("select", "edit") class="option color-menu">Manage Tags</a>
|
||||
</if-permitted>
|
||||
|
||||
<if(input.open)>
|
||||
<if-permitted user=input.user permission="member">
|
||||
<a on-click("select", "edit") class="option color-menu">Manage Tags (Open)</a>
|
||||
</if-permitted>
|
||||
</if>
|
||||
<else>
|
||||
<if-permitted user=input.user author=input.author permission="story.edit">
|
||||
<a on-click("select", "edit") class="option color-menu">Manage Tags</a>
|
||||
</if-permitted>
|
||||
</else>
|
||||
</div>
|
||||
Generated
+1196
-48
File diff suppressed because it is too large
Load Diff
@@ -25,6 +25,8 @@
|
||||
"express-http-proxy": "^1.2.0",
|
||||
"express-session": "^1.15.6",
|
||||
"graphql-query-compress": "^1.1.0",
|
||||
"http-proxy-middleware": "^0.19.1",
|
||||
"ip": "^1.1.5",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"jsonwebtoken": "^8.3.0",
|
||||
"lasso": "^3.2.6",
|
||||
@@ -37,8 +39,12 @@
|
||||
"markdown-it-regexp": "^0.4.0",
|
||||
"marko": "^4.13.8",
|
||||
"moment": "^2.22.2",
|
||||
"moment-timezone": "^0.5.23",
|
||||
"passport": "^0.4.0",
|
||||
"passport-auth0": "^1.0.0",
|
||||
"pluralize": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/http-proxy-middleware": "^0.19.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const express = require("express")
|
||||
const router = express.Router()
|
||||
|
||||
const {changesApi} = require("../../rpdata/api/Change")
|
||||
|
||||
const changesTemplate = require("../../marko/page/data/changes.marko")
|
||||
|
||||
router.get("/", async(req, res) => {
|
||||
res.markoAsync(changesTemplate, {
|
||||
changes: changesApi.list({limit: 2000}),
|
||||
selected: {changes: true},
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = router
|
||||
@@ -1,3 +1,4 @@
|
||||
const proxy = require("http-proxy-middleware")
|
||||
const express = require("express")
|
||||
const jwt = require("jsonwebtoken")
|
||||
|
||||
@@ -44,6 +45,7 @@ router.post("/", (req, res) => {
|
||||
})
|
||||
})
|
||||
|
||||
router.use("/", proxy(config.graphqlEndpoint, {ws: true}))
|
||||
|
||||
/**
|
||||
* @param {string} user
|
||||
|
||||
@@ -8,19 +8,26 @@ const {channelApi} = require("../../rpdata/api/Channel")
|
||||
const listTemplate = require("../../marko/page/logs/list.marko")
|
||||
|
||||
router.get("/", async(req, res) => {
|
||||
const filter = {limit: 0}
|
||||
const filter = {limit: 75}
|
||||
|
||||
if (req.query.characters) {
|
||||
filter.characters = req.query.characters.split(",")
|
||||
filter.limit = 0
|
||||
}
|
||||
if (req.query.channels) {
|
||||
filter.channels = req.query.channels.split(",")
|
||||
filter.limit = 0
|
||||
}
|
||||
if (req.query.events) {
|
||||
filter.events = req.query.events.split(",")
|
||||
filter.limit = 0
|
||||
}
|
||||
if (req.query.search) {
|
||||
filter.search = req.query.search
|
||||
filter.limit = 0
|
||||
}
|
||||
if (req.query.limit) {
|
||||
filter.limit = parseInt(req.query.limit)
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
const {query} = require("../client")
|
||||
|
||||
class Change {
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {string} model
|
||||
* @param {string} op
|
||||
* @param {string} author
|
||||
* @param {Date | string | number} date
|
||||
* @param {{model:string,id:string}[]} keys '
|
||||
* @param {{type:string, [x:string]:any}[]} objects
|
||||
*/
|
||||
constructor(id, model, op, author, date, keys, objects) {
|
||||
this.id = id
|
||||
this.model = model
|
||||
this.op = op
|
||||
this.author = author
|
||||
this.date = date
|
||||
this.keys = keys
|
||||
this.objects = objects
|
||||
}
|
||||
|
||||
static fromData(data) {
|
||||
return new Change(data.id, data.model, data.op, data.author, data.date, data.keys, data.objects)
|
||||
}
|
||||
}
|
||||
|
||||
class ChangesAPI {
|
||||
/**
|
||||
* Call `channels(filter)` query
|
||||
*
|
||||
* @param {{limit:int, keys: {model:string,id:string}[]}} filter
|
||||
* @returns {Promise<Change[]>}
|
||||
*/
|
||||
list(filter = null) {
|
||||
return query(`
|
||||
query ListChanges($filter:ChangesFilter) {
|
||||
changes(filter:$filter) {
|
||||
id
|
||||
model
|
||||
op
|
||||
author
|
||||
date
|
||||
keys {
|
||||
model
|
||||
id
|
||||
}
|
||||
objects {
|
||||
type: __typename
|
||||
|
||||
...on Character {
|
||||
id
|
||||
name
|
||||
}
|
||||
|
||||
...on Chapter {
|
||||
id
|
||||
title
|
||||
}
|
||||
|
||||
...on Story {
|
||||
id
|
||||
name
|
||||
}
|
||||
|
||||
...on Post {
|
||||
id
|
||||
time
|
||||
nick
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {filter}).then(({changes}) => {
|
||||
return changes.map(d => Change.fromData(d))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Change, changesApi: new ChangesAPI }
|
||||
|
||||
@@ -190,6 +190,19 @@ class ChracterAPI {
|
||||
return removeCharacter
|
||||
})
|
||||
}
|
||||
|
||||
unknownNicks(limit = 100) {
|
||||
return query(`
|
||||
query UnknownNicks($limit: Int!) {
|
||||
unknownNicks(filter: {limit: $limit}) {
|
||||
nick
|
||||
score
|
||||
}
|
||||
}
|
||||
`, {limit}).then(({unknownNicks}) => {
|
||||
return unknownNicks
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Character, charactersApi: new ChracterAPI }
|
||||
+90
-2
@@ -1,4 +1,4 @@
|
||||
const {query} = require("../client")
|
||||
const {query, Subscription} = require("../client")
|
||||
|
||||
const {Character} = require("./Character")
|
||||
const {Channel} = require("./Channel")
|
||||
@@ -124,6 +124,53 @@ class LogAPI {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Call `importLog(input)` mutation, returns multpile logs.
|
||||
*
|
||||
* @param {{importer:"MircLike"|"ForumLog", date?:Date|string|number, channel:string, timezone:string, data:string}} input
|
||||
* @returns {Promise<Log[]>}
|
||||
*/
|
||||
import(input) {
|
||||
return query(`
|
||||
mutation ImportLog($input: LogImportInput!) {
|
||||
importLog(input: $input) {
|
||||
id
|
||||
shortId
|
||||
date
|
||||
title
|
||||
eventName
|
||||
description
|
||||
open
|
||||
channel {
|
||||
name
|
||||
logged
|
||||
hub
|
||||
eventName
|
||||
locationName
|
||||
}
|
||||
characters {
|
||||
id
|
||||
nicks
|
||||
author
|
||||
name
|
||||
shortName
|
||||
description
|
||||
}
|
||||
posts {
|
||||
id
|
||||
position
|
||||
time
|
||||
kind
|
||||
nick
|
||||
text
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {input}, {permissions: ["log.add"]}).then(({importLog}) => {
|
||||
return importLog.map(d => Log.fromData(d))
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Call `editLog(input)` mutation, returns the id and all editable fields.
|
||||
*
|
||||
@@ -146,7 +193,6 @@ class LogAPI {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call `removeLog(input)` mutation, returns the id
|
||||
*
|
||||
@@ -164,6 +210,48 @@ class LogAPI {
|
||||
return editLog
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to the changes.
|
||||
*
|
||||
* @param {string} logId The long logId, the short one won't do.
|
||||
*/
|
||||
subscribeChanges(logId) {
|
||||
return new Subscription(`
|
||||
subscription Changes($keys: [ChangeKeyInput!]!) {
|
||||
changes(keys: $keys) {
|
||||
id
|
||||
model
|
||||
op
|
||||
author
|
||||
listed
|
||||
keys {
|
||||
model
|
||||
id
|
||||
}
|
||||
date
|
||||
objects {
|
||||
type: __typename
|
||||
...on Log {
|
||||
id
|
||||
title
|
||||
eventName
|
||||
description
|
||||
open
|
||||
}
|
||||
...on Post {
|
||||
id
|
||||
time
|
||||
kind
|
||||
nick
|
||||
text
|
||||
position
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`, {keys: [{model: "Log", id: logId}]})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { Log, logsApi: new LogAPI }
|
||||
+86
-1
@@ -1,3 +1,4 @@
|
||||
const EventEmitter = require("events")
|
||||
const fetch = require("isomorphic-fetch")
|
||||
const config = require("../config")
|
||||
const compressQuery = require("graphql-query-compress")
|
||||
@@ -30,4 +31,88 @@ function query(query, variables = {}, options = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = { query }
|
||||
class Subscription extends EventEmitter {
|
||||
constructor(query, variables) {
|
||||
super()
|
||||
|
||||
this.query = query
|
||||
this.variables = Object.assign({}, variables)
|
||||
this.websocket = null
|
||||
this.verboseLogging = false
|
||||
}
|
||||
|
||||
connect() {
|
||||
const baseUrl = (window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host
|
||||
let id = 1
|
||||
|
||||
this.websocket = new WebSocket(baseUrl + config.graphqlEndpoint, "graphql-ws")
|
||||
|
||||
this.websocket.onopen = () => {
|
||||
this.websocket.send(JSON.stringify({type: "connection_init", payload: {}}));
|
||||
this.websocket.send(JSON.stringify({id: (id++).toFixed(0), type: "start", payload: {
|
||||
query: this.query,
|
||||
variables: this.variables,
|
||||
extensions: {},
|
||||
}}));
|
||||
|
||||
console.log("WS Open")
|
||||
}
|
||||
|
||||
this.websocket.onmessage = (ev) => {
|
||||
let data = {}
|
||||
try {
|
||||
data = JSON.parse(ev.data)
|
||||
} catch (err) {
|
||||
console.warn("Error", err, ev)
|
||||
return
|
||||
}
|
||||
|
||||
if (this.verboseLogging) {
|
||||
console.log("WS Data:", data)
|
||||
}
|
||||
|
||||
switch (data.type) {
|
||||
case "connection_ack": {
|
||||
this.emit("connect")
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "connection_error": {
|
||||
console.warn("WS Connection Error", data.payload.message)
|
||||
this.websocket.close()
|
||||
|
||||
this.emit("error", new Error(data.payload.message))
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "data": {
|
||||
if (data.payload.errors != null && data.payload.errors.length > 0) {
|
||||
this.emit("error", data.payload.errors)
|
||||
} else {
|
||||
this.emit("data", data.payload.data)
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.websocket.onerror = (err) => {
|
||||
console.warn("WS Error", err)
|
||||
}
|
||||
|
||||
this.websocket.onclose = () => {
|
||||
this.emit("disconnect")
|
||||
}
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this.websocket != null) {
|
||||
this.websocket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { query, Subscription }
|
||||
@@ -8,6 +8,9 @@ const config = require("./config")
|
||||
// Express depedencies
|
||||
const express = require("express")
|
||||
const proxy = require("express-http-proxy")
|
||||
const proxy2 = require("http-proxy-middleware")
|
||||
const ip = require("ip")
|
||||
const dns = require("dns")
|
||||
const lasso = require("lasso")
|
||||
const lassoMiddleware = require("lasso/middleware")
|
||||
const markoExpress = require("marko/express")
|
||||
@@ -25,7 +28,39 @@ lasso.configure(require("./marko-config"))
|
||||
|
||||
// Set trusted proxy
|
||||
if (config.trustedProxy != null) {
|
||||
app.set('trust proxy', config.trustedProxy)
|
||||
if (ip.isV4Format(config.trustedProxy) || ip.isV6Format(config.trustedProxy)) {
|
||||
app.set('trust proxy', config.trustedProxy)
|
||||
|
||||
console.log("Trusting proxy", config.trustedProxy);
|
||||
} else {
|
||||
let trusted = null
|
||||
|
||||
setInterval(() => {
|
||||
dns.resolve4(config.trustedProxy, (err, res) => {
|
||||
if (err != null) {
|
||||
if (trusted === null) {
|
||||
console.error("Failed to resolve trustedProxy hostname")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
if (res.length === 0) {
|
||||
if (trusted === null) {
|
||||
console.error("No results for trustedProxy hostname")
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if (trusted !== res[0]) {
|
||||
console.log("Trusting proxy", res[0], `(${config.trustedProxy})`);
|
||||
app.set('trust proxy', res[0])
|
||||
|
||||
trusted = res[0]
|
||||
}
|
||||
})
|
||||
}, 1000)
|
||||
}
|
||||
}
|
||||
|
||||
// Apply middleware
|
||||
@@ -72,6 +107,7 @@ app.use("/logs/:id(L[0-9]{0,7})/", require("./routes/logs-content"))
|
||||
app.use("/data/", require("./routes/data"))
|
||||
app.use("/data/characters/", require("./routes/data/characters"))
|
||||
app.use("/data/channels/", require("./routes/data/channels"))
|
||||
app.use("/data/changes/", require("./routes/data/changes"))
|
||||
|
||||
// Entry point
|
||||
app.get("/", function(req, res) {
|
||||
|
||||
Reference in New Issue
Block a user