Remove the old api handler

Note that this breaks the admin interface, which will be rewritten
master
Daniel Berteaud 10 years ago
parent bbf4eee3df
commit 27337d4875
  1. 21
      public/js/vroom.js
  2. 47
      vroom.pl

@ -35,7 +35,7 @@ $.ajax({
// Default ajax setup // Default ajax setup
$.ajaxSetup({ $.ajaxSetup({
url: rootUrl + 'jsapi', url: rootUrl + 'api',
type: 'POST', type: 'POST',
dataType: 'json', dataType: 'json',
headers: { headers: {
@ -46,7 +46,6 @@ $.ajaxSetup({
// Handle lang switch // Handle lang switch
$('#switch_lang').change(function(){ $('#switch_lang').change(function(){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'switch_lang', action: 'switch_lang',
@ -98,7 +97,6 @@ function addNotifiedEmail(email){
function removeNotifiedEmail(email){ function removeNotifiedEmail(email){
var id = escapeJqSelector(email.replace(/['"]/, '_').replace('\\\'', '\'')); var id = escapeJqSelector(email.replace(/['"]/, '_').replace('\\\'', '\''));
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'email_notification', action: 'email_notification',
@ -527,7 +525,6 @@ function initVroom(room) {
// Get our role and other room settings from the server // Get our role and other room settings from the server
function getRoomInfo(){ function getRoomInfo(){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'get_room_info', action: 'get_room_info',
@ -593,7 +590,6 @@ function initVroom(room) {
// Get the role of a peer // Get the role of a peer
function getPeerRole(id){ function getPeerRole(id){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'get_peer_role', action: 'get_peer_role',
@ -958,7 +954,6 @@ function initVroom(room) {
function promotePeer(id){ function promotePeer(id){
if (peers[id] && peers[id].role != 'owner'){ if (peers[id] && peers[id].role != 'owner'){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'promote_peer', action: 'promote_peer',
@ -1062,7 +1057,6 @@ function initVroom(room) {
function wipeRoomData(){ function wipeRoomData(){
if (etherpad.enabled){ if (etherpad.enabled){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'wipe_data', action: 'wipe_data',
@ -1450,7 +1444,6 @@ function initVroom(room) {
wipeChatHistory(); wipeChatHistory();
if (etherpad.enabled){ if (etherpad.enabled){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'get_pad_session', action: 'get_pad_session',
@ -1510,7 +1503,6 @@ function initVroom(room) {
// we send it. Not that I like sending this kind of data to the server // we send it. Not that I like sending this kind of data to the server
// but it's needed for email notifications // but it's needed for email notifications
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'join', action: 'join',
@ -1611,7 +1603,6 @@ function initVroom(room) {
return; return;
} }
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'invite_email', action: 'invite_email',
@ -1709,7 +1700,6 @@ function initVroom(room) {
$('#lockButton').change(function() { $('#lockButton').change(function() {
var action = ($(this).is(":checked")) ? 'lock_room' : 'unlock_room'; var action = ($(this).is(":checked")) ? 'lock_room' : 'unlock_room';
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: action, action: action,
@ -1745,7 +1735,6 @@ function initVroom(room) {
$('#askForNameButton').change(function() { $('#askForNameButton').change(function() {
var set = ($(this).is(":checked")) ? 'on':'off'; var set = ($(this).is(":checked")) ? 'on':'off';
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'set_ask_for_name', action: 'set_ask_for_name',
@ -1909,7 +1898,6 @@ function initVroom(room) {
event.preventDefault(); event.preventDefault();
var pass = $('#authPass').val(); var pass = $('#authPass').val();
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'authenticate', action: 'authenticate',
@ -1949,7 +1937,6 @@ function initVroom(room) {
} }
else{ else{
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'set_join_password', action: 'set_join_password',
@ -1986,7 +1973,6 @@ function initVroom(room) {
if (pass == pass2 && pass != ''){ if (pass == pass2 && pass != ''){
$('#setJoinPassButton').addClass('disabled'); $('#setJoinPassButton').addClass('disabled');
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'set_join_password', action: 'set_join_password',
@ -2032,7 +2018,6 @@ function initVroom(room) {
} }
else{ else{
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'set_owner_password', action: 'set_owner_password',
@ -2067,7 +2052,6 @@ function initVroom(room) {
if (pass == pass2 && pass != ''){ if (pass == pass2 && pass != ''){
$('#setOwnerPassButton').addClass('disabled'); $('#setOwnerPassButton').addClass('disabled');
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'set_owner_password', action: 'set_owner_password',
@ -2116,7 +2100,6 @@ function initVroom(room) {
$('#newEmailNotificationForm').submit(function(event){ $('#newEmailNotificationForm').submit(function(event){
event.preventDefault(); event.preventDefault();
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'email_notification', action: 'email_notification',
@ -2306,7 +2289,6 @@ function initVroom(room) {
webrtc.sendToAll('terminate_room', {}); webrtc.sendToAll('terminate_room', {});
wipeRoomData(); wipeRoomData();
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'delete_room', action: 'delete_room',
@ -2351,7 +2333,6 @@ function initVroom(room) {
// Used to detect inactive rooms // Used to detect inactive rooms
setInterval(function(){ setInterval(function(){
$.ajax({ $.ajax({
url: rootUrl + 'api',
data: { data: {
req: JSON.stringify({ req: JSON.stringify({
action: 'ping', action: 'ping',

@ -97,7 +97,7 @@ helper valid_room_name => sub {
my ($name) = @_; my ($name) = @_;
my $ret = {}; my $ret = {};
# A few names are reserved # A few names are reserved
my @reserved = qw(about help feedback feedback_thanks goodbye admin create localize jsapi api my @reserved = qw(about help feedback feedback_thanks goodbye admin create localize api
missing dies password kicked invitation js css img fonts snd); missing dies password kicked invitation js css img fonts snd);
if ($name !~ m/^[\w\-]{1,49}$/ || grep { $name eq $_ } @reserved){ if ($name !~ m/^[\w\-]{1,49}$/ || grep { $name eq $_ } @reserved){
return 0; return 0;
@ -1730,51 +1730,6 @@ get '/:room' => sub {
); );
}; };
# Route for various room actions
post '/*jsapi' => { jsapi => [qw(jsapi admin/jsapi)] } => sub {
my $self = shift;
my $action = $self->param('action');
my $prefix = ($self->stash('jsapi') eq 'admin/jsapi') ? 'admin' : 'room';
my $room = $self->param('room') || '';
# Refuse any action from non members of the room
if ($prefix ne 'admin' && (!$self->session('name') ||
!$self->has_joined({
name => $self->session('name'),
room => $room}) ||
!$self->session($room) ||
!$self->session($room)->{role})){
return $self->render(
json => {
msg => $self->l('ERROR_NOT_LOGGED_IN'),
status => 'error'
}
);
}
# Sanity check on the room name
if (!$self->valid_room_name($room)){
return $self->render(
json => {
msg => $self->l('ERROR_NAME_INVALID'),
status => 'error'
},
);
}
# Push the room name to the stash, just in case
$self->stash(room => $room);
# Gather room info from the DB
my $data = $self->get_room_by_name($room);
# Stop here if the room doesn't exist
if (!$data){
return $self->render(
json => {
msg => sprintf ($self->l('ERROR_ROOM_s_DOESNT_EXIST'), $room),
err => 'ERROR_ROOM_s_DOESNT_EXIST',
status => 'error'
},
);
}
};
# use the templates defined in the config # use the templates defined in the config
push @{app->renderer->paths}, 'templates/'.$config->{'interface.template'}; push @{app->renderer->paths}, 'templates/'.$config->{'interface.template'};
# Set the secret used to sign cookies # Set the secret used to sign cookies

Loading…
Cancel
Save