Add new page
This commit is contained in:
parent
25edc27b6d
commit
cb6aa9f724
|
@ -25,7 +25,10 @@ sub startup ($self) {
|
|||
$r->get('/')->to('Main#index');
|
||||
$r->get('/index.html')->to('Main#index');
|
||||
$r->get('/rules')->to('Main#rules');
|
||||
$r->get('/services')->to('Main#services');
|
||||
|
||||
my $svc = $r->any('/services')->to(controller => 'Services');
|
||||
$svc->get('/')->to(action => 'index');
|
||||
$svc->get('/bridges')->to(action => 'bridges');
|
||||
|
||||
$r->get('/register')->to('Register#registration');
|
||||
$r->post('/register')->to('Register#register');
|
||||
|
|
|
@ -19,11 +19,6 @@ sub rules ($self) {
|
|||
$self->render();
|
||||
}
|
||||
|
||||
sub services ($self) {
|
||||
$self->render();
|
||||
}
|
||||
|
||||
|
||||
my $cache = Mojo::Cache->new(max_keys => 1);
|
||||
$cache->set(users => []);
|
||||
Mojo::IOLoop->recurring(60 => sub {
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package unix_dog::Controller::Services;
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use experimental 'signatures';
|
||||
|
||||
use Mojo::Base 'Mojolicious::Controller', -signatures;
|
||||
|
||||
sub index($c) {
|
||||
$c->render();
|
||||
}
|
||||
|
||||
sub bridges($c) {
|
||||
$c->render();
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,75 @@
|
|||
% title 'UNIX.dog Services';
|
||||
% layout 'default';
|
||||
<section>
|
||||
<h2>XMPP and Matrix Bridge Helper</h2>
|
||||
<p id="result">
|
||||
</p>
|
||||
<noscript>Since JS is disabled, this form will send the addresses to
|
||||
the UNIX.dog server to convert.</noscript>
|
||||
<form id="bridging" method="post">
|
||||
<div>
|
||||
<label for="bridge_service">Bridge:</label>
|
||||
<select name="bridge" id="bridge_service">
|
||||
<option value="unix.dog">UNIX.dog</option>
|
||||
<option value="aria-net">ARIA-net</option>
|
||||
</select>
|
||||
</div>
|
||||
<div>
|
||||
<select name="type" id="bridge_type">
|
||||
<option value="muc">XMPP MUC:</option>
|
||||
<option value="room">Matrix Room:</option>
|
||||
<option value="jid">XMPP User:</option>
|
||||
<option value="user">Matrix User:</option>
|
||||
</select>
|
||||
<input type="text" id="handle" name="handle" required />
|
||||
</div>
|
||||
<div>
|
||||
<input type="submit"/>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
<script>
|
||||
const conversion = {
|
||||
"unix.dog": {
|
||||
"muc": jid => (s => `#_xmpp_${s[0]}_${s[1]}:unix.dog`)(jid.split("@")),
|
||||
"room": rm => `${rm.replace(":","#")}@matrix.unix.dog`,
|
||||
"jid": jid => `@_xmpp_${jid.replace("@", "=40")}:unix.dog`,
|
||||
"user": u => `${u.slice(1).replace(":","_")}@matrix.unix.dog`
|
||||
},
|
||||
"aria-net": {
|
||||
"muc": jid => (s => `#_bifrost_${s[0]}_${s[1]}:aria-net.org`)(jid.split("@")),
|
||||
"room": rm => `${rm.replace(":","#")}@aria-net.org`,
|
||||
"jid": jid => `@_bifrost_${jid.replace("@", "=40")}:aria-net.org`,
|
||||
"user": u => `${u.slice(1).replace(":", "_")}@aria-net.org`
|
||||
},
|
||||
};
|
||||
|
||||
const urlify = {
|
||||
"room": jid => `xmpp:${encodeURI(jid)}?join`,
|
||||
"muc": room => `https://matrix.to/#/%23${encodeURI(room.slice(1))}`,
|
||||
"user": jid => `xmpp:${encodeURI(jid)}?roster`,
|
||||
"jid": u => `https://matrix.to/#/${encodeURI(u)}`,
|
||||
};
|
||||
|
||||
const form = document.getElementById("bridging");
|
||||
const output = document.getElementById("result");
|
||||
|
||||
form.addEventListener("submit", e => {
|
||||
e.preventDefault();
|
||||
|
||||
const formData = new FormData(form);
|
||||
|
||||
let service = formData.get("bridge");
|
||||
let type = formData.get("type");
|
||||
let handle = formData.get("handle");
|
||||
|
||||
let bridged = conversion[service][type](handle);
|
||||
output.textContent = `Use address `
|
||||
|
||||
let link = document.createElement("a");
|
||||
link.href = urlify[type](bridged);
|
||||
link.textContent = bridged;
|
||||
|
||||
output.appendChild(link);
|
||||
});
|
||||
</script>
|
Loading…
Reference in New Issue