refs #5464 fix: utiliza una sola cookie
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
e67a40714c
commit
b0d205c4da
|
@ -69,15 +69,15 @@ module.exports = Self => {
|
||||||
|
|
||||||
const result = response.headers.get('set-cookie');
|
const result = response.headers.get('set-cookie');
|
||||||
const [firtHeader] = result.split(' ');
|
const [firtHeader] = result.split(' ');
|
||||||
const firtCookie = firtHeader.substring(0, firtHeader.length - 1);
|
const cookie = firtHeader.substring(0, firtHeader.length - 1);
|
||||||
const body = await response.text();
|
const body = await response.text();
|
||||||
const dom = new jsdom.JSDOM(body);
|
const dom = new jsdom.JSDOM(body);
|
||||||
const token = dom.window.document.querySelector('[name="__CSRFToken__"]').value;
|
const token = dom.window.document.querySelector('[name="__CSRFToken__"]').value;
|
||||||
|
|
||||||
await login(token, firtCookie);
|
await login(token, cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(token, firtCookie) {
|
async function login(token, cookie) {
|
||||||
const data = {
|
const data = {
|
||||||
__CSRFToken__: token,
|
__CSRFToken__: token,
|
||||||
do: 'scplogin',
|
do: 'scplogin',
|
||||||
|
@ -90,21 +90,18 @@ module.exports = Self => {
|
||||||
body: new URLSearchParams(data),
|
body: new URLSearchParams(data),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
|
||||||
'Cookie': firtCookie
|
'Cookie': cookie
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(ostUri, params);
|
await fetch(ostUri, params);
|
||||||
const result = response.headers.get('set-cookie');
|
|
||||||
const [firtHeader] = result.split(' ');
|
|
||||||
const secondCookie = firtHeader.substring(0, firtHeader.length - 1);
|
|
||||||
|
|
||||||
await close(token, secondCookie);
|
await close(token, cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function close(token, secondCookie) {
|
async function close(token, cookie) {
|
||||||
for (const ticketId of ticketsId) {
|
for (const ticketId of ticketsId) {
|
||||||
try {
|
try {
|
||||||
const lock = await getLockCode(token, secondCookie, ticketId);
|
const lock = await getLockCode(token, cookie, ticketId);
|
||||||
if (!lock.code) {
|
if (!lock.code) {
|
||||||
let error = `Can't get lock code`;
|
let error = `Can't get lock code`;
|
||||||
if (lock.msg) error += `: ${lock.msg}`;
|
if (lock.msg) error += `: ${lock.msg}`;
|
||||||
|
@ -127,7 +124,7 @@ module.exports = Self => {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: form,
|
body: form,
|
||||||
headers: {
|
headers: {
|
||||||
'Cookie': secondCookie
|
'Cookie': cookie
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
await fetch(ostUri, params);
|
await fetch(ostUri, params);
|
||||||
|
@ -139,13 +136,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getLockCode(token, secondCookie, ticketId) {
|
async function getLockCode(token, cookie, ticketId) {
|
||||||
const ostUri = `${config.host}/ajax.php/lock/ticket/${ticketId}`;
|
const ostUri = `${config.host}/ajax.php/lock/ticket/${ticketId}`;
|
||||||
const params = {
|
const params = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRFToken': token,
|
'X-CSRFToken': token,
|
||||||
'Cookie': secondCookie
|
'Cookie': cookie
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const response = await fetch(ostUri, params);
|
const response = await fetch(ostUri, params);
|
||||||
|
|
Loading…
Reference in New Issue