@@ -41,10 +41,12 @@ public function __construct(
4141 private readonly PackageDistributionResolver $ distributionResolver ,
4242 private readonly PackageProviderManager $ providerManager ,
4343 private readonly MessageBusInterface $ messenger ,
44+ #[Autowire(param: 'dirigent.distributions.async_api_requests ' )]
45+ private readonly bool $ asyncApiRequests ,
4446 #[Autowire(param: 'dirigent.packages.dynamic_updates ' )]
4547 private readonly bool $ dynamicUpdatesEnabled ,
4648 #[Autowire(param: 'dirigent.metadata.mirror_vcs_repositories ' )]
47- private readonly bool $ mirrorVcsRepositories = false ,
49+ private readonly bool $ mirrorVcsRepositories ,
4850 ) {
4951 }
5052
@@ -63,7 +65,7 @@ public function root(RouterInterface $router): JsonResponse
6365 ];
6466
6567 if ($ this ->getParameter ('dirigent.distributions.mirror ' )) {
66- $ distributionUrlPattern = u ($ router ->getRouteCollection ()->get ('api_package_distribution ' )->getPath ())
68+ $ distributionUrlPattern = u ($ router ->getRouteCollection ()->get ('api_package_distribution_mirror ' )->getPath ())
6769 ->replace ('{package} ' , '%package% ' )
6870 ->replace ('{version} ' , '%version% ' )
6971 ->replace ('{reference} ' , '%reference% ' )
@@ -105,18 +107,19 @@ public function packageMetadata(Request $request): Response
105107 return $ response ;
106108 }
107109
108- #[Route('/dist/{package}/{version}-{reference}.{type} ' ,
110+ #[Route('/dist/{package}/{version}-r{revision}- {reference}.{type} ' ,
109111 name: 'api_package_distribution ' ,
110112 requirements: [
111113 'package ' => MapPackage::PACKAGE_REGEX ,
112114 'version ' => '.+ ' ,
115+ 'revision ' => '[1-9][0-9]* ' ,
113116 'reference ' => '[a-z0-9]+ ' ,
114117 'type ' => '(zip) ' ,
115118 ],
116119 methods: ['GET ' ],
117120 )]
118121 #[IsGrantedAccess]
119- public function packageDistribution (Request $ request , string $ reference , string $ type ): Response
122+ public function packageDistribution (Request $ request , int $ revision , string $ reference , string $ type ): Response
120123 {
121124 if (!$ this ->getParameter ('dirigent.distributions.enabled ' )) {
122125 throw $ this ->createNotFoundException ();
@@ -125,21 +128,57 @@ public function packageDistribution(Request $request, string $reference, string
125128 $ packageName = $ request ->attributes ->get ('package ' );
126129 $ versionName = $ request ->attributes ->get ('version ' );
127130
128- if (!$ this ->distributionResolver ->exists ($ packageName , $ versionName , $ reference , $ type )) {
129- if (null === $ package = $ this ->findPackage ($ packageName )) {
130- throw $ this ->createNotFoundException ();
131- }
131+ if (null === $ package = $ this ->findPackage ($ packageName )) {
132+ throw $ this ->createNotFoundException ();
133+ }
132134
133- if (null === $ metadata = $ this ->metadataRepository ->findOneByNormalizedNameAndReference ($ package , $ versionName , $ reference )) {
134- throw $ this ->createNotFoundException ();
135- }
135+ if (null === $ metadata = $ this ->metadataRepository ->findOneByNormalizedNameAndRevision ($ package , $ versionName , $ revision )) {
136+ throw $ this ->createNotFoundException ();
137+ }
136138
137- if (!$ this ->distributionResolver ->resolve ($ metadata , $ type , async: $ this ->getParameter ('dirigent.distributions.async_api_requests ' ))) {
138- throw $ this ->createNotFoundException ();
139- }
139+ if (!$ this ->distributionResolver ->resolve ($ metadata , $ reference , $ type , async: $ this ->asyncApiRequests )) {
140+ throw $ this ->createNotFoundException ();
141+ }
142+
143+ $ path = $ this ->distributionResolver ->path ($ metadata , $ reference , $ type );
144+ $ filename = u ("$ packageName- $ versionName-r $ revision- $ reference. $ type " )->replace ('/ ' , '- ' )->toString ();
145+
146+ return $ this ->file ($ path , $ filename );
147+ }
148+
149+ #[Route('/dist-mirror/{package}/{version}-{reference}.{type} ' ,
150+ name: 'api_package_distribution_mirror ' ,
151+ requirements: [
152+ 'package ' => MapPackage::PACKAGE_REGEX ,
153+ 'version ' => '.+ ' ,
154+ 'reference ' => '[a-z0-9]+ ' ,
155+ 'type ' => '(zip) ' ,
156+ ],
157+ methods: ['GET ' ],
158+ )]
159+ #[IsGrantedAccess]
160+ public function packageDistributionMirror (Request $ request , string $ reference , string $ type ): Response
161+ {
162+ if (!$ this ->getParameter ('dirigent.distributions.enabled ' )) {
163+ throw $ this ->createNotFoundException ();
164+ }
165+
166+ $ packageName = $ request ->attributes ->get ('package ' );
167+ $ versionName = $ request ->attributes ->get ('version ' );
168+
169+ if (null === $ package = $ this ->findPackage ($ packageName )) {
170+ throw $ this ->createNotFoundException ();
171+ }
172+
173+ if (null === $ metadata = $ this ->metadataRepository ->findOneByNormalizedNameAndDistributionReference ($ package , $ versionName , $ reference )) {
174+ throw $ this ->createNotFoundException ();
175+ }
176+
177+ if (!$ this ->distributionResolver ->resolve ($ metadata , $ reference , $ type , async: $ this ->asyncApiRequests )) {
178+ throw $ this ->createNotFoundException ();
140179 }
141180
142- $ path = $ this ->distributionResolver ->path ($ packageName , $ versionName , $ reference , $ type );
181+ $ path = $ this ->distributionResolver ->path ($ metadata , $ reference , $ type );
143182 $ filename = u ("$ packageName- $ versionName- $ reference. $ type " )->replace ('/ ' , '- ' )->toString ();
144183
145184 return $ this ->file ($ path , $ filename );
0 commit comments