@@ -53,14 +53,12 @@ func (c *harborClient) ListRepos(request ProjectRequest) (names []string, err er
53
53
if request .Name != "" {
54
54
projectUrl = projectUrl + "&q=name=~" + request .Name
55
55
}
56
- body , _ , err1 := c .HttpClient .Get (projectUrl )
57
- if err1 != nil {
58
- err = err1
56
+ body , _ , err := c .HttpClient .Get (projectUrl )
57
+ if err != nil {
59
58
return
60
59
}
61
60
var projects []harborBody
62
- if err1 = json .Unmarshal (body , & projects ); err1 != nil {
63
- err = err1
61
+ if err = json .Unmarshal (body , & projects ); err != nil {
64
62
return
65
63
}
66
64
for _ , r := range projects {
@@ -71,7 +69,6 @@ func (c *harborClient) ListRepos(request ProjectRequest) (names []string, err er
71
69
72
70
func (c * harborClient ) ListImages (request RepoRequest ) (response RepoResponse , err error ) {
73
71
project := request .Repo
74
- //计数器
75
72
startCount := (request .Page - 1 ) * request .Limit
76
73
77
74
if c .Version == "v2" {
@@ -80,6 +77,7 @@ func (c *harborClient) ListImages(request RepoRequest) (response RepoResponse, e
80
77
limit := 100
81
78
artifactCount := 0
82
79
repoArCount := 0
80
+ artifactStart := 0
83
81
var repos []harborBody
84
82
for start {
85
83
repoUrl := fmt .Sprintf ("%s/%s/%s?page=%d&&page_size=%d" , getProjectUrl (c .Version ), project , repositoryUrl , p , limit )
@@ -93,26 +91,31 @@ func (c *harborClient) ListImages(request RepoRequest) (response RepoResponse, e
93
91
err = err1
94
92
return
95
93
}
94
+ if len (items ) < limit {
95
+ start = false
96
+ }
96
97
for _ , v := range items {
97
98
if v .ArtifactCount == 0 {
98
99
continue
99
100
}
101
+ artifactCount = artifactCount + v .ArtifactCount
100
102
if artifactCount >= startCount {
101
103
repoArCount = repoArCount + v .ArtifactCount
102
- if repoArCount >= limit {
104
+ if repoArCount >= request . Limit {
103
105
start = false
104
106
break
105
107
}
106
108
repos = append (repos , v )
107
109
continue
108
110
}
109
- if artifactCount + v . ArtifactCount < = startCount {
110
- artifactCount = artifactCount + v . ArtifactCount
111
+ if artifactCount > = startCount {
112
+ artifactStart = artifactCount - startCount
111
113
}
112
114
}
113
115
p ++
114
116
}
115
117
repoUrl := fmt .Sprintf ("%s/%s/%s" , getProjectUrl (c .Version ), project , repositoryUrl )
118
+ var items []string
116
119
for _ , r := range repos {
117
120
repoName := strings .Replace (r .Name , project + "/" , "" , - 1 )
118
121
body , res , err2 := c .HttpClient .Get (fmt .Sprintf ("%s/%s/%s?page=%d&&page_size=%d" , repoUrl , repoName , artifactUrl , 1 , r .ArtifactCount ))
@@ -132,10 +135,23 @@ func (c *harborClient) ListImages(request RepoRequest) (response RepoResponse, e
132
135
}
133
136
for _ , art := range artifacts {
134
137
for _ , tag := range art .Tags {
135
- response . Items = append (response . Items , r .Name + ":" + tag .Name )
138
+ items = append (items , r .Name + ":" + tag .Name )
136
139
}
137
140
}
138
141
}
142
+ artifactEnd := artifactStart + limit
143
+ if artifactStart + limit > len (items ) {
144
+ artifactEnd = len (items ) - 1
145
+ }
146
+ if artifactStart > artifactEnd {
147
+ response .Items = []string {}
148
+ return
149
+ }
150
+ response .Items = items [artifactStart : artifactEnd + 1 ]
151
+ if len (response .Items ) == request .Limit {
152
+ response .ContinueToken = "continue"
153
+ }
154
+
139
155
} else {
140
156
result , err1 := c .HttpClient .GetNameResult (getProjectUrl (c .Version ))
141
157
if err1 != nil {
0 commit comments