修复首次获取Cookie

This commit is contained in:
whyour 2021-03-18 19:58:52 +08:00
parent b1f6d1ce14
commit d238850b35
5 changed files with 159 additions and 73 deletions

View File

@ -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);

View File

@ -165,6 +165,7 @@ export default class CookieService {
let ucookie = this.getCookie(res);
let content = getFileContentByName(config.confFile);
const regx = /.*Cookie[0-9]{1}\=\"(.+?)\"/g;
if (content.match(regx)) {
const lastCookie = oldCookie || (content.match(regx) as any[]).pop();
const cookieRegx = /Cookie([0-9]+)\=.+?/.exec(lastCookie);
if (cookieRegx) {
@ -173,6 +174,11 @@ export default class CookieService {
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 };
} else {
return res.body;

View File

@ -1,4 +1,24 @@
.form {
@import '~antd/es/style/themes/default.less';
.container {
display: flex;
flex-direction: column;
height: 100vh;
overflow: auto;
background: @layout-body-background;
}
.lang {
width: 100%;
height: 40px;
line-height: 44px;
text-align: right;
:global(.ant-dropdown-trigger) {
margin-right: 24px;
}
}
.content {
position: absolute;
top: 45%;
left: 50%;
@ -6,53 +26,97 @@
width: 320px;
height: 320px;
padding: 36px;
box-shadow: 0 0 100px rgba(0, 0, 0, 0.08);
// box-shadow: 0 0 100px rgba(0, 0, 0, 0.08);
}
button {
width: 100%;
@media (min-width: @screen-md-min) {
.container {
background-image: url('https://gw.alipayobjects.com/zos/rmsportal/TVYTbAXWheQpRcWDaDMu.svg');
background-repeat: no-repeat;
background-position: center 110px;
background-size: 100%;
}
p {
color: rgb(204, 204, 204);
.content {
padding: 32px 0 24px;
}
}
.top {
text-align: center;
margin-top: 16px;
font-size: 12px;
}
.header {
height: 44px;
line-height: 44px;
a {
display: flex;
justify-content: space-between;
align-items: center;
justify-content: center;
}
}
.logo {
text-align: center;
cursor: pointer;
margin-bottom: 24px;
display: flex;
justify-content: center;
align-items: center;
height: 44px;
margin-right: 16px;
vertical-align: top;
}
img {
width: 40px;
margin-right: 8px;
.title {
position: relative;
top: 2px;
color: @heading-color;
font-weight: 600;
font-size: 33px;
font-family: Avenir, 'Helvetica Neue', Arial, Helvetica, sans-serif;
}
.desc {
margin-top: 12px;
margin-bottom: 40px;
color: @text-color-secondary;
font-size: @font-size-base;
}
.main {
width: 320px;
margin: 25px auto 0;
@media screen and (max-width: @screen-sm) {
width: 95%;
max-width: 320px;
}
span {
vertical-align: text-bottom;
:global {
.@{ant-prefix}-tabs-nav-list {
margin: auto;
font-size: 16px;
text-transform: uppercase;
display: inline-block;
font-weight: 700;
// color: @primary-color;
// .text-gradient();
}
}
.icon {
margin-left: 16px;
color: rgba(0, 0, 0, 0.2);
font-size: 24px;
vertical-align: middle;
cursor: pointer;
transition: color 0.3s;
&:hover {
color: @primary-color;
}
}
.other {
margin-top: 24px;
line-height: 22px;
text-align: left;
.register {
float: right;
}
}
.prefixIcon {
color: @primary-color;
font-size: @font-size-base;
}
}
.ant-spin-container,
.ant-spin-nested-loading {
height: 100%;
}
.footer {
position: absolute;
width: 100%;
bottom: 0;
}

View File

@ -1,9 +1,10 @@
import React, { Fragment, useEffect } from 'react';
import { Button, Row, Input, Form, notification } from 'antd';
import config from '@/utils/config';
import { history } from 'umi';
import { history, Link } from 'umi';
import styles from './index.less';
import { request } from '@/utils/http';
import logo from '@/assets/logo.png';
const FormItem = Form.Item;
@ -39,11 +40,17 @@ const Login = () => {
}, []);
return (
<Fragment>
<div className={styles.form}>
<div className={styles.logo}>
<span>{config.siteName}</span>
<div className={styles.container}>
<div className={styles.content}>
<div className={styles.top}>
<div className={styles.header}>
<Link to="/">
<img alt="logo" className={styles.logo} src={logo} />
<span className={styles.title}>{config.siteName}</span>
</Link>
</div>
</div>
<div className={styles.main}>
<Form onFinish={handleOk}>
<FormItem
name="username"
@ -60,13 +67,18 @@ const Login = () => {
<Input type="password" placeholder="密码" />
</FormItem>
<Row>
<Button type="primary" htmlType="submit">
Sign in
<Button
type="primary"
htmlType="submit"
style={{ width: '100%' }}
>
</Button>
</Row>
</Form>
</div>
</Fragment>
</div>
</div>
);
};

View File

@ -1,5 +1,5 @@
export default {
siteName: '京东羊毛脚本控制面板',
siteName: '脚本控制面板',
apiPrefix: '/api/',
authKey: 'token',