Skip to content

Commit

Permalink
Merge pull request #327 from PysioHub/main
Browse files Browse the repository at this point in the history
fix: #319 #322 #324 feat: add DeepSource
  • Loading branch information
pysio2007 authored Jan 15, 2025
2 parents b965258 + 6094371 commit b128031
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 20 deletions.
14 changes: 14 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version = 1

[[analyzers]]
name = "javascript"

[analyzers.meta]
plugins = ["vue"]
environment = [
"nodejs",
"vitest"
]

[[transformers]]
name = "standardjs"
43 changes: 27 additions & 16 deletions src/.vuepress/components/Wordle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,35 @@ export default {
},
methods: {
async fetchNewWord() {
try {
const response = await fetch(API_URL);
const [word] = await response.json();
this.answer = word.toLowerCase();
} catch (error) {
console.error('Failed to fetch word:', error);
this.answer = 'nowan'; // 降级方案
let isValid = false;
let word = '';
let attempts = 0;
const maxAttempts = 5; // 最大重试次数
while (!isValid && attempts < maxAttempts) {
try {
const response = await fetch(API_URL);
[word] = await response.json();
word = word.toLowerCase();
// 验证单词是否有效
const validationResponse = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`);
if (validationResponse.ok) {
isValid = true;
this.answer = word;
break;
}
} catch (error) {
console.error('Failed to fetch or validate word:', error);
}
attempts++;
}
if (!isValid) {
this.answer = 'nowan'; // 如果多次尝试后仍未获取到有效单词,使用降级方案
console.warn('Failed to get a valid word after multiple attempts');
}
},
// async loadValidWords() {
// try {
// const response = await fetch('/word-list.txt'); // 需要提供有效词列表
// const text = await response.text();
// this.validWords = new Set(text.split('\n').map(w => w.trim().toLowerCase()));
// } catch (error) {
// console.error('Failed to load valid words:', error);
// }
// },
async isValidWord(word) {
try {
const response = await fetch(`https://api.dictionaryapi.dev/api/v2/entries/en/${word}`);
Expand Down
27 changes: 24 additions & 3 deletions src/.vuepress/components/ipcheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,33 @@ export default {
}
// 获取第二个 IP 地址
const ipResponse2 = await fetch('https://myip.ipip.net/');
const ipResponse2 = await fetch('https://2024.ipchaxun.com/');
if (!ipResponse2.ok) {
throw new Error(`HTTP error! status: ${ipResponse2.status}`);
}
const ipText = await ipResponse2.text();
userIP2 = ipText.match(/当前 IP:(\d+\.\d+\.\d+\.\d+)/)[1];
const ipJson2 = await ipResponse2.json();
if (ipJson2.ret === 'ok') {
userIP2 = ipJson2.ip;
// 创建一个兼容的数据结构
const compatibleData = {
ip: ipJson2.ip,
country: ipJson2.data[0],
region: ipJson2.data[1],
city: ipJson2.data[2],
org: ipJson2.data[4],
data: {
ip: ipJson2.ip,
country: ipJson2.data[0],
region: ipJson2.data[1],
city: ipJson2.data[2],
org: ipJson2.data[4]
}
};
this.ipData2 = compatibleData;
} else {
throw new Error('Failed to get IP data from ipchaxun');
}
// 比较两个 IP 地址
if (userIP !== userIP2) {
Expand Down
2 changes: 1 addition & 1 deletion src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ projects:
# desc: 文章详细描述
# link: https://你的文章链接

- icon: friend
- icon: fa-solid fa-link
name: 友链
desc: 朋友们的网站些
link: /other/friends
Expand Down

0 comments on commit b128031

Please sign in to comment.