针对tg来源优化设置临时token后缀

This commit is contained in:
2021-12-18 21:17:01 +08:00
parent ff50857071
commit ef48070eeb
2 changed files with 13 additions and 2 deletions

View File

@@ -99,10 +99,21 @@ class App extends Component {
}
componentDidMount() {
if (window.location.protocol === 'http:' &&
window.location.hostname !== '127.0.0.1' && !window.location.hostname.endsWith('localhost')) {
window.location.protocol = 'https:'; // 因为CDN的原因先在前端做下https跳转
return;
}
let arg = window.location.search;
console.log(arg);
if (arg.startsWith('?token=')) {
localStorage['TOKEN'] = arg.substr(7).replace(encodeURI('任意自定义后缀'), Math.random());
let token = arg.substr(7);
if (token.endsWith(encodeURI('_任意自定义后缀'))) {
let tmp_token_suf = localStorage['TOKEN_SUF'] || prompt('设置一个你专属的临时token后缀吧') || Math.random();
localStorage['TOKEN_SUF'] = tmp_token_suf;
token = `${token.split('_')[0]}_${tmp_token_suf}`;
}
localStorage['TOKEN'] = token;
window.location.search = '';
}
}

View File

@@ -1257,7 +1257,7 @@ class SubFlow extends PureComponent {
.then((json) => {
if (page === 1 && json.data.length) {
// update latest_post_id
let max_id = LATEST_POST_ID || -1;
let max_id = window.LATEST_POST_ID || -1;
json.data.forEach((x) => {
if (parseInt(x.pid, 10) > max_id) max_id = parseInt(x.pid, 10);
});