From 0f33e164ff48007baebfd36603e01f66d539ad0a Mon Sep 17 00:00:00 2001 From: Promix953 Date: Fri, 5 Aug 2022 17:14:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84ARM=E6=94=AF=E6=8C=81=20?= =?UTF-8?q?=E7=94=9F=E6=88=90=E5=B9=B6=E6=8F=90=E4=BA=A4=E5=A4=9A=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0Docker=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/push-to-docker.yml | 101 +++++++++++++++++---------- Dockerfile | 4 +- go.mod | 11 +-- go.sum | 22 ++---- lib/core.go | 35 +++++++--- lib/respond.go | 4 +- lib/study.go | 2 +- lib/utils.go | 16 ++--- model/user.go | 16 ++--- 9 files changed, 120 insertions(+), 91 deletions(-) diff --git a/.github/workflows/push-to-docker.yml b/.github/workflows/push-to-docker.yml index aa62ddc..103d716 100644 --- a/.github/workflows/push-to-docker.yml +++ b/.github/workflows/push-to-docker.yml @@ -1,47 +1,76 @@ name: docker build -on: [push, pull_request] - -env: - BINARY_PREFIX: "study_xxqg_" - BINARY_SUFFIX: "" - PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request." - LD_FLAGS: "-w -s" +on: + push: + branches: + - 'main' + tags: + - '*' + pull_request: + branches: + - 'main' jobs: build: - name: Build binary CI runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Setup Go environment - uses: actions/setup-go@v2.1.3 + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up Go + uses: actions/setup-go@v3 with: go-version: 1.17 - - - name: Build binary file - run: | - export LD_FLAGS="-w -s -X main.VERSION=${COMMIT_ID::7}" - go mod tidy - go build -o "output/study_xxqg" -trimpath -ldflags "$LD_FLAGS" ./ - - - name: Set up QEMU + - + name: Cache Go modules + uses: actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - + name: Set up QEMU + id: qemu uses: docker/setup-qemu-action@v2 - - name: Set up Docker Buildx + - + name: Set up Docker Buildx + id: buildx uses: docker/setup-buildx-action@v2 - - name: push to docker - run: | - docker login -u ${{secrets.DOCKERHUB_USERNAME}} -p ${{secrets.DOCKERHUB_PASSWORD}} - pwd - docker build -t jolanse/study_xxqg ./ - docker tag jolanse/study_xxqg jolanse/study_xxqg - docker push jolanse/study_xxqg - - name: push to tag - if: startsWith(github.ref, 'refs/tags/') - run: | - echo "RELEASE_VERSION=${GITHUB_REF:10}" >> $GITHUB_ENV - echo ${GITHUB_REF:10} - docker tag jolanse/study_xxqg jolanse/study_xxqg:${GITHUB_REF:10} - docker push jolanse/study_xxqg:${GITHUB_REF:10} - - + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v3 + with: + distribution: goreleaser + version: latest + args: build --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: jolanse/study_xxqg + tags: | + type=raw,value=latest + type=ref,event=tag + - + name: Docker Login + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - + name: Build and push + id: docker_build + uses: docker/build-push-action@v3 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 68e4e6a..29e0d0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,8 @@ FROM debian:bullseye-slim -COPY ./output/study_xxqg /opt/study_xxqg +ARG TARGETARCH + +COPY ./dist/nowin_linux_$TARGETARCH*/study_xxqg /opt/study_xxqg RUN mkdir /opt/config/ diff --git a/go.mod b/go.mod index 545c68b..ff73e08 100644 --- a/go.mod +++ b/go.mod @@ -17,8 +17,8 @@ require ( github.com/klauspost/compress v1.15.5 github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/makiuchi-d/gozxing v0.1.1 - github.com/mxschmitt/playwright-go v0.1400.0 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 + github.com/playwright-community/playwright-go v0.2000.1 github.com/robfig/cron/v3 v3.0.0 github.com/sirupsen/logrus v1.9.0 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e @@ -30,23 +30,18 @@ require ( ) require ( - github.com/codegangsta/negroni v1.0.0 // indirect github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect github.com/go-playground/validator/v10 v10.5.0 // indirect - github.com/goincremental/negroni-sessions v0.0.0-20171223143234-40b49004abee // indirect + github.com/go-stack/stack v1.8.1 // indirect github.com/golang/protobuf v1.5.2 // indirect - github.com/gorilla/context v1.1.1 // indirect - github.com/gorilla/securecookie v1.1.1 // indirect - github.com/gorilla/sessions v1.2.1 // indirect github.com/gorilla/websocket v1.4.2 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect github.com/json-iterator/go v1.1.10 // indirect - github.com/julienschmidt/httprouter v1.3.0 // indirect github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect github.com/leodido/go-urn v1.2.1 // indirect github.com/lestrrat-go/strftime v1.0.5 // indirect @@ -60,8 +55,6 @@ require ( github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/ugorji/go/codec v1.2.5 // indirect - github.com/urfave/negroni v1.0.0 // indirect - github.com/yujinliang/wechat v0.0.0-20220623135211-fb0809eeece2 // indirect golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect golang.org/x/mod v0.3.0 // indirect golang.org/x/net v0.0.0-20220111093109-d55c255bac03 // indirect diff --git a/go.sum b/go.sum index d068cf1..994be0b 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,5 @@ github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h1:2dk3eOnYllh+wUOuDhOoC2vUVoJF/5z478ryJ+wzEII= github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk= -github.com/codegangsta/negroni v1.0.0 h1:+aYywywx4bnKXWvoWtRfJ91vC59NbEhEY03sZjQhbVY= github.com/codegangsta/negroni v1.0.0/go.mod h1:v0y3T5G7Y1UlFfyxFn/QLRU4a2EuNau2iZY63YTKWo0= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 h1:y5HC9v93H5EPKqaS1UYVg1uYah5Xf51mBfIoWehClUQ= github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9hchkHSWYkEqJwUGisez3G1QY8Ryz0sdWrLPMGjLk= @@ -23,9 +22,10 @@ github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+ github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-playground/validator/v10 v10.5.0 h1:X9rflw/KmpACwT8zdrm1upefpvdy6ur8d1kWyq6sg3E= github.com/go-playground/validator/v10 v10.5.0/go.mod h1:xm76BBt941f7yWdGnI2DVPFFg1UK3YY04qifoXU3lOk= +github.com/go-stack/stack v1.8.1 h1:ntEHSVwIt7PNXNpgPmVfMrNhLtgjlmnZha2kOpuRiDw= +github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0 h1:mbEDV1g6RBzKd4sFjOWuyZdxItw4CWu5Kq4KaBAJbHM= github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.4.0-beta.0/go.mod h1:5+h9c5l1Z/+Pi+5boa1Fmr4Q+FImsXYnifor92ljaVs= -github.com/goincremental/negroni-sessions v0.0.0-20171223143234-40b49004abee h1:aBLa9mJSmSV0I7vZrb+jMakH/B5rR+mRI6Q/DxQ+O7g= github.com/goincremental/negroni-sessions v0.0.0-20171223143234-40b49004abee/go.mod h1:32Cq/6avji0Xp32YipwaOV3PsvpGfuYKTJP9XJrdXe8= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= @@ -38,11 +38,8 @@ github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/context v1.1.1 h1:AWwleXJkX/nhcU9bZSnZoi3h/qGYqQAGhq6zZe/aQW8= github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg= -github.com/gorilla/securecookie v1.1.1 h1:miw7JPhV+b/lAHSXz4qd/nN9jRiAFV5FwjeKyCS8BvQ= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= -github.com/gorilla/sessions v1.2.1 h1:DHd3rPN5lE3Ts3D8rKkQ8x/0kqfeNmBAaiSi+o7FsgI= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= @@ -55,10 +52,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/imroc/req/v3 v3.8.2 h1:wFZ7B0dclCQyjClP5GwXRboUGIek5l0mCpodrGgT01c= github.com/imroc/req/v3 v3.8.2/go.mod h1:3JIicOKEDHfCSYYNLb/ObZNpx64EV5y40VlHMwhUCzU= -github.com/johlanse/wechat v0.0.0-20220731101603-68047d1e93e2 h1:hbe3Fbjc+1Ne+fUzxRlxYCzZOi9kzwhacys9D1tXreo= -github.com/johlanse/wechat v0.0.0-20220731101603-68047d1e93e2/go.mod h1:Dwcvo5MQU6u7XKoClpxoUlJMBAJhES9Qz4d2TSSBrU8= -github.com/johlanse/wechat v0.0.0-20220731102434-854afb866cf2 h1:57tGW/IDYuqtbHZSXuVFRkwTRD6dmcOL/M86yK2MyTA= -github.com/johlanse/wechat v0.0.0-20220731102434-854afb866cf2/go.mod h1:Dwcvo5MQU6u7XKoClpxoUlJMBAJhES9Qz4d2TSSBrU8= github.com/johlanse/wechat v0.0.0-20220731103216-3c9e7b56434f h1:wpe87qm/nBbQ8BT+mrYvEHnXRbn11+2iSYpjrj62QAQ= github.com/johlanse/wechat v0.0.0-20220731103216-3c9e7b56434f/go.mod h1:dLGDxcVd4CFRQInD2S2aMm4CGobWAFixOEgFxXZJ6Sw= github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= @@ -66,7 +59,6 @@ github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUB github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= @@ -111,6 +103,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLA github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/playwright-community/playwright-go v0.2000.1 h1:2JViSHpJQ/UL/PO1Gg6gXV5IcXAAsoBJ3KG9L3wKXto= +github.com/playwright-community/playwright-go v0.2000.1/go.mod h1:1y9cM9b9dVHnuRWzED1KLM7FtbwTJC8ibDjI6MNqewU= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk= @@ -118,8 +112,6 @@ github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qq github.com/robfig/cron/v3 v3.0.0 h1:kQ6Cb7aHOHTSzNVNEhmp8EcWKLb4CbiMW9h9VyIhO4E= github.com/robfig/cron/v3 v3.0.0/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= -github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= @@ -146,11 +138,8 @@ github.com/ugorji/go v1.2.5/go.mod h1:gat2tIT8KJG8TVI8yv77nEO/KYT6dV7JE1gfUa8Xul github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.2.5 h1:8WobZKAk18Msm2CothY2jnztY56YVY8kF1oQrj21iis= github.com/ugorji/go/codec v1.2.5/go.mod h1:QPxoTbPKSEAlAHPYt02++xp/en9B/wUdwFCz+hj5caA= -github.com/urfave/negroni v1.0.0 h1:kIimOitoypq34K7TG7DUaJ9kq/N4Ofuwi1sjz0KipXc= github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yujinliang/wechat v0.0.0-20220623135211-fb0809eeece2 h1:beflFd/e1LnYqtB9cDPEmc1NNV4GvdWzRFtKp9+o/HQ= -github.com/yujinliang/wechat v0.0.0-20220623135211-fb0809eeece2/go.mod h1:Rv+LwiyfMMdSkJP5Kt+8QmcXlufGNcR+D6yz21gI2eM= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= @@ -172,7 +161,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -183,8 +171,6 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= -golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= diff --git a/lib/core.go b/lib/core.go index d7078a4..b4963cf 100644 --- a/lib/core.go +++ b/lib/core.go @@ -20,8 +20,8 @@ import ( "github.com/imroc/req/v3" "github.com/makiuchi-d/gozxing" "github.com/makiuchi-d/gozxing/qrcode" - "github.com/mxschmitt/playwright-go" "github.com/nfnt/resize" + "github.com/playwright-community/playwright-go" log "github.com/sirupsen/logrus" goqrcode "github.com/skip2/go-qrcode" "golang.org/x/image/bmp" @@ -32,7 +32,6 @@ import ( // Core // @Description: -// type Core struct { pw *playwright.Playwright browser playwright.Browser @@ -42,7 +41,6 @@ type Core struct { // Cookie // @Description: -// type Cookie struct { Name string `json:"name" yaml:"name"` Value string `json:"value" yaml:"value"` @@ -277,11 +275,22 @@ func (c *Core) initWindows() { if err != nil { return } - pwt, err := playwright.Run(&playwright.RunOptions{ + + pwo := &playwright.RunOptions{ DriverDirectory: dir + "/tools/driver/", SkipInstallBrowsers: true, Browsers: []string{"msedge"}, - }) + } + + err = playwright.Install(pwo) + if err != nil { + log.Errorln("[core]", "安装playwright失败") + log.Errorln("[core] ", err.Error()) + + return + } + + pwt, err := playwright.Run(pwo) if err != nil { log.Errorln("[core]", "初始化playwright失败") log.Errorln("[core] ", err.Error()) @@ -344,11 +353,21 @@ func (c *Core) initNotWindows() { } } - pwt, err := playwright.Run(&playwright.RunOptions{ + pwo := &playwright.RunOptions{ DriverDirectory: dir + "/tools/driver/", SkipInstallBrowsers: false, Browsers: []string{"chromium"}, - }) + } + + err = playwright.Install(pwo) + if err != nil { + log.Errorln("[core]", "安装playwright失败") + log.Errorln("[core] ", err.Error()) + + return + } + + pwt, err := playwright.Run(pwo) if err != nil { log.Errorln("[core]", "初始化playwright失败") log.Errorln("[core] ", err.Error()) @@ -538,7 +557,7 @@ func removeNode(page playwright.Page) { // * 图片裁剪 // * 入参:图片输入、输出、缩略图宽、缩略图高、Rectangle{Pt(x0, y0), Pt(x1, y1)},精度 // * 规则:如果精度为0则精度保持不变 -//* +// * // * 返回:error // */ func Clip(in io.Reader, out io.Writer, wi, hi, x0, y0, x1, y1, quality int) (err error) { diff --git a/lib/respond.go b/lib/respond.go index 2afd4b6..231dd83 100644 --- a/lib/respond.go +++ b/lib/respond.go @@ -12,7 +12,7 @@ import ( "time" "github.com/imroc/req/v3" - "github.com/mxschmitt/playwright-go" + "github.com/playwright-community/playwright-go" log "github.com/sirupsen/logrus" "github.com/tidwall/gjson" @@ -191,7 +191,7 @@ func (c *Core) RespondDaily(user *model.User, model string) { //} tryCount := 0 - for true { + for { label: tryCount++ if tryCount >= 30 { diff --git a/lib/study.go b/lib/study.go index c8ea5e2..bbd51d6 100644 --- a/lib/study.go +++ b/lib/study.go @@ -9,7 +9,7 @@ import ( "time" "github.com/guonaihong/gout" - "github.com/mxschmitt/playwright-go" + "github.com/playwright-community/playwright-go" log "github.com/sirupsen/logrus" "github.com/johlanse/study_xxqg/model" diff --git a/lib/utils.go b/lib/utils.go index b4d40da..e44ea08 100644 --- a/lib/utils.go +++ b/lib/utils.go @@ -3,7 +3,7 @@ package lib import ( "net/http" - "github.com/mxschmitt/playwright-go" + "github.com/playwright-community/playwright-go" ) func cookieToJar(cookies []Cookie) []*http.Cookie { @@ -28,9 +28,9 @@ func cookieToJar(cookies []Cookie) []*http.Cookie { return cooks } -func cookieToParam(cookies []Cookie) []playwright.SetNetworkCookieParam { +func cookieToParam(cookies []Cookie) []playwright.BrowserContextAddCookiesOptionsCookies { var ( - cooks []playwright.SetNetworkCookieParam + cooks []playwright.BrowserContextAddCookiesOptionsCookies ) for _, c := range cookies { @@ -38,15 +38,15 @@ func cookieToParam(cookies []Cookie) []playwright.SetNetworkCookieParam { if c.Name == "acw_tc" || c.Name == "aliyungf_tc" { domain = "iflow-api.xuexi.cn\t" } - cooks = append(cooks, playwright.SetNetworkCookieParam{ - Name: c.Name, - Value: c.Value, + cooks = append(cooks, playwright.BrowserContextAddCookiesOptionsCookies{ + Name: playwright.String(c.Name), + Value: playwright.String(c.Value), Domain: playwright.String(domain), Path: playwright.String(c.Path), - Expires: playwright.Int(c.Expires), + Expires: playwright.Float(float64(c.Expires)), HttpOnly: playwright.Bool(c.HTTPOnly), Secure: playwright.Bool(c.Secure), - SameSite: playwright.String(c.SameSite), + SameSite: playwright.SameSiteAttributeStrict, }) } return cooks diff --git a/model/user.go b/model/user.go index 45b5225..0f94cdb 100644 --- a/model/user.go +++ b/model/user.go @@ -11,7 +11,7 @@ import ( "github.com/guonaihong/gout" "github.com/imroc/req/v3" - "github.com/mxschmitt/playwright-go" + "github.com/playwright-community/playwright-go" log "github.com/sirupsen/logrus" "github.com/tidwall/gjson" @@ -239,18 +239,18 @@ func TokenToCookies(token string) []*http.Cookie { return []*http.Cookie{cookie} } -func (u *User) ToBrowserCookies() []playwright.SetNetworkCookieParam { - cookie := playwright.SetNetworkCookieParam{ - Name: "token", - Value: u.Token, +func (u *User) ToBrowserCookies() []playwright.BrowserContextAddCookiesOptionsCookies { + cookie := playwright.BrowserContextAddCookiesOptionsCookies{ + Name: playwright.String("token"), + Value: playwright.String(u.Token), Path: playwright.String("/"), Domain: playwright.String(".xuexi.cn"), - Expires: playwright.Int(int(time.Now().Add(time.Hour * 12).UnixNano())), + Expires: playwright.Float(float64(time.Now().Add(time.Hour * 12).Unix())), Secure: playwright.Bool(false), HttpOnly: playwright.Bool(false), - SameSite: playwright.String("Strict"), + SameSite: playwright.SameSiteAttributeStrict, } - return []playwright.SetNetworkCookieParam{cookie} + return []playwright.BrowserContextAddCookiesOptionsCookies{cookie} } // CheckUserCookie