Skip to content

Commit 4134e74

Browse files
committed
feat: 嵌入vsix
1 parent 315b7f0 commit 4134e74

6 files changed

Lines changed: 18 additions & 17 deletions

File tree

.github/workflows/backend-ci-cd.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ jobs:
9999
GIT_COMMIT=$(git rev-parse HEAD)
100100
echo "GIT_COMMIT=${GIT_COMMIT}" >> $GITHUB_OUTPUT
101101
102+
- name: Get VSIX
103+
run: |
104+
wget -O assets/vsix/monkeycode-${{ steps.get_version.outputs.VERSION }}.vsix https://release.baizhi.cloud/monkeycode/vsixs/monkeycode-${{ steps.get_version.outputs.VERSION }}.vsix
105+
102106
- name: Set up QEMU
103107
uses: docker/setup-qemu-action@v3
104108

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
backend/assets

backend/build/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FROM alpine:3.21 as binary
2626
WORKDIR /app
2727

2828
ADD migration ./migration
29+
ADD assets ./assets
2930

3031
COPY --from=builder /out/main /app/main
3132

backend/cmd/server/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ func main() {
5050
panic(err)
5151
}
5252

53-
s.euse.SyncLatest()
54-
5553
svc := service.NewService(service.WithPprof())
5654
svc.Add(s)
5755
if err := svc.Run(); err != nil {

backend/internal/openai/handler/v1/v1.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"log/slog"
66
"net/http"
7+
"strings"
78

89
"github.com/labstack/echo/v4"
910

@@ -13,6 +14,7 @@ import (
1314
"github.com/chaitin/MonkeyCode/backend/domain"
1415
"github.com/chaitin/MonkeyCode/backend/internal/middleware"
1516
"github.com/chaitin/MonkeyCode/backend/internal/proxy"
17+
"github.com/chaitin/MonkeyCode/backend/pkg/version"
1618
)
1719

1820
type V1Handler struct {
@@ -72,18 +74,15 @@ func BadRequest(c *web.Context, msg string) error {
7274
}
7375

7476
func (h *V1Handler) Version(c *web.Context) error {
75-
v, err := h.euse.Latest(c.Request().Context())
76-
if err != nil {
77-
return err
78-
}
77+
v := strings.Trim(version.Version, "v")
7978

8079
s, err := h.uuse.GetSetting(c.Request().Context())
8180
if err != nil {
8281
return err
8382
}
8483
return c.JSON(http.StatusOK, domain.VersionInfo{
85-
Version: v.Version,
86-
URL: fmt.Sprintf("%s/api/v1/static/vsix/%s", h.config.GetBaseURL(c.Request(), s), v.Version),
84+
Version: v,
85+
URL: fmt.Sprintf("%s/api/v1/static/vsix/%s", h.config.GetBaseURL(c.Request(), s), v),
8786
})
8887
}
8988

backend/internal/user/handler/v1/user.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"log/slog"
99
"net/http"
10+
"strings"
1011
"sync"
1112
"time"
1213

@@ -19,6 +20,7 @@ import (
1920
"github.com/chaitin/MonkeyCode/backend/errcode"
2021
"github.com/chaitin/MonkeyCode/backend/internal/middleware"
2122
"github.com/chaitin/MonkeyCode/backend/pkg/session"
23+
"github.com/chaitin/MonkeyCode/backend/pkg/version"
2224
"github.com/chaitin/MonkeyCode/backend/pkg/vsix"
2325
)
2426

@@ -173,26 +175,22 @@ func (h *UserHandler) VSIXDownload(c *web.Context) error {
173175
return c.String(http.StatusTooManyRequests, "Too Many Requests")
174176
}
175177

176-
v, err := h.euse.GetByVersion(c.Request().Context(), c.Param("version"))
177-
if err != nil {
178-
return err
179-
}
180-
181178
s, err := h.usecase.GetSetting(c.Request().Context())
182179
if err != nil {
183180
return err
184181
}
185182

186183
host := c.Request().Host
187184
h.logger.With("url", c.Request().URL).With("header", c.Request().Header).With("host", host).DebugContext(c.Request().Context(), "vsix download")
188-
cacheKey := h.generateCacheKey(v.Version, h.cfg.GetBaseURL(c.Request(), s))
185+
cacheKey := h.generateCacheKey(version.Version, h.cfg.GetBaseURL(c.Request(), s))
186+
version := strings.Trim(version.Version, "v")
189187

190188
h.cacheMu.RLock()
191189
if entry, exists := h.vsixCache[cacheKey]; exists {
192190
if time.Since(entry.createdAt) < time.Hour {
193191
h.cacheMu.RUnlock()
194192

195-
disposition := fmt.Sprintf("attachment; filename=monkeycode-%s.vsix", v.Version)
193+
disposition := fmt.Sprintf("attachment; filename=monkeycode-%s.vsix", version)
196194
c.Response().Header().Set("Content-Type", "application/octet-stream")
197195
c.Response().Header().Set("Content-Disposition", disposition)
198196
c.Response().Header().Set("Content-Length", fmt.Sprintf("%d", len(entry.data)))
@@ -204,7 +202,7 @@ func (h *UserHandler) VSIXDownload(c *web.Context) error {
204202
h.cacheMu.RUnlock()
205203

206204
var buf bytes.Buffer
207-
if err := vsix.ChangeVsixEndpoint(v.Path, "extension/package.json", h.cfg.GetBaseURL(c.Request(), s), &buf); err != nil {
205+
if err := vsix.ChangeVsixEndpoint(fmt.Sprintf("/app/assets/vsix/monkeycode-%s.vsix", version), "extension/package.json", h.cfg.GetBaseURL(c.Request(), s), &buf); err != nil {
208206
return err
209207
}
210208

@@ -218,7 +216,7 @@ func (h *UserHandler) VSIXDownload(c *web.Context) error {
218216

219217
go h.cleanExpiredCache()
220218

221-
disposition := fmt.Sprintf("attachment; filename=monkeycode-%s.vsix", v.Version)
219+
disposition := fmt.Sprintf("attachment; filename=monkeycode-%s.vsix", version)
222220
c.Response().Header().Set("Content-Type", "application/octet-stream")
223221
c.Response().Header().Set("Content-Disposition", disposition)
224222
c.Response().Header().Set("Content-Length", fmt.Sprintf("%d", len(data)))

0 commit comments

Comments
 (0)