recycleactor commited on
Commit
4039d14
·
verified ·
1 Parent(s): bc0ee50

Upload main.rs

Browse files
Files changed (1) hide show
  1. src/main.rs +3 -4
src/main.rs CHANGED
@@ -1207,7 +1207,7 @@ fn forwarded_proto(headers: &HeaderMap) -> String {
1207
  headers
1208
  .get("x-forwarded-proto")
1209
  .and_then(|v| v.to_str().ok())
1210
- .unwrap_or("https")
1211
  .trim()
1212
  .to_string()
1213
  }
@@ -1357,15 +1357,14 @@ async fn pair_page(Host(host): Host, headers: HeaderMap, Query(q): Query<PairPag
1357
  html.push_str(r#"<button id="dz-login" type="button">Войти через Deezer</button>"#);
1358
  html.push_str(r#"<div id="msg" class="muted" style="margin:12px 0 0"></div>"#);
1359
  html.push_str(r#"<div id="dz-root"></div>"#);
1360
- html.push_str(r#"<script src="https://cdns-files.deezer.com/js/min/dz.js"></script>"#);
1361
  html.push_str(r#"<script>(function(){"#);
1362
  html.push_str("var code=");
1363
  html.push_str(&code_js);
1364
- html.push_str(r#";var msg=document.getElementById('msg');function setMsg(cls,text){msg.className=cls?(cls+' muted'):'muted';msg.textContent=text;}if(!code){setMsg('err','Нет кода пары. Открой ссылку заново с QR.');return;}function postToken(at,uid){return fetch('/pair/oauth',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({code:code,access_token:at,user_id:String(uid||'')})}).then(function(r){return r.json().catch(function(){return {};}).then(function(j){return {ok:r.ok,json:j};});});}function initDZ(){try{DZ.init({appId:"#);
1365
  html.push_str(&app_id_js);
1366
  html.push_str(r#",channelUrl:"#);
1367
  html.push_str(&channel_url_js);
1368
- html.push_str(r#"});return true;}catch(e){return false;}}if(!initDZ()){setMsg('err','Не удалось инициализировать Deezer SDK.');return;}document.getElementById('dz-login').addEventListener('click',function(){setMsg('','Ожидаю Deezer…');DZ.login(function(resp){if(resp&&resp.authResponse&&resp.authResponse.accessToken){setMsg('','Сохраняю токен…');postToken(resp.authResponse.accessToken,resp.authResponse.userID).then(function(r){if(r.ok&&!r.json.error){setMsg('ok','Готово ✓ Вернись на телевизор.');}else{setMsg('err','Ошибка сохранения: '+(r.json.error||'error'));}}).catch(function(){setMsg('err','Ошибка сети при сохранении');});}else{setMsg('err','Вход отменён или не удалось получить токен');}},{perms:'basic_access,email,manage_library,listening_history'});});})();</script>"#);
1369
  html.push_str(r#"<p class="muted" style="margin:14px 0 0">Если Deezer пишет про неверный redirect/domain — нужно указать свой <b>DEEZER_APP_ID</b> для домена этого сервера.</p>"#);
1370
  html.push_str(r#"</div></body></html>"#);
1371
  Html(html)
 
1207
  headers
1208
  .get("x-forwarded-proto")
1209
  .and_then(|v| v.to_str().ok())
1210
+ .unwrap_or("http")
1211
  .trim()
1212
  .to_string()
1213
  }
 
1357
  html.push_str(r#"<button id="dz-login" type="button">Войти через Deezer</button>"#);
1358
  html.push_str(r#"<div id="msg" class="muted" style="margin:12px 0 0"></div>"#);
1359
  html.push_str(r#"<div id="dz-root"></div>"#);
 
1360
  html.push_str(r#"<script>(function(){"#);
1361
  html.push_str("var code=");
1362
  html.push_str(&code_js);
1363
+ html.push_str(r#";var msg=document.getElementById('msg');function setMsg(cls,text){msg.className=cls?(cls+' muted'):'muted';msg.textContent=text;}if(!code){setMsg('err','Нет кода пары. Открой ссылку заново с QR.');return;}function postToken(at,uid){return fetch('/pair/oauth',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({code:code,access_token:at,user_id:String(uid||'')})}).then(function(r){return r.json().catch(function(){return {};}).then(function(j){return {ok:r.ok,json:j};});});}function start(){function initDZ(){try{if(!window.DZ||!DZ.init){return false;}DZ.init({appId:"#);
1364
  html.push_str(&app_id_js);
1365
  html.push_str(r#",channelUrl:"#);
1366
  html.push_str(&channel_url_js);
1367
+ html.push_str(r#"});return true;}catch(e){return false;}}if(!initDZ()){setMsg('err','Не удалось инициализировать Deezer SDK.');return;}document.getElementById('dz-login').addEventListener('click',function(){setMsg('','Ожидаю Deezer…');DZ.login(function(resp){if(resp&&resp.authResponse&&resp.authResponse.accessToken){setMsg('','Сохраняю токен…');postToken(resp.authResponse.accessToken,resp.authResponse.userID).then(function(r){if(r.ok&&!r.json.error){setMsg('ok','Готово ✓ Вернись на телевизор.');}else{setMsg('err','Ошибка сохранения: '+(r.json.error||'error'));}}).catch(function(){setMsg('err','Ошибка сети при сохранении');});}else{setMsg('err','Вход отменён или не удалось получить токен');}},{perms:'basic_access,email,manage_library,listening_history'});});}function loadSdk(){var s=document.createElement('script');s.src='https://cdns-files.deezer.com/js/min/dz.js';s.onload=function(){start();};s.onerror=function(){setMsg('err','Не удалось загрузить Deezer SDK (dz.js). Проверь сеть/блокировщик.');};document.head.appendChild(s);}loadSdk();})();</script>"#);
1368
  html.push_str(r#"<p class="muted" style="margin:14px 0 0">Если Deezer пишет про неверный redirect/domain — нужно указать свой <b>DEEZER_APP_ID</b> для домена этого сервера.</p>"#);
1369
  html.push_str(r#"</div></body></html>"#);
1370
  Html(html)