Skip to content

Commit b4e7e50

Browse files
committed
Swith to POST session request with webClientId and updateType
1 parent ce28603 commit b4e7e50

File tree

3 files changed

+41
-50
lines changed

3 files changed

+41
-50
lines changed

alvr/web_server/src/main.rs

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use logging_backend::*;
88
use settings_schema::Switch;
99
use std::{
1010
path::PathBuf,
11-
sync::{Arc, Mutex},
11+
sync::{Arc, Mutex, atomic::*},
1212
time::SystemTime,
1313
};
1414
use tail::tail_stream;
@@ -225,48 +225,27 @@ async fn run(log_senders: Arc<Mutex<Vec<UnboundedSender<String>>>>) -> StrResult
225225
let session_manager = session_manager.clone();
226226
move || reply::json(session_manager.lock().unwrap().get())
227227
})
228-
.or(warp::path!(String).and(body::json()).map({
228+
.or(warp::path!(String / String).and(body::json()).map({
229229
let session_manager = session_manager.clone();
230-
move |meta_str: String, value: serde_json::Value| {
231-
let meta_list = meta_str.split('?').collect::<Vec<_>>();
232-
if meta_list.len() == 2 {
233-
let update_author_id = meta_list[0];
234-
if let Ok(update_type) = serde_json::from_str(meta_list[1]) {
235-
let res = session_manager
236-
.lock()
237-
.unwrap()
238-
.get_mut(update_author_id, update_type)
239-
.merge_from_json(value);
240-
if let Err(e) = res {
241-
warn!("{}", e);
242-
// HTTP Code: WARNING
243-
return reply::with_status(
244-
reply(),
245-
StatusCode::from_u16(199).unwrap(),
246-
);
247-
} else {
248-
return reply::with_status(reply(), StatusCode::OK);
249-
}
230+
move |update_type: String, update_author_id: String, value: serde_json::Value| {
231+
if let Ok(update_type) = serde_json::from_str(&format!("\"{}\"", update_type)) {
232+
let res = session_manager
233+
.lock()
234+
.unwrap()
235+
.get_mut(&update_author_id, update_type)
236+
.merge_from_json(value);
237+
if let Err(e) = res {
238+
warn!("{}", e);
239+
// HTTP Code: WARNING
240+
reply::with_status(reply(), StatusCode::from_u16(199).unwrap())
241+
} else {
242+
reply::with_status(reply(), StatusCode::OK)
250243
}
244+
} else {
245+
reply::with_status(reply(), StatusCode::BAD_REQUEST)
251246
}
252-
reply::with_status(reply(), StatusCode::BAD_REQUEST)
253247
}
254-
}))
255-
// stopgap. todo: remove
256-
.or(warp::post().and(body::json().map(move |value| {
257-
let res = session_manager
258-
.lock()
259-
.unwrap()
260-
.get_mut("", SessionUpdateType::Settings)
261-
.merge_from_json(value);
262-
if let Err(e) = res {
263-
warn!("{}", e);
264-
// HTTP Code: WARNING
265-
reply::with_status(reply(), StatusCode::from_u16(199).unwrap())
266-
} else {
267-
reply::with_status(reply(), StatusCode::OK)
268-
}
269-
}))),
248+
})),
270249
);
271250

272251
let log_subscription = warp::path("log").and(warp::ws()).map(move |ws: Ws| {

server_release_template/web_gui/js/app/customSettings.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ define([
8181
controllerMode.val(controller.val());
8282
alvrSettings.storeParam(controllerMode, true);
8383

84-
alvrSettings.storeSession();
84+
alvrSettings.storeSession("settings");
8585
});
8686

8787
controller.val(controllerMode.val());
@@ -105,7 +105,7 @@ define([
105105
target.val(headsetOptions[headset.val()][key]);
106106
alvrSettings.storeParam(target, true);
107107
}
108-
alvrSettings.storeSession();
108+
alvrSettings.storeSession("settings");
109109
});
110110

111111
if ($(headsetBase + "modelNumber").val() == "Oculus Rift S") {
@@ -269,7 +269,7 @@ define([
269269
$("#_root_video_renderResolution_scale-choice-").prop("checked", true);
270270
alvrSettings.storeParam($("#_root_video_renderResolution_scale-choice-"), true);
271271

272-
alvrSettings.storeSession();
272+
alvrSettings.storeSession("settings");
273273
});
274274

275275
}
@@ -311,7 +311,7 @@ define([
311311

312312

313313

314-
alvrSettings.storeSession();
314+
alvrSettings.storeSession("settings");
315315

316316
});
317317

server_release_template/web_gui/js/app/settings.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,36 @@ define([
1717
var index = 0;
1818
const usedi18n = {};
1919

20+
function randomAlphanumericID() {
21+
const len = 10;
22+
const arr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghilmnopqrstuvwxyz0123456789";
23+
var ans = '';
24+
for (var i = len; i > 0; i--) {
25+
ans += arr[Math.floor(Math.random() * arr.length)];
26+
}
27+
return ans;
28+
}
29+
30+
var webClientId = randomAlphanumericID();
31+
2032
self.disableWizard = function () {
2133
session.setupWizard = false;
22-
self.storeSession();
34+
self.storeSession("other");
2335
}
2436

2537
self.updateClientTrustState = function (sessionListIndex, state) {
2638
session.lastClients[sessionListIndex].state = state;
27-
self.storeSession();
39+
self.storeSession("clientList");
2840
}
2941

3042
self.pushManualClient = function (descriptor) {
3143
session.lastClients.push(descriptor);
32-
self.storeSession();
44+
self.storeSession("clientList");
3345
}
3446

3547
self.removeClient = function (sessionListIndex) {
3648
session.lastClients.splice(sessionListIndex, 1);
37-
self.storeSession();
49+
self.storeSession("clientList");
3850
}
3951

4052
function init() {
@@ -155,18 +167,18 @@ define([
155167
_.set(session.settingsCache, finalPath, val);
156168

157169
if (!skipstoreSession) {
158-
self.storeSession();
170+
self.storeSession("settings");
159171
}
160172
}
161173

162-
self.storeSession = function () {
174+
self.storeSession = function (updateType) {
163175
if (updating) {
164176
return;
165177
}
166178

167179
$.ajax({
168180
type: "POST",
169-
url: "../../session",
181+
url: `../../session/${updateType}/${webClientId}`,
170182
contentType: "application/json;charset=UTF-8",
171183
data: JSON.stringify(session),
172184
processData: false,

0 commit comments

Comments
 (0)