This commit is contained in:
Sakurasan
2025-04-16 23:39:56 +08:00
parent 2360e7d2bf
commit d4cbc27a77
6 changed files with 80 additions and 27 deletions

View File

@@ -2,7 +2,9 @@ package main
import ( import (
"context" "context"
"embed"
"fmt" "fmt"
"io/fs"
"log" "log"
"net/http" "net/http"
"opencatd-open/middleware" "opencatd-open/middleware"
@@ -18,6 +20,9 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
//go:embed dist/*
var web embed.FS
func main() { func main() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
var wg sync.WaitGroup var wg sync.WaitGroup
@@ -53,6 +58,7 @@ func main() {
r := gin.Default() r := gin.Default()
r.Use(middleware.CORS()) r.Use(middleware.CORS())
teamGroup := r.Group("/1") teamGroup := r.Group("/1")
teamGroup.Use(team.AuthMiddleware()) teamGroup.Use(team.AuthMiddleware())
{ {
@@ -122,13 +128,24 @@ func main() {
} }
v1 := r.Group("/v1") v1 := r.Group("/v1")
v1.Use(middleware.AuthLLM(store.DB)) v1.Use(middleware.AuthLLM(db))
{ {
// v1.POST("/v2/*proxypath", router.HandleProxy) // v1.POST("/v2/*proxypath", router.HandleProxy)
v1.POST("/v1/*proxypath", proxy.HandleProxy) v1.POST("/v1/*proxypath", proxy.HandleProxy)
// v1.GET("/models", dashboard.HandleModels) // v1.GET("/models", dashboard.HandleModels)
} }
idxFS, err := fs.Sub(web, "dist")
if err != nil {
panic(err)
}
r.GET("/", gin.WrapH(http.FileServer(http.FS(idxFS))))
assetsFS, err := fs.Sub(web, "dist/assets")
if err != nil {
panic(err)
}
r.GET("/assets/*filepath", gin.WrapH(http.StripPrefix("/assets/", http.FileServer(http.FS(assetsFS)))))
srv := &http.Server{ srv := &http.Server{
Addr: ":8080", Addr: ":8080",
Handler: r, Handler: r,

View File

@@ -1,14 +1,15 @@
FROM node:20-alpine AS frontend FROM node:20-alpine AS frontend
WORKDIR /frontend-build WORKDIR /frontend-build
COPY ./web/ . COPY ./frontend .
RUN npm install && npm run build && rm -rf node_modules
FROM golang:1.23-alpine as builder RUN npm config set registry https://registry.npmmirror.com && npm install -g pnpm --registry=https://registry.npmmirror.com && pnpm i && pnpm build
FROM golang:1.23-alpine as backend
LABEL anther="github.com/Sakurasan" LABEL anther="github.com/Sakurasan"
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk --no-cache add make cmake upx RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk --no-cache add make cmake upx
WORKDIR /build WORKDIR /build
COPY --from=frontend /frontend-build/dist /build/dist COPY . .
COPY . /build COPY --from=frontend /frontend-build/dist /build/cmd/openteam/dist
ENV GO111MODULE=on ENV GO111MODULE=on
# ENV GOPROXY=https://goproxy.cn,direct # ENV GOPROXY=https://goproxy.cn,direct
CMD [ "go mod tidy","go mod download" ] CMD [ "go mod tidy","go mod download" ]
@@ -20,8 +21,8 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
&& echo "Asia/Shanghai" > /etc/timezone && echo "Asia/Shanghai" > /etc/timezone
# RUN apk update && apk --no-cache add openssl libgcc libstdc++ binutils # RUN apk update && apk --no-cache add openssl libgcc libstdc++ binutils
WORKDIR /app WORKDIR /app
COPY --from=builder /build/bin/opencatd /app/opencatd COPY --from=backend /build/bin/openteam /app/openteam
ENV GIN_MODE=release ENV GIN_MODE=release
ENV PATH=$PATH:/app ENV PATH=$PATH:/app
EXPOSE 80 EXPOSE 80
ENTRYPOINT ["/app/opencatd"] ENTRYPOINT ["/app/openteam"]

View File

@@ -27,6 +27,6 @@
"pinia": "^2.3.1", "pinia": "^2.3.1",
"postcss": "^8.5.3", "postcss": "^8.5.3",
"tailwindcss": "^3.4.17", "tailwindcss": "^3.4.17",
"vite": "^6.2.6" "vite": "^6.3.0"
} }
} }

View File

@@ -13,7 +13,7 @@ importers:
version: 13.1.0 version: 13.1.0
'@vitejs/plugin-basic-ssl': '@vitejs/plugin-basic-ssl':
specifier: ^2.0.0 specifier: ^2.0.0
version: 2.0.0(vite@6.2.6(jiti@1.21.7)(yaml@2.7.1)) version: 2.0.0(vite@6.3.0(jiti@1.21.7)(yaml@2.7.1))
axios: axios:
specifier: ^1.8.4 specifier: ^1.8.4
version: 1.8.4 version: 1.8.4
@@ -41,7 +41,7 @@ importers:
version: 4.3.0(vue@3.5.13) version: 4.3.0(vue@3.5.13)
'@vitejs/plugin-vue': '@vitejs/plugin-vue':
specifier: ^5.2.3 specifier: ^5.2.3
version: 5.2.3(vite@6.2.6(jiti@1.21.7)(yaml@2.7.1))(vue@3.5.13) version: 5.2.3(vite@6.3.0(jiti@1.21.7)(yaml@2.7.1))(vue@3.5.13)
autoprefixer: autoprefixer:
specifier: ^10.4.21 specifier: ^10.4.21
version: 10.4.21(postcss@8.5.3) version: 10.4.21(postcss@8.5.3)
@@ -58,8 +58,8 @@ importers:
specifier: ^3.4.17 specifier: ^3.4.17
version: 3.4.17 version: 3.4.17
vite: vite:
specifier: ^6.2.6 specifier: ^6.3.0
version: 6.2.6(jiti@1.21.7)(yaml@2.7.1) version: 6.3.0(jiti@1.21.7)(yaml@2.7.1)
packages: packages:
@@ -680,6 +680,14 @@ packages:
fastq@1.19.1: fastq@1.19.1:
resolution: {integrity: sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==} resolution: {integrity: sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==}
fdir@6.4.3:
resolution: {integrity: sha512-PMXmW2y1hDDfTSRc9gaXIuCCRpuoz3Kaz8cUelp3smouvfT632ozg2vrT6lJsHKKOF59YLbOGfAWGUcKEfRMQw==}
peerDependencies:
picomatch: ^3 || ^4
peerDependenciesMeta:
picomatch:
optional: true
fill-range@7.1.1: fill-range@7.1.1:
resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==} resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==}
engines: {node: '>=8'} engines: {node: '>=8'}
@@ -895,6 +903,10 @@ packages:
resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==} resolution: {integrity: sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==}
engines: {node: '>=8.6'} engines: {node: '>=8.6'}
picomatch@4.0.2:
resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==}
engines: {node: '>=12'}
pify@2.3.0: pify@2.3.0:
resolution: {integrity: sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==} resolution: {integrity: sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@@ -1036,6 +1048,10 @@ packages:
thenify@3.3.1: thenify@3.3.1:
resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==} resolution: {integrity: sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==}
tinyglobby@0.2.12:
resolution: {integrity: sha512-qkf4trmKSIiMTs/E63cxH+ojC2unam7rJ0WrauAzpT3ECNTxGRMlaXxVbfxMUC/w0LaYk6jQ4y/nGR9uBO3tww==}
engines: {node: '>=12.0.0'}
to-regex-range@5.0.1: to-regex-range@5.0.1:
resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==} resolution: {integrity: sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==}
engines: {node: '>=8.0'} engines: {node: '>=8.0'}
@@ -1052,8 +1068,8 @@ packages:
util-deprecate@1.0.2: util-deprecate@1.0.2:
resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==}
vite@6.2.6: vite@6.3.0:
resolution: {integrity: sha512-9xpjNl3kR4rVDZgPNdTL0/c6ao4km69a/2ihNQbcANz8RuCOK3hQBmLSJf3bRKVQjVMda+YvizNE8AwvogcPbw==} resolution: {integrity: sha512-9aC0n4pr6hIbvi1YOpFjwQ+QOTGssvbJKoeYkuHHGWwlXfdxQlI8L2qNMo9awEEcCPSiS+5mJZk5jH1PAqoDeQ==}
engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0} engines: {node: ^18.0.0 || ^20.0.0 || >=22.0.0}
hasBin: true hasBin: true
peerDependencies: peerDependencies:
@@ -1373,13 +1389,13 @@ snapshots:
'@types/web-bluetooth@0.0.16': {} '@types/web-bluetooth@0.0.16': {}
'@vitejs/plugin-basic-ssl@2.0.0(vite@6.2.6(jiti@1.21.7)(yaml@2.7.1))': '@vitejs/plugin-basic-ssl@2.0.0(vite@6.3.0(jiti@1.21.7)(yaml@2.7.1))':
dependencies: dependencies:
vite: 6.2.6(jiti@1.21.7)(yaml@2.7.1) vite: 6.3.0(jiti@1.21.7)(yaml@2.7.1)
'@vitejs/plugin-vue@5.2.3(vite@6.2.6(jiti@1.21.7)(yaml@2.7.1))(vue@3.5.13)': '@vitejs/plugin-vue@5.2.3(vite@6.3.0(jiti@1.21.7)(yaml@2.7.1))(vue@3.5.13)':
dependencies: dependencies:
vite: 6.2.6(jiti@1.21.7)(yaml@2.7.1) vite: 6.3.0(jiti@1.21.7)(yaml@2.7.1)
vue: 3.5.13 vue: 3.5.13
'@vue/compiler-core@3.5.13': '@vue/compiler-core@3.5.13':
@@ -1684,6 +1700,10 @@ snapshots:
dependencies: dependencies:
reusify: 1.1.0 reusify: 1.1.0
fdir@6.4.3(picomatch@4.0.2):
optionalDependencies:
picomatch: 4.0.2
fill-range@7.1.1: fill-range@7.1.1:
dependencies: dependencies:
to-regex-range: 5.0.1 to-regex-range: 5.0.1
@@ -1866,6 +1886,8 @@ snapshots:
picomatch@2.3.1: {} picomatch@2.3.1: {}
picomatch@4.0.2: {}
pify@2.3.0: {} pify@2.3.0: {}
pinia@2.3.1(vue@3.5.13): pinia@2.3.1(vue@3.5.13):
@@ -2042,6 +2064,11 @@ snapshots:
dependencies: dependencies:
any-promise: 1.3.0 any-promise: 1.3.0
tinyglobby@0.2.12:
dependencies:
fdir: 6.4.3(picomatch@4.0.2)
picomatch: 4.0.2
to-regex-range@5.0.1: to-regex-range@5.0.1:
dependencies: dependencies:
is-number: 7.0.0 is-number: 7.0.0
@@ -2056,11 +2083,14 @@ snapshots:
util-deprecate@1.0.2: {} util-deprecate@1.0.2: {}
vite@6.2.6(jiti@1.21.7)(yaml@2.7.1): vite@6.3.0(jiti@1.21.7)(yaml@2.7.1):
dependencies: dependencies:
esbuild: 0.25.2 esbuild: 0.25.2
fdir: 6.4.3(picomatch@4.0.2)
picomatch: 4.0.2
postcss: 8.5.3 postcss: 8.5.3
rollup: 4.40.0 rollup: 4.40.0
tinyglobby: 0.2.12
optionalDependencies: optionalDependencies:
fsevents: 2.3.3 fsevents: 2.3.3
jiti: 1.21.7 jiti: 1.21.7

View File

@@ -79,9 +79,9 @@ const handleRegister = async () => {
password: password.value password: password.value
}) })
if (res.status === 200) { if (res.status === 200) {
setToast(res.data?.msg || '注册成功', 'success'); setToast(res.data?.msg || '注册', 'success');
setTimeout(() => { setTimeout(() => {
router.push('/sign_in'); router.push('/login');
}, 100); }, 100);
error.value = '' error.value = ''
} }

View File

@@ -18,23 +18,28 @@ LDFlags=" \
.PHONY: web .PHONY: web
# web # web
web: web:
cd web && npm install && npm run build && mv dist .. cd frontend && npm install -g pnpm && pnpm build && mv dist ../cmd/openteam/
.PHONY: build .PHONY: build
# build # build
build: build:
# mkdir -p bin/ && go build -ldflags $(LDFlags) -o ./bin/ ./... # mkdir -p bin/ && go build -ldflags $(LDFlags) -o ./bin/ ./...
rm -rf bin rm -rf bin
mkdir -p bin/ && go build -ldflags "-s -w" -o ./bin/opencatd opencat.go mkdir -p bin/ && go build -ldflags "-s -w" -o ./bin/openteam ./cmd/openteam/
upx -9 bin/opencatd upx -9 bin/openteam
.PHONY:image
# build docker images
image:
docker build -t mirrors2/opencatd-open:latest -f deploy/docker/Dockerfile . --push
.PHONY:docker .PHONY:docker
# build docker images # build docker images
docker: docker:
docker run --privileged --rm tonistiigi/binfmt --install all docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx create --use --name xbuilder --driver docker-container # docker buildx create --use --name xbuilder --driver docker-container
docker buildx inspect xbuilder --bootstrap docker buildx inspect xbuilder --bootstrap
docker buildx build --platform linux/amd64,linux/arm64 -t mirrors2/opencatd:latest -f docker/Dockerfile . --push docker buildx build --platform linux/amd64,linux/arm64 -t mirrors2/opencatd-open:latest -f deploy/docker/Dockerfile . --push
.PHONY: clean .PHONY: clean
# clean # clean