Skip to content

Commit

Permalink
feat(nuxt.config): support DATABASE_REPO
Browse files Browse the repository at this point in the history
  • Loading branch information
zjp-CN committed Nov 24, 2024
1 parent 0ad31dc commit ffa0ea9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions os-checks/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default defineNuxtConfig({
public: {
debug: process.env.DEBUG ? true : false,
docs_url: process.env.DOCS_URL,
database_repo: process.env.DATABASE_REPO,
}
}
})
9 changes: 7 additions & 2 deletions os-checks/utils/github-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ type Github = {
path: string
}

function defaultDatabaRepo(): string {
const runtimeConfig = useRuntimeConfig();
return runtimeConfig.public.database_repo || "os-checker/database";
}

// 当构建期间设置了 DEBUG 环境变量,则去 debug 分支而不是 main 分支拉取数据
function defaultBranch(): string {
const runtimeConfig = useRuntimeConfig();
Expand All @@ -12,9 +17,9 @@ function defaultBranch(): string {

// https://raw.githubusercontent.com/os-checker/os-checker.github.io/main/os-checks/public/test_raw_reports.json
export default function <T>(github: Github): Promise<T> {
const repo = github.repo || "database";
const repo = github.repo || defaultDatabaRepo();
const branch = github.branch || defaultBranch();
const url = `https://raw.githubusercontent.com/os-checker/${repo}/${branch}/${github.path}`;
const url = `https://raw.githubusercontent.com/${repo}/${branch}/${github.path}`;
return $fetch(url, {
// 构造简单请求来解决跨域问题(同时 github raw 资源支持所有源)
"headers": { "content-type": "text/plain" },
Expand Down

0 comments on commit ffa0ea9

Please sign in to comment.