diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..c30f4437 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,4 @@ +FROM nginx:1.25 + +COPY build/web/ /data/webroot +COPY nginx.conf /etc/nginx/conf.d/default.conf \ No newline at end of file diff --git a/Makefile b/Makefile index cbd6d3ed..850c2d67 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,16 @@ build-web: rm -fr build/web/fonts/ && mkdir build/web/fonts cp -r scripts/s build/web/fonts/s +build-web-samehost: + flutter build web --web-renderer canvaskit --release --dart-define=API_SERVER_URL=/ + cd scripts && go run main.go ../build/web/main.dart.js && cd .. + rm -fr build/web/fonts/ && mkdir build/web/fonts + cp -r scripts/s build/web/fonts/s + deploy-web: build-web cd build && tar -zcvf web.tar.gz web scp build/web.tar.gz huawei-1:/data/webroot ssh huawei-1 "cd /data/webroot && tar -zxvf web.tar.gz && rm -rf web.tar.gz app && mv web app" rm -fr build/web.tar.gz -.PHONY: run build-android build-macos ipa +.PHONY: run build-android build-macos ipa build-web-samehost build-web deploy-web diff --git a/docker-build.sh b/docker-build.sh new file mode 100755 index 00000000..3b553c5e --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +VERSION=1.0.6 +VERSION_DATE=202310091100 + +rm -fr build/web + +flutter build web --web-renderer canvaskit --release --dart-define=API_SERVER_URL=/ +cd scripts && go run main.go ../build/web/main.dart.js && cd .. +rm -fr build/web/fonts/ && mkdir build/web/fonts +cp -r scripts/s build/web/fonts/s + +docker build -t mylxsw/aidea-web:$VERSION . +docker tag mylxsw/aidea-web:$VERSION mylxsw/aidea-web:$VERSION_DATE +docker tag mylxsw/aidea-web:$VERSION mylxsw/aidea-web:latest + +docker push mylxsw/aidea-web:$VERSION +docker push mylxsw/aidea-web:$VERSION_DATE +docker push mylxsw/aidea-web:latest + diff --git a/lib/helper/constant.dart b/lib/helper/constant.dart index aeb428f5..9ab6997c 100644 --- a/lib/helper/constant.dart +++ b/lib/helper/constant.dart @@ -8,10 +8,6 @@ const databaseVersion = 25; const maxRoomNumForNonVIP = 50; const coinSign = '个'; -// API 服务器地址 -const apiServerURL = 'https://ai-api.aicode.cc'; -// const apiServerURL = 'http://localhost'; - const settingAPIServerToken = 'api-token'; const settingUserInfo = 'user-info'; const settingUsingGuestMode = 'using-guest-mode'; diff --git a/lib/helper/env.dart b/lib/helper/env.dart new file mode 100644 index 00000000..ab9ece93 --- /dev/null +++ b/lib/helper/env.dart @@ -0,0 +1,14 @@ +/// API 服务器地址 +String get apiServerURL { + var url = const String.fromEnvironment( + 'API_SERVER_URL', + defaultValue: 'https://ai-api.aicode.cc', + ); + + // 当配置的 URL 为 / 时,自动替换为空,用于 Web 端 + if (url == '/') { + return ''; + } + + return url; +} diff --git a/lib/helper/http.dart b/lib/helper/http.dart index 5a1d5294..6c6a66a1 100644 --- a/lib/helper/http.dart +++ b/lib/helper/http.dart @@ -1,4 +1,4 @@ -import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/logger.dart'; import 'package:askaide/helper/platform.dart'; import 'package:dio/dio.dart'; diff --git a/lib/page/setting_screen.dart b/lib/page/setting_screen.dart index ee171e1f..48aa28f7 100644 --- a/lib/page/setting_screen.dart +++ b/lib/page/setting_screen.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:askaide/bloc/account_bloc.dart'; import 'package:askaide/helper/ability.dart'; import 'package:askaide/helper/cache.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/helper.dart'; import 'package:askaide/helper/http.dart'; import 'package:askaide/helper/logger.dart'; diff --git a/lib/page/signin_screen.dart b/lib/page/signin_screen.dart index 981d0569..60fcd176 100644 --- a/lib/page/signin_screen.dart +++ b/lib/page/signin_screen.dart @@ -4,6 +4,7 @@ import 'package:animated_text_kit/animated_text_kit.dart'; import 'package:askaide/bloc/version_bloc.dart'; import 'package:askaide/helper/ability.dart'; import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/helper.dart'; import 'package:askaide/helper/logger.dart'; import 'package:askaide/helper/platform.dart'; diff --git a/lib/page/signup_screen.dart b/lib/page/signup_screen.dart index eb14aebe..23396423 100644 --- a/lib/page/signup_screen.dart +++ b/lib/page/signup_screen.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:animated_text_kit/animated_text_kit.dart'; import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/helper.dart'; import 'package:askaide/lang/lang.dart'; import 'package:askaide/page/component/background_container.dart'; diff --git a/lib/repo/api_server.dart b/lib/repo/api_server.dart index 92d0f2c1..009f9aa1 100644 --- a/lib/repo/api_server.dart +++ b/lib/repo/api_server.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/error.dart'; import 'package:askaide/helper/http.dart'; import 'package:askaide/helper/logger.dart'; diff --git a/lib/repo/deepai_repo.dart b/lib/repo/deepai_repo.dart index 0af3d6c2..8439e9fa 100644 --- a/lib/repo/deepai_repo.dart +++ b/lib/repo/deepai_repo.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/platform.dart'; import 'package:askaide/repo/data/settings_data.dart'; import 'package:http/http.dart' as http; diff --git a/lib/repo/openai_repo.dart b/lib/repo/openai_repo.dart index 0b59bad5..ea908f1b 100644 --- a/lib/repo/openai_repo.dart +++ b/lib/repo/openai_repo.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'dart:io'; import 'package:askaide/helper/ability.dart'; import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/platform.dart'; import 'package:askaide/repo/model/model.dart' as mm; import 'package:dart_openai/openai.dart'; diff --git a/lib/repo/stabilityai_repo.dart b/lib/repo/stabilityai_repo.dart index 6fe2aa0d..dc637569 100644 --- a/lib/repo/stabilityai_repo.dart +++ b/lib/repo/stabilityai_repo.dart @@ -1,5 +1,6 @@ import 'dart:convert'; import 'package:askaide/helper/constant.dart'; +import 'package:askaide/helper/env.dart'; import 'package:askaide/helper/platform.dart'; import 'package:askaide/repo/data/settings_data.dart'; import 'package:http/http.dart' as http; diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 00000000..33687536 --- /dev/null +++ b/nginx.conf @@ -0,0 +1,15 @@ +server { + listen 80; + + gzip on; + gzip_static on; + gzip_vary on; + gzip_types text/plain application/x-javascript text/css application/xml text/xml application/javascript; + + root /data/webroot; + + location / { + index index.html; + try_files $uri $uri/ =404; + } +} \ No newline at end of file