Browse Source

token信息转移到headers

pull/6/head
hole-thu 5 years ago
parent
commit
8ee3bca212
  1. 6
      src/Message.js
  2. 9
      src/UserAction.js
  3. 53
      src/flows_api.js

6
src/Message.js

@ -26,8 +26,10 @@ export class MessageViewer extends PureComponent {
},
() => {
fetch(
'/_api/v1/systemlog?user_token=' +
encodeURIComponent(this.props.token)
'/_api/v1/systemlog',
{
headers: {'User-Token': this.props.token},
}
)
.then(get_json)
.then((json) => {

9
src/UserAction.js

@ -15,7 +15,6 @@ import { cache } from './cache';
import {
API,
get_json,
token_param,
} from './flows_api';
import './UserAction.css';
@ -268,13 +267,13 @@ export class ReplyForm extends Component {
let data = new URLSearchParams();
data.append('pid', this.props.pid);
data.append('text', this.state.text);
data.append('user_token', this.props.token);
fetch(
API_BASE + '/docomment' + token_param(this.props.token),
API_BASE + '/docomment',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Token': this.props.token,
},
body: data,
},
@ -396,13 +395,13 @@ export class PostForm extends Component {
data.append('cw', this.state.cw);
data.append('text', this.state.text);
data.append('type', img ? 'image' : 'text');
data.append('user_token', this.props.token);
if (img) data.append('data', img);
fetch(API_BASE + '/dopost' + token_param(this.props.token), {
fetch(API_BASE + '/dopost', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Token': this.props.token,
},
body: data,
})

53
src/flows_api.js

@ -2,10 +2,6 @@ import { get_json, gen_name} from './infrastructure/functions';
import { API_BASE } from './Common';
import { cache } from './cache';
export function token_param(token) {
return token ? '?user_token=' + token : '?notoken';
}
export { get_json };
const SEARCH_PAGESIZE = 50;
@ -35,7 +31,12 @@ export const API = {
load_replies: async (pid, token, color_picker, cache_version) => {
pid = parseInt(pid);
let response = await fetch(
API_BASE + '/getcomment' + token_param(token) + '&pid=' + pid ,
API_BASE + '/getcomment?pid=' + pid ,
{
headers: {
'User-Token': token,
}
}
);
let json = await handle_response(response);
// Why delete then put ??
@ -62,15 +63,15 @@ export const API = {
set_attention: async (pid, attention, token) => {
let data = new URLSearchParams();
data.append('user_token', token);
data.append('pid', pid);
data.append('switch', attention ? '1' : '0');
let response = await fetch(
API_BASE + '/attention' + token_param(token),
API_BASE + '/attention',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Token': token,
},
body: data,
},
@ -82,15 +83,15 @@ export const API = {
report: async (pid, reason, token) => {
let data = new URLSearchParams();
data.append('user_token', token);
data.append('pid', pid);
data.append('reason', reason);
let response = await fetch(
API_BASE + '/report' + token_param(token),
API_BASE + '/report',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Token': token,
},
body: data,
},
@ -104,11 +105,12 @@ export const API = {
data.append('id', id);
data.append('note', note);
let response = await fetch(
API_BASE + '/delete' + token_param(token),
API_BASE + '/delete',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Token': token,
},
body: data,
},
@ -121,11 +123,12 @@ export const API = {
data.append('cw', cw);
data.append('pid', id);
let response = await fetch(
API_BASE + '/editcw' + token_param(token),
API_BASE + '/editcw',
{
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Token': token,
},
body: data,
},
@ -135,10 +138,11 @@ export const API = {
get_list: async (page, token) => {
let response = await fetch(
API_BASE + '/getlist'
+ token_param(token)
+ '&p=' + page
+ (window.config.no_c_post ? '&no_cw' : '')
API_BASE + '/getlist?p=' + page
+ (window.config.no_c_post ? '&no_cw' : ''),
{
headers: {'User-Token': token},
},
);
return handle_response(response);
},
@ -146,28 +150,35 @@ export const API = {
get_search: async (page, keyword, token) => {
let response = await fetch(
API_BASE +
'/search' +
token_param(token) +
'&pagesize=' +
'/search?pagesize=' +
SEARCH_PAGESIZE +
'&page=' +
page +
'&keywords=' +
encodeURIComponent(keyword)
encodeURIComponent(keyword),
{
headers: {'User-Token': token},
}
);
return handle_response(response);
},
get_single: async (pid, token) => {
let response = await fetch(
API_BASE + '/getone' + token_param(token) + '&pid=' + pid,
API_BASE + '/getone?pid=' + pid,
{
headers: {'User-Token': token},
}
);
return handle_response(response);
},
get_attention: async (token) => {
let response = await fetch(
API_BASE + '/getattention' + token_param(token),
API_BASE + '/getattention',
{
headers: {'User-Token': token},
}
);
return handle_response(response);
},

Loading…
Cancel
Save