@@ -11,6 +11,7 @@ import { CommandExecutionError } from './CommandExecutionError.ts'
1111import { prompt } from './lib.ts'
1212import process from "process" ;
1313import * as url from "node:url" ;
14+ import * as https from "node:https" ;
1415
1516const btoa = ( str : string ) => Buffer . from ( str , 'binary' ) . toString ( 'base64' )
1617const atob = ( str : string ) => Buffer . from ( str , 'base64' ) . toString ( 'binary' )
@@ -91,7 +92,7 @@ export async function createSecret(ncUrl: string, ncUser: string, secretFile: st
9192
9293 const result = await new Promise < string > ( ( resolve , reject ) => {
9394
94- const req = http . request (
95+ const req = http_client ( ncUrl ) . request (
9596 `${ ncUrl } /ocs/v2.php/apps/secrets/api/v1/secrets?format=json` ,
9697 rOptions ,
9798 ( response ) => {
@@ -201,7 +202,7 @@ export async function retrieveSecret(shareUrlStr: string, options: {
201202 }
202203
203204 const result = await new Promise < string > ( ( resolve , reject ) => {
204- const req = http . request (
205+ const req = http_client ( shareUrlStr ) . request (
205206 `${ baseUrl } /ocs/v2.php/apps/secrets/api/v1/share?format=json` ,
206207 reqOptions ,
207208 ( response ) => {
@@ -238,13 +239,23 @@ export async function retrieveSecret(shareUrlStr: string, options: {
238239
239240}
240241
242+ function http_client ( url : string ) : any {
243+
244+ let http_client = http
245+ if ( url . startsWith ( "https:" ) ) {
246+ http_client = https
247+ }
248+
249+ return http_client
250+ }
251+
241252/**
242253 * @param ncUrl
243254 */
244255async function getApiInfo ( ncUrl : string ) : Promise < string > {
245256
246257 const result = await new Promise < string > ( ( resolve , reject ) => {
247- const req = http . request ( `${ ncUrl } /ocs/v2.php/apps/secrets/version?format=json` ,
258+ const req = http_client ( ncUrl ) . request ( `${ ncUrl } /ocs/v2.php/apps/secrets/version?format=json` ,
248259 {
249260 method : 'GET' ,
250261 headers : {
0 commit comments