Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit 322b30a

Browse files
committed
Support automatically sync with upstream for forks
1 parent de5fbea commit 322b30a

File tree

7 files changed

+100
-15
lines changed

7 files changed

+100
-15
lines changed

Diff for: .github/workflows/deploy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- master
77

88
jobs:
9-
build:
9+
build_and_deploy:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout

Diff for: .github/workflows/docker.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ env:
1010
IMAGE: bclswl0827/chatgemini
1111

1212
jobs:
13-
build-and-push:
13+
build_docker_image:
1414
runs-on: ubuntu-latest
1515

1616
permissions:

Diff for: .github/workflows/sync.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Upstream Sync
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
schedule:
8+
- cron: "0 * * * *"
9+
workflow_dispatch:
10+
11+
jobs:
12+
sync_with_upstream:
13+
name: Sync with Upstream
14+
runs-on: ubuntu-latest
15+
if: ${{ github.event.repository.fork }}
16+
17+
steps:
18+
- name: Checkout target repo
19+
uses: actions/checkout@v3
20+
21+
- name: Sync Upstream
22+
uses: aormsby/[email protected]
23+
with:
24+
target_repo_token: ${{ secrets.GITHUB_TOKEN }}
25+
upstream_sync_repo: bclswl0827/ChatGemini
26+
upstream_sync_branch: master
27+
target_sync_branch: master
28+
test_mode: false
29+
30+
- name: Check for Failure
31+
if: failure()
32+
run: |
33+
echo "[Error] Due to a change in the workflow file of the upstream repository, GitHub has automatically suspended the scheduled automatic update. You need to manually sync your fork."
34+
exit 1

Diff for: README.md

+57
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,63 @@ $ docker run -d \
100100

101101
模板中仅留下了必填的 `REACT_APP_GEMINI_API_KEY` 变量, 在部署完成过后,若需修改或新增配置,请前往 Vercel 控制台,点击对应项目,再点击 `Settings` -> `Environment Variables` 进行修改。修改完成后,需要在 Vercel 控制台重新触发部署,以使新配置生效。
102102

103+
## 保持更新
104+
105+
### 若使用手动部署
106+
107+
若使用手动部署,可透过以下步骤保持更新:
108+
109+
1. 进入项目目录
110+
```bash
111+
$ cd ChatGemini
112+
```
113+
2. 拉取最新代码
114+
```bash
115+
$ git pull
116+
```
117+
3. 安装依赖
118+
```bash
119+
$ npm install
120+
```
121+
4. 重新构建项目
122+
```bash
123+
$ npm run build
124+
```
125+
5. 部署项目
126+
6. 重启服务
127+
128+
### 若使用 Docker 部署
129+
130+
若使用 Docker 部署,可透过以下步骤保持更新:
131+
132+
1. 删除旧容器
133+
```bash
134+
$ docker rm -f chatgemini
135+
```
136+
2. 拉取最新镜像
137+
```bash
138+
$ docker pull ghcr.io/bclswl0827/chatgemini
139+
```
140+
3. 运行新容器
141+
```bash
142+
$ docker run -d \
143+
--name chatgemini \
144+
--restart always \
145+
--publish 8080:8080 \
146+
--env REACT_APP_GEMINI_API_KEY="您的密钥" \
147+
ghcr.io/bclswl0827/chatgemini
148+
```
149+
150+
### 若使用 Vercel 部署
151+
152+
使用 Vercel 部署的项目,平台会在用户 GitHub 仓库创建一个新仓库,而不是 Fork 本仓库,因此无法正确检测更新。请按照下列步骤手动更新:
153+
154+
1. 删掉由 Vercel 创建的仓库
155+
2. 使用页面右上角的 Fork 按钮,Fork 本项目
156+
3. 在 Vercel 重新选择并部署 Fork 后的项目并完成部署
157+
158+
Fork 后的仓库,由于 GitHub 存在限制,需要手动去您 Fork 后仓库的 Actions 页面启用 Workflows,并启用 Upstream Sync Action,启用之后即可开启每小时定时自动同步上游代码。
159+
103160
## 应用配置
104161

105162
项目基础配置位于根目录下的 `.env` 文件中,手动部署时,请创建该文件并根据实际情况进行配置;若使用 Docker 方式部署,请在创建容器时传入 `--env` 参数进行配置。

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "chatgemini",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"homepage": ".",
55
"private": true,
66
"dependencies": {

Diff for: src/views/Chat.tsx

+4-10
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,6 @@ const Chat = (props: RouterComponentProps) => {
173173
...sessions[id].slice(index + 1),
174174
],
175175
};
176-
if (index - 1 in attachmentsURL) {
177-
setAttachmentsURL((prev) => {
178-
const { [index - 1]: _, ...rest } = prev;
179-
return rest;
180-
});
181-
}
182176
dispatch(updateSessions(_sessions));
183177
setChat(_sessions[id]);
184178
});
@@ -225,21 +219,21 @@ const Chat = (props: RouterComponentProps) => {
225219
return (
226220
<Container className="max-w-[calc(100%)] py-5 pl-3 mb-auto mx-1 md:mx-[4rem] lg:mx-[8rem]">
227221
<ImageView>
228-
{chat.map(({ role, parts, attachment }, index) => {
222+
{chat.map(({ role, parts, attachment, timestamp }, index) => {
229223
const { mimeType, data } = attachment ?? {
230224
mimeType: "",
231225
data: "",
232226
};
233227
let base64BlobURL = "";
234-
if (!!data.length && index in attachmentsURL) {
235-
base64BlobURL = attachmentsURL[index];
228+
if (!!data.length && timestamp in attachmentsURL) {
229+
base64BlobURL = attachmentsURL[timestamp];
236230
} else if (!!data.length) {
237231
base64BlobURL = getBase64BlobUrl(
238232
`data:${mimeType};base64,${data}`
239233
);
240234
setAttachmentsURL((prev) => ({
241235
...prev,
242-
[index]: base64BlobURL,
236+
[timestamp]: base64BlobURL,
243237
}));
244238
}
245239

0 commit comments

Comments
 (0)