Skip to content
Merged
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
1 change: 1 addition & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module.exports = {
"flat-pages",
"pnpm",
"server",
"dmg",
],
],
"scope-case": [2, "always", ["lower-case", "kebab-case"]],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: latest
version: 9.9.0

- name: Restore Cache
uses: actions/setup-node@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: 9
version: 9.9.0

- name: Restore Cache
uses: actions/setup-node@v3
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/deploy-web-dev-cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: 9
version: 9.9.0

- name: Restore Cache
uses: actions/setup-node@v3
Expand All @@ -31,8 +31,12 @@ jobs:
- name: Install dependencies
env:
FLAT_AGREEMENT_URL: ${{ vars.FLAT_AGREEMENT_URL }}
FLAT_WEB_ALIYUN_PREFIX: ${{ vars.FLAT_WEB_ALIYUN_PREFIX }}
FLAT_WEB_SCENE_ID: ${{ vars.FLAT_WEB_SCENE_ID }}
run: |
echo "FLAT_AGREEMENT_URL=$FLAT_AGREEMENT_URL" >> config/CN/.env.development
echo "FLAT_WEB_ALIYUN_PREFIX=$FLAT_WEB_ALIYUN_PREFIX" >> config/CN/.env.development
echo "FLAT_WEB_SCENE_ID=$FLAT_WEB_SCENE_ID" >> config/CN/.env.development
node ./scripts/ci/remove-workspace-packages.js web
node ./scripts/ci/remove-package-scripts-hooks.js
# failure automatically retries 3 times
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/deploy-web-dev-sg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: 9
version: 9.9.0

- name: Restore Cache
uses: actions/setup-node@v3
Expand All @@ -29,7 +29,12 @@ jobs:
cache: "pnpm"

- name: Install dependencies
env:
FLAT_WEB_ALIYUN_PREFIX: ${{ vars.FLAT_WEB_ALIYUN_PREFIX }}
FLAT_WEB_SCENE_ID: ${{ vars.FLAT_WEB_SCENE_ID }}
run: |
echo "FLAT_WEB_ALIYUN_PREFIX=$FLAT_WEB_ALIYUN_PREFIX" >> config/CN/.env.development
echo "FLAT_WEB_SCENE_ID=$FLAT_WEB_SCENE_ID" >> config/CN/.env.development
node ./scripts/ci/remove-workspace-packages.js web
node ./scripts/ci/remove-package-scripts-hooks.js
# failure automatically retries 3 times
Expand Down
83 changes: 0 additions & 83 deletions .github/workflows/deploy-web-prod-cn.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/deploy-web-prod-sg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ jobs:
- name: Install PNPM
uses: pnpm/action-setup@v2
with:
version: 9
version: 9.9.0

- name: Install dependencies
env:
FLAT_WEB_ALIYUN_PREFIX: ${{ vars.FLAT_WEB_ALIYUN_PREFIX }}
FLAT_WEB_SCENE_ID: ${{ vars.FLAT_WEB_SCENE_ID }}
run: |
echo "FLAT_WEB_ALIYUN_PREFIX=$FLAT_WEB_ALIYUN_PREFIX" >> config/CN/.env.production
echo "FLAT_WEB_SCENE_ID=$FLAT_WEB_SCENE_ID" >> config/CN/.env.production
node ./scripts/ci/remove-workspace-packages.js web
node ./scripts/ci/remove-package-scripts-hooks.js
# failure automatically retries 3 times
Expand Down
2 changes: 2 additions & 0 deletions cspell.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
"courseware",
"PPTURL",
"aliyun",
"nypf9bgg", // aliyun captcha scene ID
"regx",
"bootup",
"btns",
Expand Down Expand Up @@ -79,6 +80,7 @@ module.exports = {
"unhide",
"nsis",
"respawn",
"UDZO", // electron-builder DMG format

// file type
"avif",
Expand Down
1 change: 1 addition & 0 deletions desktop/main-app/electron-builder/CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mas:
gatekeeperAssess: true

dmg:
format: UDZO
contents:
- { x: 130, y: 220 }
- { x: 410, y: 220, type: link, path: /Applications }
Expand Down
1 change: 1 addition & 0 deletions desktop/main-app/electron-builder/SG.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mac:
- arm64

dmg:
format: UDZO
contents:
- { x: 130, y: 220 }
- { x: 410, y: 220, type: link, path: /Applications }
Expand Down
13 changes: 13 additions & 0 deletions desktop/renderer-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<title>Flat</title>
<script>
const region = process.env.FLAT_REGION || "CN";
window.AliyunCaptchaConfig = {
// 必填,验证码示例所属地区,支持中国内地(cn)、新加坡(sgp)
region: region === "CN" ? region.toLowerCase() : "sgp",
// 必填,身份标。开通阿里云验证码2.0后,您可以在控制台概览页面的实例基本信息卡片区域,获取身份标
prefix: process.env.FLAT_WEB_ALIYUN_PREFIX,
};
</script>
<script
type="text/javascript"
src="https://o.alicdn.com/captcha-frontend/aliyunCaptcha/AliyunCaptcha.js"
></script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
81 changes: 81 additions & 0 deletions desktop/renderer-app/scripts/vite-plugin-html-env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { Plugin } from "vite";
import { configRegion } from "../../../scripts/utils/auto-choose-config";
import dotenvReal from "dotenv";
import { expand } from "dotenv-expand";
import fs from "fs";
import path from "path";

// 使用 require 导入 CommonJS 模块
const { configPath } = require("../../../scripts/constants");

/**
* 替换 HTML 中的 process.env.XXX 为实际值
* 因为 Vite 的 define 只替换模块代码,不替换 HTML 中的内联脚本
*/
export function injectHtmlEnv(): Plugin {
return {
name: "flat:html-env",
enforce: "pre",
transformIndexHtml: {
enforce: "pre",
transform(originalHTML) {
const envVars = getEnvVars();
let html = originalHTML;

// 替换所有 process.env.XXX 为实际值
for (const [key, value] of Object.entries(envVars)) {
const regex = new RegExp(`process\\.env\\.${key}`, "g");
html = html.replace(regex, JSON.stringify(value));
}

return {
html,
tags: [],
};
},
},
};
}

function getEnvVars(): Record<string, string> {
const envVars: Record<string, string> = {};
const mode = process.env.NODE_ENV === "production" ? "production" : "development";
const envDir = path.join(configPath, configRegion());
const envConfigContent = getEnvConfigContent(envDir, mode);

// 设置 FLAT_REGION
envVars.FLAT_REGION = configRegion();

if (envConfigContent) {
const parsed = dotenvReal.parse(envConfigContent);
expand({ parsed });
const env = { ...parsed };

// 从环境变量文件中读取的值
for (const [key, value] of Object.entries(env)) {
envVars[key] = value;
}
}

// 如果环境变量文件中有 FLAT_WEB_ALIYUN_PREFIX,使用它;否则使用默认值
if (!envVars.FLAT_WEB_ALIYUN_PREFIX) {
envVars.FLAT_WEB_ALIYUN_PREFIX = "195gxh";
}

return envVars;
}

function getEnvConfigContent(envDir: string, mode: string): string | null {
const configFileList = [
path.join(envDir, `.env.${mode}.local`),
path.join(envDir, `.env.${mode}`),
];

for (const filepath of configFileList) {
if (fs.existsSync(filepath) && fs.statSync(filepath).isFile()) {
return fs.readFileSync(filepath, "utf-8");
}
}

return null;
}
2 changes: 2 additions & 0 deletions desktop/renderer-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { dotenv } from "@netless/flat-vite-plugins/dotenv";
import { reactVirtualized } from "@netless/flat-vite-plugins/react-virtualized";
import { electron } from "./scripts/vite-plugin-electron";
import { injectGtag } from "./scripts/vite-plugin-html-gtag";
import { injectHtmlEnv } from "./scripts/vite-plugin-html-env";
import { rootNodeModules, rendererPath } from "../../scripts/constants";
import { autoChooseConfig } from "../../scripts/utils/auto-choose-config";

Expand All @@ -27,6 +28,7 @@ export default defineConfig((): UserConfig => {
const plugins: PluginOption[] = [
reactPlugin,
dotenv(autoChooseConfig()),
injectHtmlEnv(),
reactVirtualized(),
injectGtag(),
copy({
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "flat-monorepo",
"private": true,
"packageManager": "pnpm@9.9.0",
"scripts": {
"preinstall": "npx only-allow pnpm",
"prepare": "husky install",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface BindingPhonePanelProps {
sendBindingPhoneCode: (
countryCode: string,
phone: string,
captchaVerifyParam?: string,
) => Promise<BindingPhoneSendCodeResult>;
needRebindingPhone: (phone: string) => void;
}
Expand Down Expand Up @@ -111,6 +112,7 @@ export const BindingPhonePanel: React.FC<BindingPhonePanelProps> = ({
<Form.Item name="code" rules={[codeValidator]}>
<LoginSendCode
isAccountValidated={isAccountValidated}
isCaptcha={false}
sendVerificationCode={sendVerificationCode}
type={type}
onRebinding={onRebinding}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
.login-countdown {
user-select: none;
-webkit-user-select: none;
}

.send-verify-code-button {
margin: 0;
padding: 0;
border: none;
background: none;
width: 1px;
height: 1px;
opacity: 0;
overflow: hidden;
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
Loading
Loading