diff --git a/src/app/Shared/Services/Api.service.tsx b/src/app/Shared/Services/Api.service.tsx index 6d9580f54..8d6d63ae0 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'; @@ -503,18 +503,20 @@ 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`, { - method: 'POST', - }).pipe( + return this.sendRequest( + 'beta', + `fs/recordings/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/upload`, + { + method: 'POST', + }, + ).pipe( map((resp) => resp.ok), first(), ); } 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/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}`, { method: 'DELETE', }).pipe( map((resp) => resp.ok), @@ -531,10 +533,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/${encodeURIComponent(jvmId)}/${encodeURIComponent(recordingName)}/metadata/labels`, { method: 'POST', body: this.transformAndStringifyToRawLabels(labels), diff --git a/src/app/utils/utils.ts b/src/app/utils/utils.ts index ac91cdc97..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'; @@ -248,42 +247,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());