Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added functionality to retrieve and save GitHub token (#812) #837

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@
"echarts": "^5.3.0",
"element-ready": "^6.2.1",
"github-url-detection": "^8.1.0",
"i18next": "^23.11.5",
"i18next-browser-languagedetector": "^8.0.0",
"i18next-http-backend": "^2.5.2",
"jquery": "^3.6.0",
"lodash-es": "^4.17.21",
"moment": "^2.30.1",
"react": "^17.0.2",
"react-chat-widget": "^3.1.4",
"react-dom": "^17.0.2",
"react-hot-loader": "^4.13.0",
"react-i18next": "^14.1.2",
"react-modal": "3.15.1",
"strip-indent": "^4.0.0"
},
Expand Down
35 changes: 35 additions & 0 deletions src/api/githubApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// src/api/githubApi.ts
let githubToken = '';

export const saveToken = (token: string) => {
githubToken = token;
localStorage.setItem('github_token', token); // 保存 token 到 localStorage
};

export const getToken = () => {
if (!githubToken) {
githubToken = localStorage.getItem('github_token') || '';
}
return githubToken;
};

export const githubRequest = async (endpoint: string, options: RequestInit = {}) => {
const token = getToken();
if (!token) {
throw new Error('GitHub Token 未设置');
}

const response = await fetch(`https://api.github.com${endpoint}`, {
...options,
headers: {
...options.headers,
Authorization: `Bearer ${token}`,
},
});

if (!response.ok) {
throw new Error(`GitHub 请求失败: ${response.statusText}`);
}

return response.json();
};
12 changes: 12 additions & 0 deletions src/helpers/get-message-by-locale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import messages_en from '../locales/en/messages.json';
import messages_zh_CN from '../locales/zh_CN/messages.json';

const messages_locale = {
en: messages_en,
zh_CN: messages_zh_CN,
};

export default function getMessageByLocale(key: string, locale: string) {
// @ts-ignore
return messages_locale[locale][key]['message'];
}
36 changes: 0 additions & 36 deletions src/helpers/i18n.ts

This file was deleted.

Loading
Loading