Accept . as a query string delimiter.

This commit is contained in:
Dermot Duffy
2023-09-06 21:22:21 -07:00
parent 97dac5332b
commit 568a5cea35
5 changed files with 125 additions and 13 deletions
+4 -2
View File
@@ -749,7 +749,7 @@ class FrigateCard extends LitElement {
// the default view and the querystring view, see:
// https://github.com/dermotduffy/frigate-hass-card/issues/1200
if (!this._view) {
const querystringActions = getActionsFromQueryString();
const querystringActions = getActionsFromQueryString(window.location.search);
if (
!querystringActions.find(
(action) =>
@@ -1594,7 +1594,9 @@ class FrigateCard extends LitElement {
protected _locationChangeHandler = (): void => {
// Only execute actions when the card has rendered at least once.
if (this.hasUpdated) {
getActionsFromQueryString().forEach((action) => this._cardActionHandler(action));
getActionsFromQueryString(window.location.search).forEach((action) =>
this._cardActionHandler(action),
);
}
};
+4 -1
View File
@@ -217,7 +217,10 @@ const frigateCardCustomActionsBaseSchema = customActionSchema.extend({
.or(z.literal('fire-dom-event')),
// Card this command is intended for.
card_id: z.string().optional(),
card_id: z
.string()
.regex(/^\w+$/, 'card_id parameter can only contain [a-z][A-Z][0-9_]')
.optional(),
});
const FRIGATE_CARD_GENERAL_ACTIONS = [
+7 -4
View File
@@ -1,11 +1,14 @@
import { FrigateCardCustomAction } from '../types';
import { createFrigateCardCustomAction } from './action.js';
export const getActionsFromQueryString = (): FrigateCardCustomAction[] => {
const params = new URLSearchParams(window.location.search);
export const getActionsFromQueryString = (
queryString: string,
): FrigateCardCustomAction[] => {
const params = new URLSearchParams(queryString);
const actions: FrigateCardCustomAction[] = [];
const actionRE = new RegExp(/^frigate-card-action(:(?<cardID>\w+))?:(?<action>\w+)/);
const actionRE = new RegExp(
/^frigate-card-action([.:](?<cardID>\w+))?[.:](?<action>\w+)/,
);
for (const [key, value] of params.entries()) {
const match = key.match(actionRE);
if (!match || !match.groups) {