From 94feccaf3a27ffdc70422e1f2d8d1f64b9f20187 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Mon, 2 Oct 2023 14:40:04 -0400 Subject: [PATCH 1/5] remove subdirectory for recording requests --- src/app/Shared/Services/Api.service.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 6d9580f54..a597065d5 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -503,8 +503,7 @@ export class ApiService { // from file system path functions uploadArchivedRecordingToGrafanaFromPath(jvmId: string, recordingName: string): Observable { - const subdirectoryName = jvmIdToSubdirectoryName(jvmId); - return this.sendRequest('beta', `fs/recordings/${subdirectoryName}/${encodeURIComponent(recordingName)}/upload`, { + return this.sendRequest('beta', `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}/upload`, { method: 'POST', }).pipe( map((resp) => resp.ok), @@ -513,8 +512,7 @@ export class ApiService { } deleteArchivedRecordingFromPath(jvmId: string, recordingName: string): Observable { - const subdirectoryName = jvmIdToSubdirectoryName(jvmId); - return this.sendRequest('beta', `fs/recordings/${subdirectoryName}/${encodeURIComponent(recordingName)}`, { + return this.sendRequest('beta', `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}`, { method: 'DELETE', }).pipe( map((resp) => resp.ok), @@ -531,10 +529,9 @@ export class ApiService { } postRecordingMetadataFromPath(jvmId: string, recordingName: string, labels: RecordingLabel[]): Observable { - const subdirectoryName = jvmIdToSubdirectoryName(jvmId); return this.sendRequest( 'beta', - `fs/recordings/${subdirectoryName}/${encodeURIComponent(recordingName)}/metadata/labels`, + `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}/metadata/labels`, { method: 'POST', body: this.transformAndStringifyToRawLabels(labels), From 6f4f395771d9dfa4466e6453c0eeec954f0a6898 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Mon, 2 Oct 2023 14:50:17 -0400 Subject: [PATCH 2/5] remove unused functions --- src/app/Shared/Services/Api.service.tsx | 2 +- src/app/utils/utils.ts | 37 ------------------------- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index a597065d5..997ecf102 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -16,7 +16,7 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { LayoutTemplate, SerialLayoutTemplate } from '@app/Dashboard/types'; import { RecordingLabel } from '@app/RecordingMetadata/types'; -import { createBlobURL, jvmIdToSubdirectoryName } from '@app/utils/utils'; +import { createBlobURL } from '@app/utils/utils'; import { ValidatedOptions } from '@patternfly/react-core'; import _ from 'lodash'; import { EMPTY, forkJoin, from, Observable, ObservableInput, of, ReplaySubject, shareReplay, throwError } from 'rxjs'; diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index ac91cdc97..c1ad13863 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -248,42 +248,5 @@ export const isAssetNew = (currVer: string) => { return !semverValid(oldVer) || semverGt(currVer, oldVer); }; -export const utf8ToBase32 = (str: string): string => { - const encoder = new TextEncoder(); - const byteArray = encoder.encode(str); - const BASE32_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'; - let bits = 0; - let value = 0; - let base32 = ''; - - for (let i = 0; i < byteArray.length; i++) { - value = (value << 8) | byteArray[i]; - bits += 8; - while (bits >= 5) { - bits -= 5; - base32 += BASE32_ALPHABET[(value >>> bits) & 0x1f]; - } - } - - if (bits > 0) { - value <<= 5 - bits; - base32 += BASE32_ALPHABET[value & 0x1f]; - } - - const paddingLength = base32.length % 8 !== 0 ? 8 - (base32.length % 8) : 0; - for (let i = 0; i < paddingLength; i++) { - base32 += '='; - } - - return base32; -}; - -export const jvmIdToSubdirectoryName = (jvmId: string): string => { - if (jvmId === UPLOADS_SUBDIRECTORY || jvmId === 'lost') { - return jvmId; - } - return utf8ToBase32(jvmId); -}; - export const includesSubstr = (a: string, b: string): boolean => !!a && !!b && a.toLowerCase().includes(b.trim().toLowerCase()); From a29011a37cb7dd555f5858f41e6ca2d08c998f01 Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Tue, 3 Oct 2023 15:05:27 -0400 Subject: [PATCH 3/5] clean up --- src/app/Shared/Services/Api.service.tsx | 12 ++++-------- src/app/utils/utils.ts | 1 - 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 997ecf102..3b4152e69 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -529,14 +529,10 @@ export class ApiService { } postRecordingMetadataFromPath(jvmId: string, recordingName: string, labels: RecordingLabel[]): Observable { - return this.sendRequest( - 'beta', - `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}/metadata/labels`, - { - method: 'POST', - body: this.transformAndStringifyToRawLabels(labels), - }, - ).pipe( + return this.sendRequest('beta', `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}/metadata/labels`, { + method: 'POST', + body: this.transformAndStringifyToRawLabels(labels), + }).pipe( map((resp) => resp.ok), first(), ); diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index c1ad13863..a684c48fe 100644 --- a/src/app/utils/utils.ts +++ b/src/app/utils/utils.ts @@ -14,7 +14,6 @@ * limitations under the License. */ -import { UPLOADS_SUBDIRECTORY } from '@app/Shared/Services/api.types'; import { ISortBy, SortByDirection } from '@patternfly/react-table'; import _ from 'lodash'; import { NavigateFunction } from 'react-router-dom'; From 5ef6627f799fa1110155aef50609a36f459107ae Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Fri, 20 Oct 2023 11:52:37 -0400 Subject: [PATCH 4/5] encodeURIComponent jvmId --- src/app/Shared/Services/Api.service.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 3b4152e69..f72bad8d0 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -503,7 +503,7 @@ export class ApiService { // from file system path functions uploadArchivedRecordingToGrafanaFromPath(jvmId: string, recordingName: string): Observable { - return this.sendRequest('beta', `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}/upload`, { + return this.sendRequest('beta', `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/upload`, { method: 'POST', }).pipe( map((resp) => resp.ok), @@ -512,7 +512,7 @@ export class ApiService { } deleteArchivedRecordingFromPath(jvmId: string, recordingName: string): Observable { - return this.sendRequest('beta', `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}`, { + return this.sendRequest('beta', `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}`, { method: 'DELETE', }).pipe( map((resp) => resp.ok), @@ -529,7 +529,7 @@ export class ApiService { } postRecordingMetadataFromPath(jvmId: string, recordingName: string, labels: RecordingLabel[]): Observable { - return this.sendRequest('beta', `fs/recordings/${jvmId}/${encodeURIComponent(recordingName)}/metadata/labels`, { + return this.sendRequest('beta', `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/metadata/labels`, { method: 'POST', body: this.transformAndStringifyToRawLabels(labels), }).pipe( From a5ee6d76868e76184bcb0c0f956f8a17e9e43d1c Mon Sep 17 00:00:00 2001 From: Ming Wang Date: Fri, 20 Oct 2023 11:55:24 -0400 Subject: [PATCH 5/5] cleanup --- src/app/Shared/Services/Api.service.tsx | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index f72bad8d0..8d6d63ae0 100644 --- a/src/app/Shared/Services/Api.service.tsx +++ b/src/app/Shared/Services/Api.service.tsx @@ -503,9 +503,13 @@ export class ApiService { // from file system path functions uploadArchivedRecordingToGrafanaFromPath(jvmId: string, recordingName: string): Observable { - return this.sendRequest('beta', `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/upload`, { - method: 'POST', - }).pipe( + return this.sendRequest( + 'beta', + `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/upload`, + { + method: 'POST', + }, + ).pipe( map((resp) => resp.ok), first(), ); @@ -529,10 +533,14 @@ export class ApiService { } postRecordingMetadataFromPath(jvmId: string, recordingName: string, labels: RecordingLabel[]): Observable { - return this.sendRequest('beta', `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/metadata/labels`, { - method: 'POST', - body: this.transformAndStringifyToRawLabels(labels), - }).pipe( + return this.sendRequest( + 'beta', + `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/metadata/labels`, + { + method: 'POST', + body: this.transformAndStringifyToRawLabels(labels), + }, + ).pipe( map((resp) => resp.ok), first(), );