From d4f229fdb033bc921285b0b62c74cbe7a1b77cd6 Mon Sep 17 00:00:00 2001 From: Monet Lee Date: Mon, 25 Nov 2024 12:09:16 +0800 Subject: [PATCH] fix: solve merge error. --- .../workflows/remove-unused-labels copy.yml | 74 ------------------- go.mod | 6 +- pkg/common/db/database/admin.go | 6 +- pkg/common/tokenverify/token_verify.go | 15 ++++ 4 files changed, 23 insertions(+), 78 deletions(-) delete mode 100644 .github/workflows/remove-unused-labels copy.yml diff --git a/.github/workflows/remove-unused-labels copy.yml b/.github/workflows/remove-unused-labels copy.yml deleted file mode 100644 index ab80b1f9..00000000 --- a/.github/workflows/remove-unused-labels copy.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: Remove Unused Labels -on: - workflow_dispatch: - -jobs: - cleanup: - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - contents: read - steps: - - name: Checkout Repository - uses: actions/checkout@v4 - - - name: Fetch All Issues and PRs - id: fetch_issues_prs - uses: actions/github-script@v7.0.1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const issues = await github.paginate(github.rest.issues.listForRepo, { - owner: context.repo.owner, - repo: context.repo.repo, - state: 'all', - per_page: 100 - }); - - const labelsInUse = new Set(); - issues.forEach(issue => { - issue.labels.forEach(label => { - labelsInUse.add(label.name); - }); - }); - - return JSON.stringify(Array.from(labelsInUse)); - result-encoding: string - - - name: Fetch All Labels - id: fetch_labels - uses: actions/github-script@v7.0.1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const labels = await github.paginate(github.rest.issues.listLabelsForRepo, { - owner: context.repo.owner, - repo: context.repo.repo, - per_page: 100 - }); - - return JSON.stringify(labels.map(label => label.name)); - result-encoding: string - - - name: Remove Unused Labels - uses: actions/github-script@v7.0.1 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const labelsInUse = new Set(JSON.parse(process.env.LABELS_IN_USE)); - const allLabels = JSON.parse(process.env.ALL_LABELS); - - const unusedLabels = allLabels.filter(label => !labelsInUse.has(label)); - - for (const label of unusedLabels) { - await github.rest.issues.deleteLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: label - }); - console.log(`Deleted label: ${label}`); - } - env: - LABELS_IN_USE: ${{ steps.fetch_issues_prs.outputs.result }} - ALL_LABELS: ${{ steps.fetch_labels.outputs.result }} diff --git a/go.mod b/go.mod index 415298ac..830aacac 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module github.com/openimsdk/chat -go 1.21 +go 1.21.2 + +toolchain go1.23.2 require ( github.com/gin-gonic/gin v1.9.1 @@ -11,7 +13,7 @@ require ( github.com/pkg/errors v0.9.1 // indirect google.golang.org/grpc v1.62.1 google.golang.org/protobuf v1.33.0 - gopkg.in/yaml.v3 v3.0.1 + gopkg.in/yaml.v3 v3.0.1 // indirect gorm.io/gorm v1.25.8 ) diff --git a/pkg/common/db/database/admin.go b/pkg/common/db/database/admin.go index 527a32d6..74b9ee4d 100644 --- a/pkg/common/db/database/admin.go +++ b/pkg/common/db/database/admin.go @@ -16,10 +16,12 @@ package database import ( "context" - "go.mongodb.org/mongo-driver/bson/primitive" "time" + "go.mongodb.org/mongo-driver/bson/primitive" + "github.com/openimsdk/chat/pkg/common/db/cache" + "github.com/openimsdk/chat/pkg/common/tokenverify" "github.com/openimsdk/tools/db/mongoutil" "github.com/openimsdk/tools/db/pagination" "github.com/openimsdk/tools/db/tx" @@ -138,7 +140,7 @@ func NewAdminDatabase(cli *mongoutil.Client, rdb redis.UniversalClient, token *t applet: applet, clientConfig: clientConfig, application: application, - cache: cache.NewTokenInterface(rdb), + cache: cache.NewTokenInterface(rdb, token), }, nil } diff --git a/pkg/common/tokenverify/token_verify.go b/pkg/common/tokenverify/token_verify.go index f53cd5ae..7cf68d8a 100644 --- a/pkg/common/tokenverify/token_verify.go +++ b/pkg/common/tokenverify/token_verify.go @@ -109,6 +109,21 @@ func (t *Token) GetToken(token string) (string, int32, error) { return userID, userType, nil } +func (t *Token) GetExpire(token string) time.Time { + val, err := jwt.ParseWithClaims(token, &claims{}, t.secret()) + if err != nil { + return time.Time{} + } + c, ok := val.Claims.(*claims) + if !ok { + return time.Time{} + } + if c.ExpiresAt == nil { + return time.Time{} + } + return c.ExpiresAt.Time +} + //func (t *Token) GetAdminTokenCache(token string) (string, error) { // userID, userType, err := getToken(token) // if err != nil {