Skip to content

Commit

Permalink
feat: crawl tab shows the number of available nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
snakem982 committed Jan 9, 2025
1 parent 977e2c6 commit af372ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions backend/spider/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

type Getter struct {
Id string `json:"id,omitempty" yaml:"id,omitempty"`
Id string `json:"id" yaml:"id"`
Type string `json:"type" yaml:"type"`
Url string `json:"url" yaml:"url"`
Headers map[string]string `json:"headers,omitempty" yaml:"headers,omitempty"`
Expand Down Expand Up @@ -51,18 +51,20 @@ func GetBytes(url string, headers map[string]string) []byte {

func AddIdAndUpdateGetter(pc chan []map[string]any, nodes []map[string]any, g Getter) {
i := len(nodes)

// 更新getter
g.CrawlNodes = i
g.AvailableNodes = 0
bytes, _ := json.Marshal(g)
_ = cache.Put(g.Id, bytes)

// 添加id
if i > 0 {
for _, node := range nodes {
node["gid"] = g.Id
}
pc <- nodes
}
// 更新getter
g.CrawlNodes = i
g.AvailableNodes = 0
bytes, _ := json.Marshal(g)
_ = cache.Put(g.Id, bytes)
}

func AvailableAndUpdateGetter(proxies []map[string]any) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/views/Crawl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,15 +329,15 @@ async function filter() {
<el-table-column label="爬取节点 Crawl" width="95em" align="center">
<template #default="scope">
<el-text truncated size="large" type="danger" v-if="!scope.row.crawl_nodes">
0
{{ scope.row.crawl_nodes == 0 ? 0 : "" }}
</el-text>
<el-text truncated size="large" v-else> {{ scope.row.crawl_nodes }}</el-text>
</template>
</el-table-column>
<el-table-column label="可用节点 Available" width="95em" align="center">
<template #default="scope">
<el-text truncated size="large" type="danger" v-if="!scope.row.available_nodes">
0
{{ scope.row.crawl_nodes == 0 ? 0 : "" }}
</el-text>
<el-text truncated size="large" v-else> {{ scope.row.available_nodes }}</el-text>
</template>
Expand Down

0 comments on commit af372ed

Please sign in to comment.