Skip to content

Commit ccca32a

Browse files
committed
fic
1 parent 1810b71 commit ccca32a

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/pages/index.js

+33-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function Home() {
3838

3939

4040
useEffect(() => {
41+
// 底部ip获取
4142
fetch('https://forge.speedtest.cn/api/location/info')
4243
.then(res1 => res1.json())
4344
.then((res1) => {
@@ -48,19 +49,38 @@ export default function Home() {
4849
console.log(err);
4950
setIpinfo('获取国内的IP信息失败')
5051
})
51-
fetch('https://ip.1rmb.tk/ip')
52-
.then(res2 => res2.json())
53-
.then((res2) => {
54-
const info2 = `访问本站的IP: ${res2.ip} (${res2.addr} ${res2.info})`
55-
setIpinfov(info2)
56-
}).catch(err => {
57-
console.log(err);
58-
setIpinfov('获取访问本站的IP信息失败')
59-
})
52+
// fetch('https://ip.1rmb.tk/ip')
53+
// .then(res2 => res2.json())
54+
// .then((res2) => {
55+
// const info2 = `访问本站的IP: ${res2.ip} (${res2.addr} ${res2.info})`
56+
// setIpinfov(info2)
57+
// }).catch(err => {
58+
// console.log(err);
59+
// setIpinfov('获取访问本站的IP信息失败')
60+
// })
6061

6162
}, [])
6263

63-
64+
function formatDate(timestamp, format = 'YYYY-MM-DD HH:mm:ss') {
65+
const date = new Date(timestamp * 1000);
66+
67+
const replacements = {
68+
'YYYY': date.getFullYear(),
69+
'MM': addLeadingZero(date.getMonth() + 1),
70+
'DD': addLeadingZero(date.getDate()),
71+
'HH': addLeadingZero(date.getHours()),
72+
'mm': addLeadingZero(date.getMinutes()),
73+
'ss': addLeadingZero(date.getSeconds())
74+
};
75+
76+
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, match => {
77+
return replacements[match];
78+
});
79+
}
80+
81+
function addLeadingZero(num) {
82+
return num.toString().padStart(2, '0');
83+
}
6484

6585
const handleClick = async () => {
6686
setAlert(null)
@@ -121,6 +141,8 @@ export default function Home() {
121141
<p>额度总量:{balance.total_granted}</p>
122142
<p>已用额度:{balance.total_used}</p>
123143
<p>剩余额度:{balance.total_available}</p>
144+
<p>有效期起:{formatDate(balance.grants.data[0].effective_at)}</p>
145+
<p>有效期止:{formatDate(balance.grants.data[0].expires_at)}</p>
124146
</div>
125147
)}
126148

@@ -129,7 +151,7 @@ export default function Home() {
129151
<footer className={styles.footer}>
130152
<i><a className={styles.a} href="https://github.com/x-dr/chatgptProxyAPI">By @x-dr</a></i>
131153
<p >{ipinfo}</p>
132-
<p >{ipinfov}</p>
154+
{/* <p >{ipinfov}</p> */}
133155

134156
</footer>
135157

0 commit comments

Comments
 (0)