mirror of
https://github.com/whyour/qinglong.git
synced 2026-07-01 04:40:38 +08:00
修复首次获取Cookie
This commit is contained in:
@@ -5,6 +5,7 @@ import { Logger } from 'winston';
|
||||
import config from '../config';
|
||||
import * as fs from 'fs';
|
||||
import { celebrate, Joi } from 'celebrate';
|
||||
import { execSync } from 'child_process';
|
||||
const route = Router();
|
||||
|
||||
export default (app: Router) => {
|
||||
@@ -57,6 +58,9 @@ export default (app: Router) => {
|
||||
const { name, content } = req.body;
|
||||
const path = (config.fileMap as any)[name];
|
||||
fs.writeFileSync(path, content);
|
||||
if (name === 'crontab.list') {
|
||||
execSync(`crontab ${path}`);
|
||||
}
|
||||
res.send({ code: 200, msg: '保存成功' });
|
||||
} catch (e) {
|
||||
logger.error('🔥 error: %o', e);
|
||||
|
||||
+12
-6
@@ -165,12 +165,18 @@ export default class CookieService {
|
||||
let ucookie = this.getCookie(res);
|
||||
let content = getFileContentByName(config.confFile);
|
||||
const regx = /.*Cookie[0-9]{1}\=\"(.+?)\"/g;
|
||||
const lastCookie = oldCookie || (content.match(regx) as any[]).pop();
|
||||
const cookieRegx = /Cookie([0-9]+)\=.+?/.exec(lastCookie);
|
||||
if (cookieRegx) {
|
||||
const num = parseInt(cookieRegx[1]) + 1;
|
||||
const newCookie = `${lastCookie}\nCookie${num}="${ucookie}"`;
|
||||
const result = content.replace(lastCookie, newCookie);
|
||||
if (content.match(regx)) {
|
||||
const lastCookie = oldCookie || (content.match(regx) as any[]).pop();
|
||||
const cookieRegx = /Cookie([0-9]+)\=.+?/.exec(lastCookie);
|
||||
if (cookieRegx) {
|
||||
const num = parseInt(cookieRegx[1]) + 1;
|
||||
const newCookie = `${lastCookie}\nCookie${num}="${ucookie}"`;
|
||||
const result = content.replace(lastCookie, newCookie);
|
||||
fs.writeFileSync(config.confFile, result);
|
||||
}
|
||||
} else {
|
||||
const newCookie = `Cookie1="${ucookie}"`;
|
||||
const result = content.replace(`Cookie1=""`, newCookie);
|
||||
fs.writeFileSync(config.confFile, result);
|
||||
}
|
||||
return { cookie: ucookie };
|
||||
|
||||
Reference in New Issue
Block a user