2727
2828use OCA \Recognize \Helper \TAR ;
2929use OCP \AppFramework \Services \IAppConfig ;
30+ use OCP \IConfig ;
3031use OCP \Http \Client \IClientService ;
3132use OCP \IBinaryFinder ;
3233use OCP \Migration \IOutput ;
@@ -39,6 +40,7 @@ final class InstallDeps implements IRepairStep {
3940 public const NODE_SERVER_UNOFFICIAL = 'https://unofficial-builds.nodejs.org/download/release/ ' ;
4041
4142 protected IAppConfig $ config ;
43+ private IConfig $ systemConfig ;
4244 private string $ binaryDir ;
4345 private string $ preGypBinaryDir ;
4446 private string $ ffmpegDir ;
@@ -52,8 +54,9 @@ final class InstallDeps implements IRepairStep {
5254 private IBinaryFinder $ binaryFinder ;
5355 private string $ nodeModulesDir ;
5456
55- public function __construct (IAppConfig $ config , IClientService $ clientService , LoggerInterface $ logger , IBinaryFinder $ binaryFinder ) {
57+ public function __construct (IAppConfig $ config , IConfig $ systemConfig , IClientService $ clientService , LoggerInterface $ logger , IBinaryFinder $ binaryFinder ) {
5658 $ this ->config = $ config ;
59+ $ this ->systemConfig = $ systemConfig ;
5760 $ this ->binaryDir = dirname (__DIR__ , 2 ) . '/bin/ ' ;
5861 $ this ->nodeModulesDir = dirname (__DIR__ , 2 ) . '/node_modules/ ' ;
5962 $ this ->preGypBinaryDir = dirname (__DIR__ , 2 ) . '/node_modules/@mapbox/node-pre-gyp/bin/ ' ;
@@ -185,10 +188,25 @@ protected function testBinary(string $binaryPath): ?string {
185188 return trim (implode ("\n" , $ output ));
186189 }
187190
191+
192+ /**
193+ * Build proxy environment variable prefix from Nextcloud system config.
194+ *
195+ * @return string Empty string or "HTTPS_PROXY=... HTTP_PROXY=... " prefix
196+ */
197+ protected function getProxyEnv () : string {
198+ $ proxy = $ this ->systemConfig ->getSystemValueString ('proxy ' , '' );
199+ if ($ proxy === '' ) {
200+ return '' ;
201+ }
202+ return 'HTTPS_PROXY= ' . escapeshellarg ($ proxy ) . ' '
203+ . 'HTTP_PROXY= ' . escapeshellarg ($ proxy ) . ' ' ;
204+ }
205+
188206 protected function runTfjsInstall (string $ nodeBinary ) : void {
189207 $ oriCwd = getcwd ();
190208 chdir ($ this ->tfjsPath );
191- $ cmd = 'PATH= ' .escapeshellcmd ($ this ->preGypBinaryDir ).': ' .escapeshellcmd ($ this ->binaryDir ).':$PATH ' . escapeshellcmd ($ nodeBinary ) . ' ' . escapeshellarg ($ this ->tfjsInstallScript ) . ' cpu ' . escapeshellarg ('download ' );
209+ $ cmd = $ this -> getProxyEnv () . 'PATH= ' .escapeshellcmd ($ this ->preGypBinaryDir ).': ' .escapeshellcmd ($ this ->binaryDir ).':$PATH ' . escapeshellcmd ($ nodeBinary ) . ' ' . escapeshellarg ($ this ->tfjsInstallScript ) . ' cpu ' . escapeshellarg ('download ' );
192210 try {
193211 exec ($ cmd . ' 2>&1 ' , $ output , $ returnCode ); // Appending 2>&1 to avoid leaking sterr
194212 } catch (\Throwable $ e ) {
@@ -205,7 +223,7 @@ protected function runTfjsInstall(string $nodeBinary) : void {
205223 protected function runTfjsGpuInstall (string $ nodeBinary ) : void {
206224 $ oriCwd = getcwd ();
207225 chdir ($ this ->tfjsGPUPath );
208- $ cmd = 'PATH= ' .escapeshellcmd ($ this ->preGypBinaryDir ).': ' .escapeshellcmd ($ this ->binaryDir ).':$PATH ' . escapeshellcmd ($ nodeBinary ) . ' ' . escapeshellarg ($ this ->tfjsGpuInstallScript ) . ' gpu ' . escapeshellarg ('download ' );
226+ $ cmd = $ this -> getProxyEnv () . 'PATH= ' .escapeshellcmd ($ this ->preGypBinaryDir ).': ' .escapeshellcmd ($ this ->binaryDir ).':$PATH ' . escapeshellcmd ($ nodeBinary ) . ' ' . escapeshellarg ($ this ->tfjsGpuInstallScript ) . ' gpu ' . escapeshellarg ('download ' );
209227 try {
210228 exec ($ cmd . ' 2>&1 ' , $ output , $ returnCode ); // Appending 2>&1 to avoid leaking sterr
211229 } catch (\Throwable $ e ) {
@@ -222,7 +240,7 @@ protected function runTfjsGpuInstall(string $nodeBinary) : void {
222240 protected function runFfmpegInstall (string $ nodeBinary ): void {
223241 $ oriCwd = getcwd ();
224242 chdir ($ this ->ffmpegDir );
225- $ cmd = escapeshellcmd ($ nodeBinary ) . ' ' . escapeshellarg ($ this ->ffmpegInstallScript );
243+ $ cmd = $ this -> getProxyEnv () . escapeshellcmd ($ nodeBinary ) . ' ' . escapeshellarg ($ this ->ffmpegInstallScript );
226244 try {
227245 exec ($ cmd . ' 2>&1 ' , $ output , $ returnCode ); // Appending 2>&1 to avoid leaking sterr
228246 } catch (\Throwable $ e ) {
0 commit comments