Skip to content

Commit

Permalink
Merge branch 'release/2.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
RayWangQvQ committed Dec 2, 2023
2 parents 9c8739f + 435475b commit 5cd2aa1
Show file tree
Hide file tree
Showing 47 changed files with 1,115 additions and 107 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,5 @@
## 2.0.1
- PR[#539]:更新文档
- PR[#557]:修复直播接口权限不足问题
## 2.0.2
- PR[#617]:增加专栏投币功能与领取大会员经验的功能
2 changes: 1 addition & 1 deletion common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<Authors>Ray</Authors>
<Version>2.0.1</Version>
<Version>2.0.2</Version>
<NoWarn>$(NoWarn);CS1591;CS0436</NoWarn>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions docs/runInLocal.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ P.S.这里的运行环境指的是 `.NET Runtime 6.0.0` ,安装方法可详见
请下载 `win-x86-x64.zip`,此文件已自包含(self-contained)运行环境。

解压后,在应用目录打开cmd或powershell,执行`.\Ray.BiliBiliTool.Console.exe --runTasks=Login`,扫码登录。
也可以直接双击`Ray.BiliBiliTool.Console.exe`来运行,建议使用windows自带的定时任务来执行它

## 3. Linux:

Expand Down
2 changes: 2 additions & 0 deletions krew/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin
bilipro
26 changes: 19 additions & 7 deletions krew/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,30 @@ help: #### display help
deploy: build install #### build + install


.PHONY: fmt
fmt: #### run go fmt against code
@go fmt ./...


.PHONY: vet
vet: #### run go vet against code
@go vet ./...

.PHONY: update-modules
update-modules: tidy #### update go modules

.PHONY: tidy
tidy: #### run go mod tidy
@go mod tidy

.PHONY: build
build: #### build the plugin
@go vet ./... && \
go fmt ./... && \
echo "build on ${GOOS}/${GOARCH}" && \
cd ${ROOT_DIR}/krew/cmd && \
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -ldflags "-X github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/cmd.Version=${GITCOMMIT}" -o $(BIN_NAME) kubectl-bilipro.go

@echo "build on ${GOOS}/${GOARCH}" && \
GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0 go build -mod readonly -ldflags "-X github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/cmd.version=${GITCOMMIT}" -o bin/$(BIN_NAME) cmd/kubectl-bilipro.go

.PHONY: install
install: #### install the plugin
@cd ${ROOT_DIR}/krew/cmd && \
@cd ${ROOT_DIR}/krew/bin && \
sudo install ./$(BIN_NAME) ${KUBECTL_DIR}/$(BIN_NAME)

.PHONY: test
Expand Down
9 changes: 6 additions & 3 deletions krew/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ For example: the kubectl is installed under `/usr/bin`, then put the bilibilipro

### Deployment && Update

Command: `kubectl bilipro init --config config.yaml [optional]--login`
Prerequsites: please make sure you have the right permission to at least manage namespaces/deployments

Command: `kubectl bilipro init --config config.yaml`

Creates Deployment with the needed environments.

Optional Options:

- `--image=zai7lou/bilibili_tool_pro:1.0.1`
- `--image=zai7lou/bilibili_tool_pro:2.0.1`
- `--namespace=bilipro`
- `--image-pull-secret=`
- `--image-pull-secret=<docker secrets>`
- `--login` to scan QR code to login

Required Options:

Expand Down
4 changes: 2 additions & 2 deletions krew/cmd/kubectl-bilipro.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package main

import (
"fmt"
"os"

"github.com/spf13/pflag"

"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/cmd"
helper "github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/utils"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/klog/v2"
)

func main() {
Expand All @@ -17,7 +17,7 @@ func main() {

cmd := cmd.NewExecutor(genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr})
if err := cmd.Execute(); err != nil {
klog.Error(helper.GenErrorMsg(helper.SERVER_ERROR, err.Error()).Error())
fmt.Println(helper.GenErrorMsg(helper.SERVER_ERROR, err.Error()).Error())
os.Exit(1)
}
}
4 changes: 2 additions & 2 deletions krew/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
k8s.io/apimachinery v0.25.4
k8s.io/cli-runtime v0.25.4
k8s.io/client-go v0.25.4
k8s.io/klog/v2 v2.80.1
sigs.k8s.io/kustomize/api v0.12.1
sigs.k8s.io/kustomize/kyaml v0.13.9
sigs.k8s.io/yaml v1.3.0
Expand Down Expand Up @@ -58,10 +57,11 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
k8s.io/utils v0.0.0-20221107191617-1a15be271d1d // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
)

replace github.com/RayWangQvQ/BiliBiliToolPro/krew => ../krew
// replace github.com/RayWangQvQ/BiliBiliToolPro/krew => ../krew
6 changes: 3 additions & 3 deletions krew/pkg/cmd/delete.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"fmt"
"io"
"os/exec"
"strings"
Expand All @@ -9,8 +10,6 @@ import (
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml"

"k8s.io/klog/v2"

"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
helper "github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,9 +41,10 @@ func newDeleteCmd(out io.Writer, errOut io.Writer) *cobra.Command {

err := o.run(out)
if err != nil {
klog.Error(err)
fmt.Println(err)
return err
}
fmt.Println("bilibili tool is removed from your cluster")
return nil
},
}
Expand Down
5 changes: 2 additions & 3 deletions krew/pkg/cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package cmd

import (
"fmt"
"io"
"os/exec"

"k8s.io/klog/v2"

"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
helper "github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -37,7 +36,7 @@ func newGetCmd(out io.Writer, errOut io.Writer) *cobra.Command {

err := o.run(out)
if err != nil {
klog.Error(err)
fmt.Println(err)
return err
}
return nil
Expand Down
43 changes: 34 additions & 9 deletions krew/pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"os/exec"
"strings"
"time"

corev1 "k8s.io/api/core/v1"

Expand All @@ -17,8 +16,6 @@ import (

"sigs.k8s.io/kustomize/api/types"

"k8s.io/klog/v2"

"github.com/spf13/cobra"

"github.com/RayWangQvQ/BiliBiliToolPro/krew/pkg/options"
Expand Down Expand Up @@ -52,15 +49,15 @@ func newInitCmd(out io.Writer, errOut io.Writer) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
err := o.run(out)
if err != nil {
klog.Error(err)
fmt.Println(err)
return err
}
return nil
},
}

f := cmd.Flags()
f.StringVarP(&o.deployOpts.Image, "image", "i", "zai7lou/bilibili_tool_pro:1.0.1", "bilibilipro image")
f.StringVarP(&o.deployOpts.Image, "image", "i", "zai7lou/bilibili_tool_pro:2.0.1", "bilibilipro image")
f.StringVarP(&o.deployOpts.Namespace, "namespace", "n", "bilipro", "namespace scope for this request")
f.StringVar(&o.deployOpts.ImagePullSecret, "image-pull-secret", "", "image pull secret to be used for pulling bilibilipro image")
f.StringVarP(&o.deployOpts.ConfigFilePath, "config", "c", "", "the config file contanis the environment variables")
Expand Down Expand Up @@ -94,6 +91,8 @@ func (o *initCmd) run(writer io.Writer) error {
}

// TODO: All about paths are a little bit tricky should give it more thoughts

fmt.Println("Creating the kustomization file")
// if the bilibili tool is deployed under system/pre-defined namespace, ignore the namespace file
var resources []string // nolint: go-staticcheck
if o.deployOpts.Namespace == "default" || o.deployOpts.Namespace == "kube-system" || o.deployOpts.Namespace == "kube-public" {
Expand Down Expand Up @@ -211,6 +210,7 @@ func (o *initCmd) run(writer io.Writer) error {
}
}

fmt.Println("Applying the kustomization file")
// do kubectl apply
// make sure kubectl is under your PATH
cmd := exec.Command("kubectl", "apply", "-f", "-")
Expand All @@ -219,9 +219,9 @@ func (o *initCmd) run(writer io.Writer) error {
return err
}

// if there is login required
// if there is login required, exectue the login command as the last step
if o.login {

fmt.Println("please login...")
client, _, err := helper.GetK8sClient()
if err != nil {
return err
Expand All @@ -233,8 +233,33 @@ func (o *initCmd) run(writer io.Writer) error {
return err
}

// TODO: Stupid way, just sleep to wait container is ready, maybe a watch is a better option
time.Sleep(15 * time.Second)
fmt.Println("wait for the deployment to be ready")
// Wait for the deployment ready
checkCmdArgs := []string{
"rollout",
"status",
"deployment/bilibilipro",
"-n",
o.deployOpts.Namespace,
}
checkCmd := exec.Command("kubectl", checkCmdArgs...)

for {
if err := checkCmd.Start(); err != nil {
fmt.Printf("deployment is not ready yet, current status: %v\n", err)
continue
}

err := checkCmd.Wait()
if err == nil {
fmt.Printf("deployment is ready\n")
break
}
fmt.Printf("deployment is not ready yet, current status: %v\n", err)
}

fmt.Println("please scan the QR code")
// Exec the login command
args := []string{
"exec",
podName,
Expand Down
4 changes: 1 addition & 3 deletions krew/pkg/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"io"

"k8s.io/klog/v2"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -35,7 +33,7 @@ func newVersionCmd(out io.Writer, errOut io.Writer) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
err := o.run()
if err != nil {
klog.Error(err)
fmt.Println(err)
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion krew/pkg/resources/base/bilibiliPro/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
spec:
containers:
- name: bilibilipro
image: zai7lou/bilibili_tool_pro:1.0.1
image: zai7lou/bilibili_tool_pro:2.0.1
imagePullPolicy: IfNotPresent
resources:
requests:
Expand Down
2 changes: 2 additions & 0 deletions krew/pkg/utils/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ func GetK8sClient() (*kubernetes.Clientset, *rest.Config, error) {
if err != nil {
return nil, nil, GenErrorMsg(SERVER_ERROR, err.Error())
}
config.QPS = float32(10.0)
config.Burst = 20

// create the clientset
clientset, err := kubernetes.NewForConfig(config)
Expand Down
16 changes: 16 additions & 0 deletions scripts/publish.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime win-x86 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/win-x86
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime win-x64 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/win-x64
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime win-arm64 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/win-arm64
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime linux-x64 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/linux-x64
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime linux-musl-x64 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/linux-musl-x64
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime linux-arm64 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/linux-arm64
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime linux-arm --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/linux-arm
dotnet.exe publish ../src/Ray.BiliBiliTool.Console/Ray.BiliBiliTool.Console.csproj --runtime osx-x64 --no-self-contained -c Release -p:PublishSingleFile=true -o ./bin/Publish/osx-x64
Remove-Item ./bin/Publish/win-x86/*.pdb
Remove-Item ./bin/Publish/win-x64/*.pdb
Remove-Item ./bin/Publish/win-arm64/*.pdb
Remove-Item ./bin/Publish/linux-x64/*.pdb
Remove-Item ./bin/Publish/linux-musl-x64/*.pdb
Remove-Item ./bin/Publish/linux-arm64/*.pdb
Remove-Item ./bin/Publish/linux-arm/*.pdb
Remove-Item ./bin/Publish/osx-x64/*.pdb
10 changes: 4 additions & 6 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ publish_dotnet_dependent() {
dotnet publish --configuration Release \
--self-contained false \
-p:PublishSingleFile=true \
-p:DebugType=None \
-p:DebugSymbols=false \
-o $outputDir

echo "clear pdb files"
rm -rf $outputDir/*.pdb

echo "zip files..."
cd $publishDir
zip -q -r bilibili-tool-pro-v$version-dotnet-dependent.zip ./dotnet-dependent/*
Expand All @@ -90,11 +89,10 @@ publish_self_contained() {
--runtime $runtime \
-p:PublishTrimmed=true \
-p:PublishSingleFile=true \
-p:DebugType=None \
-p:DebugSymbols=false \
-o $outputDir

echo "clear pdb files"
rm -rf $outputDir/*.pdb

echo "zip files..."
cd $publishDir
zip -q -r bilibili-tool-pro-v$version-$runtime.zip ./$runtime/*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Article;

public class AddCoinForArticleRequest
{
public AddCoinForArticleRequest(long cvid,long mid,string csrf)
{
Aid = cvid;
Upid = mid;
Csrf = csrf;
}

public long Aid { get; set; }

public long Upid { get; set; }

public int Multiply { get; set; } = 1;

// 必须为2
public int Avtype { get; private set; } = 2;

public string Csrf { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Ray.BiliBiliTool.Agent.BiliBiliAgent.Dtos.Article;

public class SearchArticleInfoResponse
{
public int Like { get; set; }

public int Coin { get; set; }

public long Mid { get; set; }
}
Loading

0 comments on commit 5cd2aa1

Please sign in to comment.