Skip to content

Commit

Permalink
chore(recordings): remove subdirectory for jvmId in recording requests (
Browse files Browse the repository at this point in the history
#1127) (#1150)

(cherry picked from commit bf9af76)

Co-authored-by: Ming Yu Wang <[email protected]>
  • Loading branch information
mergify[bot] and mwangggg authored Oct 30, 2023
1 parent 2cc2d37 commit b56456d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 47 deletions.
19 changes: 10 additions & 9 deletions src/app/Shared/Services/Api.service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -503,18 +503,20 @@ export class ApiService {

// from file system path functions
uploadArchivedRecordingToGrafanaFromPath(jvmId: string, recordingName: string): Observable<boolean> {
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<boolean> {
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),
Expand All @@ -531,10 +533,9 @@ export class ApiService {
}

postRecordingMetadataFromPath(jvmId: string, recordingName: string, labels: RecordingLabel[]): Observable<boolean> {
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),
Expand Down
38 changes: 0 additions & 38 deletions src/app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 { useHistory } from 'react-router-dom';
Expand Down Expand Up @@ -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());

0 comments on commit b56456d

Please sign in to comment.