token信息转移到headers
This commit is contained in:
@@ -26,8 +26,10 @@ export class MessageViewer extends PureComponent {
|
|||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
fetch(
|
fetch(
|
||||||
'/_api/v1/systemlog?user_token=' +
|
'/_api/v1/systemlog',
|
||||||
encodeURIComponent(this.props.token)
|
{
|
||||||
|
headers: {'User-Token': this.props.token},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
.then(get_json)
|
.then(get_json)
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import { cache } from './cache';
|
|||||||
import {
|
import {
|
||||||
API,
|
API,
|
||||||
get_json,
|
get_json,
|
||||||
token_param,
|
|
||||||
} from './flows_api';
|
} from './flows_api';
|
||||||
|
|
||||||
import './UserAction.css';
|
import './UserAction.css';
|
||||||
@@ -268,13 +267,13 @@ export class ReplyForm extends Component {
|
|||||||
let data = new URLSearchParams();
|
let data = new URLSearchParams();
|
||||||
data.append('pid', this.props.pid);
|
data.append('pid', this.props.pid);
|
||||||
data.append('text', this.state.text);
|
data.append('text', this.state.text);
|
||||||
data.append('user_token', this.props.token);
|
|
||||||
fetch(
|
fetch(
|
||||||
API_BASE + '/docomment' + token_param(this.props.token),
|
API_BASE + '/docomment',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'User-Token': this.props.token,
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
},
|
},
|
||||||
@@ -396,13 +395,13 @@ export class PostForm extends Component {
|
|||||||
data.append('cw', this.state.cw);
|
data.append('cw', this.state.cw);
|
||||||
data.append('text', this.state.text);
|
data.append('text', this.state.text);
|
||||||
data.append('type', img ? 'image' : 'text');
|
data.append('type', img ? 'image' : 'text');
|
||||||
data.append('user_token', this.props.token);
|
|
||||||
if (img) data.append('data', img);
|
if (img) data.append('data', img);
|
||||||
|
|
||||||
fetch(API_BASE + '/dopost' + token_param(this.props.token), {
|
fetch(API_BASE + '/dopost', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'User-Token': this.props.token,
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,10 +2,6 @@ import { get_json, gen_name} from './infrastructure/functions';
|
|||||||
import { API_BASE } from './Common';
|
import { API_BASE } from './Common';
|
||||||
import { cache } from './cache';
|
import { cache } from './cache';
|
||||||
|
|
||||||
export function token_param(token) {
|
|
||||||
return token ? '?user_token=' + token : '?notoken';
|
|
||||||
}
|
|
||||||
|
|
||||||
export { get_json };
|
export { get_json };
|
||||||
|
|
||||||
const SEARCH_PAGESIZE = 50;
|
const SEARCH_PAGESIZE = 50;
|
||||||
@@ -35,7 +31,12 @@ export const API = {
|
|||||||
load_replies: async (pid, token, color_picker, cache_version) => {
|
load_replies: async (pid, token, color_picker, cache_version) => {
|
||||||
pid = parseInt(pid);
|
pid = parseInt(pid);
|
||||||
let response = await fetch(
|
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);
|
let json = await handle_response(response);
|
||||||
// Why delete then put ??
|
// Why delete then put ??
|
||||||
@@ -62,15 +63,15 @@ export const API = {
|
|||||||
|
|
||||||
set_attention: async (pid, attention, token) => {
|
set_attention: async (pid, attention, token) => {
|
||||||
let data = new URLSearchParams();
|
let data = new URLSearchParams();
|
||||||
data.append('user_token', token);
|
|
||||||
data.append('pid', pid);
|
data.append('pid', pid);
|
||||||
data.append('switch', attention ? '1' : '0');
|
data.append('switch', attention ? '1' : '0');
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE + '/attention' + token_param(token),
|
API_BASE + '/attention',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'User-Token': token,
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
},
|
},
|
||||||
@@ -82,15 +83,15 @@ export const API = {
|
|||||||
|
|
||||||
report: async (pid, reason, token) => {
|
report: async (pid, reason, token) => {
|
||||||
let data = new URLSearchParams();
|
let data = new URLSearchParams();
|
||||||
data.append('user_token', token);
|
|
||||||
data.append('pid', pid);
|
data.append('pid', pid);
|
||||||
data.append('reason', reason);
|
data.append('reason', reason);
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE + '/report' + token_param(token),
|
API_BASE + '/report',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'User-Token': token,
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
},
|
},
|
||||||
@@ -104,11 +105,12 @@ export const API = {
|
|||||||
data.append('id', id);
|
data.append('id', id);
|
||||||
data.append('note', note);
|
data.append('note', note);
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE + '/delete' + token_param(token),
|
API_BASE + '/delete',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'User-Token': token,
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
},
|
},
|
||||||
@@ -121,11 +123,12 @@ export const API = {
|
|||||||
data.append('cw', cw);
|
data.append('cw', cw);
|
||||||
data.append('pid', id);
|
data.append('pid', id);
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE + '/editcw' + token_param(token),
|
API_BASE + '/editcw',
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'User-Token': token,
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
},
|
},
|
||||||
@@ -135,10 +138,11 @@ export const API = {
|
|||||||
|
|
||||||
get_list: async (page, token) => {
|
get_list: async (page, token) => {
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE + '/getlist'
|
API_BASE + '/getlist?p=' + page
|
||||||
+ token_param(token)
|
+ (window.config.no_c_post ? '&no_cw' : ''),
|
||||||
+ '&p=' + page
|
{
|
||||||
+ (window.config.no_c_post ? '&no_cw' : '')
|
headers: {'User-Token': token},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
return handle_response(response);
|
return handle_response(response);
|
||||||
},
|
},
|
||||||
@@ -146,28 +150,35 @@ export const API = {
|
|||||||
get_search: async (page, keyword, token) => {
|
get_search: async (page, keyword, token) => {
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE +
|
API_BASE +
|
||||||
'/search' +
|
'/search?pagesize=' +
|
||||||
token_param(token) +
|
|
||||||
'&pagesize=' +
|
|
||||||
SEARCH_PAGESIZE +
|
SEARCH_PAGESIZE +
|
||||||
'&page=' +
|
'&page=' +
|
||||||
page +
|
page +
|
||||||
'&keywords=' +
|
'&keywords=' +
|
||||||
encodeURIComponent(keyword)
|
encodeURIComponent(keyword),
|
||||||
|
{
|
||||||
|
headers: {'User-Token': token},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
return handle_response(response);
|
return handle_response(response);
|
||||||
},
|
},
|
||||||
|
|
||||||
get_single: async (pid, token) => {
|
get_single: async (pid, token) => {
|
||||||
let response = await fetch(
|
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);
|
return handle_response(response);
|
||||||
},
|
},
|
||||||
|
|
||||||
get_attention: async (token) => {
|
get_attention: async (token) => {
|
||||||
let response = await fetch(
|
let response = await fetch(
|
||||||
API_BASE + '/getattention' + token_param(token),
|
API_BASE + '/getattention',
|
||||||
|
{
|
||||||
|
headers: {'User-Token': token},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
return handle_response(response);
|
return handle_response(response);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user