Skip to content

Commit 010a5c2

Browse files
authored
vpm: increment vpm downloads, use new endpoints (#18202)
1 parent c45c36c commit 010a5c2

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

cmd/tools/vpm.v

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ fn vpm_install_from_vpm(module_names []string) {
220220
continue
221221
}
222222
println('Installing module "${name}" from "${mod.url}" to "${minfo.final_module_path}" ...')
223+
increment_module_download_count(name) or {
224+
errors++
225+
eprintln('Errors while incrementing the download count for ${name}:')
226+
}
223227
vcs_install_cmd := supported_vcs_install_cmds[vcs]
224228
cmd := '${vcs_install_cmd} "${mod.url}" "${minfo.final_module_path}"'
225229
verbose_println(' command: ${cmd}')
@@ -406,6 +410,10 @@ fn vpm_update(m []string) {
406410
continue
407411
} else {
408412
verbose_println(' ${vcs_res.output.trim_space()}')
413+
increment_module_download_count(zname) or {
414+
errors++
415+
eprintln('Errors while incrementing the download count for ${zname}:')
416+
}
409417
}
410418
resolve_dependencies(modulename, final_module_path, module_names)
411419
}
@@ -740,7 +748,7 @@ fn get_module_meta_info(name string) !Mod {
740748
mut errors := []string{}
741749

742750
for server_url in vpm_server_urls {
743-
modurl := server_url + '/jsmod/${name}'
751+
modurl := server_url + '/api/packages/${name}'
744752
verbose_println('Retrieving module metadata from: "${modurl}" ...')
745753
r := http.get(modurl) or {
746754
errors << 'Http server did not respond to our request for "${modurl}" .'
@@ -774,6 +782,25 @@ fn get_module_meta_info(name string) !Mod {
774782
return error(errors.join_lines())
775783
}
776784

785+
fn increment_module_download_count(name string) ! {
786+
mut errors := []string{}
787+
788+
for server_url in vpm_server_urls {
789+
modurl := server_url + '/api/packages/${name}/incr_downloads'
790+
r := http.post(modurl, '') or {
791+
errors << 'Http server did not respond to our request for "${modurl}" .'
792+
errors << 'Error details: ${err}'
793+
continue
794+
}
795+
if r.status_code != 200 {
796+
errors << 'Failed to increment the download count for module "${name}", since "${server_url}" responded with ${r.status_code} http status code. Please try again later.'
797+
continue
798+
}
799+
return
800+
}
801+
return error(errors.join_lines())
802+
}
803+
777804
fn vpm_show(module_names []string) {
778805
installed_modules := get_installed_modules()
779806
for module_name in module_names {

0 commit comments

Comments
 (0)