mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	NPM Package Registry search API endpoint (#20280)
Close #20098, in the NPM registry API, implemented to match what's described by https://github.com/npm/registry/blob/master/docs/REGISTRY-API.md#get-v1search Currently have only implemented the bare minimum to work with the [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui.html). Co-authored-by: Jack Vine <jackv@jack-lemur-suse.cat-prometheus.ts.net> Co-authored-by: KN4CK3R <admin@oldschoolhack.me> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -350,3 +350,35 @@ func setPackageTag(tag string, pv *packages_model.PackageVersion, deleteOnly boo | ||||
|  | ||||
| 	return committer.Commit() | ||||
| } | ||||
|  | ||||
| func PackageSearch(ctx *context.Context) { | ||||
| 	pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{ | ||||
| 		OwnerID: ctx.Package.Owner.ID, | ||||
| 		Type:    packages_model.TypeNpm, | ||||
| 		Name: packages_model.SearchValue{ | ||||
| 			ExactMatch: false, | ||||
| 			Value:      ctx.FormTrim("text"), | ||||
| 		}, | ||||
| 		Paginator: db.NewAbsoluteListOptions( | ||||
| 			ctx.FormInt("from"), | ||||
| 			ctx.FormInt("size"), | ||||
| 		), | ||||
| 	}) | ||||
| 	if err != nil { | ||||
| 		apiError(ctx, http.StatusInternalServerError, err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	pds, err := packages_model.GetPackageDescriptors(ctx, pvs) | ||||
| 	if err != nil { | ||||
| 		apiError(ctx, http.StatusInternalServerError, err) | ||||
| 		return | ||||
| 	} | ||||
|  | ||||
| 	resp := createPackageSearchResponse( | ||||
| 		pds, | ||||
| 		total, | ||||
| 	) | ||||
|  | ||||
| 	ctx.JSON(http.StatusOK, resp) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user