Skip to content

Commit

Permalink
add support for debugging filters with all unicode characters
Browse files Browse the repository at this point in the history
  • Loading branch information
moscicky committed Apr 30, 2024
1 parent 6dd3829 commit ebc5db9
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ContentType } from '@/api/content-type';
import { dispatchErrorNotification } from '@/utils/notification-utils';
import type { FetchTopicContentType } from '@/composables/topic/use-topic/useTopic';
import { fetchContentType } from '@/composables/topic/use-topic/useTopic';

Check warning on line 4 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Expected type imports 'after' all other imports

Check warning on line 4 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Expected type imports 'after' all other imports
import type { Ref } from 'vue';
import { ref } from 'vue';

Check warning on line 6 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Expected type imports 'after' all other imports

Check warning on line 6 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Expected type imports 'after' all other imports
import { useGlobalI18n } from '@/i18n';
import { useNotificationsStore } from '@/store/app-notifications/useAppNotifications';
import { VerificationStatus } from '@/api/message-filters-verification';
import { verifyFilters } from '@/api/hermes-client';
import type { FetchTopicContentType } from '@/composables/topic/use-topic/useTopic';
import type { PathFilter } from '@/views/subscription/subscription-form/subscription-basic-filters/types';
import type { PathFilterJson } from '@/api/subscription';
import type { Ref } from 'vue';

export interface UseSubscriptionFiltersDebug {
status: Ref<VerificationStatus | undefined>;
Expand All @@ -35,6 +35,15 @@ const toFiltersJSON = (
};
};

// https://stackoverflow.com/a/30106551
function b64EncodeUnicode(str: string): string {
return btoa(
encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {

Check failure on line 41 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`

Check failure on line 41 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`
return String.fromCharCode(parseInt(p1, 16));

Check failure on line 42 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`

Check failure on line 42 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`
}),

Check failure on line 43 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`

Check failure on line 43 in hermes-console/src/composables/subscription/use-subscription-filters-debug/useSubscriptionFiltersDebug.ts

View workflow job for this annotation

GitHub Actions / build

Delete `··`
);
}

export function useSubscriptionFiltersDebug(): UseSubscriptionFiltersDebug {
const notificationStore = useNotificationsStore();
const status: Ref<VerificationStatus | undefined> = ref();
Expand All @@ -52,7 +61,7 @@ export function useSubscriptionFiltersDebug(): UseSubscriptionFiltersDebug {
);
const response = (
await verifyFilters(topicName, {
message: btoa(message),
message: b64EncodeUnicode(message),
filters: filtersJSON,
})
).data;
Expand Down

0 comments on commit ebc5db9

Please sign in to comment.