From 38641a279fc6736077a96d20844801167c482558 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 3 Mar 2025 11:45:23 -0500 Subject: [PATCH 1/2] #388 - Fix issue with importing script files from GitHub repo --- .../df-scripts-github-dialog.component.html | 6 +++--- .../df-scripts-github-dialog.component.ts | 21 ++----------------- .../shared/services/df-base-crud.service.ts | 17 ++++++++++++--- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html index f04f14af..f71eab53 100644 --- a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html +++ b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.html @@ -20,12 +20,12 @@

Import a script file from GitHub

type="text" /> - GitHub Password + GitHub Token + placeholder="Personal Access Token" + type="text" /> diff --git a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts index 8767ead0..a7cd63ed 100644 --- a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts +++ b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts @@ -124,26 +124,9 @@ export class DfScriptsGithubDialogComponent implements OnInit { const githubApiEndpoint = `${this.repoOwner}/${this.repoName}/contents/${this.fileName}`; - const authData = window.btoa( - this.formGroup.value.username + ':' + this.formGroup.value.password - ); - - const headers: KeyValuePair[] = this.isGitRepoPrivate - ? [ - { - key: 'Authorization', - value: `Basic ${authData}`, - }, - ] - : []; - this.githubService - .get(githubApiEndpoint, { - additionalParams: [{ key: 'ref', value: 'main' }], - additionalHeaders: [...headers], - }) - - .subscribe(data => { + .getFileContent(githubApiEndpoint, this.formGroup.value.username, this.formGroup.value.password) + .subscribe((data: any) => { this.dialogRef.close({ data: data }); }); } diff --git a/src/app/shared/services/df-base-crud.service.ts b/src/app/shared/services/df-base-crud.service.ts index d19698f0..f9cd6779 100644 --- a/src/app/shared/services/df-base-crud.service.ts +++ b/src/app/shared/services/df-base-crud.service.ts @@ -1,4 +1,4 @@ -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { RequestOptions } from 'src/app/shared/types/generic-http'; import { readAsText } from 'src/app/shared/utilities/file'; import { map, switchMap } from 'rxjs'; @@ -31,6 +31,17 @@ export class DfBaseCrudService { ); } + getFileContent(id: string, username?: string, token?: string) { + let headers = new HttpHeaders(); + if (username && token) { + headers = headers.set( + 'Authorization', + 'Basic ' + btoa(`${username}:${token}`) + ); + } + return this.http.get(`${this.url}/${id}`, { headers }); + } + getEventScripts() { return this.http.get( '/api/v2/system/event_script', @@ -86,8 +97,8 @@ export class DfBaseCrudService { const url = Array.isArray(id) ? `${this.url}?ids=${id.join(',')}` : id - ? `${this.url}/${id}` - : `${this.url}`; + ? `${this.url}/${id}` + : `${this.url}`; return this.http.delete( url, this.getOptions({ snackbarError: 'server', ...options }) From 250627a1ac55af34b6dba54892226bba1115ffd3 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 3 Mar 2025 11:47:17 -0500 Subject: [PATCH 2/2] #388 - Fix issue with importing script files from GitHub repo --- .../df-scripts-github-dialog.component.ts | 6 +++++- src/app/shared/services/df-base-crud.service.ts | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts index a7cd63ed..2437765c 100644 --- a/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts +++ b/src/app/shared/components/df-scripts-github-dialog/df-scripts-github-dialog.component.ts @@ -125,7 +125,11 @@ export class DfScriptsGithubDialogComponent implements OnInit { const githubApiEndpoint = `${this.repoOwner}/${this.repoName}/contents/${this.fileName}`; this.githubService - .getFileContent(githubApiEndpoint, this.formGroup.value.username, this.formGroup.value.password) + .getFileContent( + githubApiEndpoint, + this.formGroup.value.username, + this.formGroup.value.password + ) .subscribe((data: any) => { this.dialogRef.close({ data: data }); }); diff --git a/src/app/shared/services/df-base-crud.service.ts b/src/app/shared/services/df-base-crud.service.ts index f9cd6779..919669ed 100644 --- a/src/app/shared/services/df-base-crud.service.ts +++ b/src/app/shared/services/df-base-crud.service.ts @@ -97,8 +97,8 @@ export class DfBaseCrudService { const url = Array.isArray(id) ? `${this.url}?ids=${id.join(',')}` : id - ? `${this.url}/${id}` - : `${this.url}`; + ? `${this.url}/${id}` + : `${this.url}`; return this.http.delete( url, this.getOptions({ snackbarError: 'server', ...options })