Переглянути джерело

feat: make the name in remove cookie optional

Ahmad Kholid 2 роки тому
батько
коміт
35e83dc1e1

+ 13 - 1
src/background/workflowEngine/blocksHandler/handlerCookie.js

@@ -51,7 +51,19 @@ async function cookie({ data, id }) {
     values.expirationDate = Date.now() / 1000 + +values.expirationDate;
   }
 
-  const result = await browser.cookies[key](values);
+  let result = null;
+
+  if (data.type === 'remove' && !data.name) {
+    const cookies = await browser.cookies.getAll({ url: data.url });
+    const removePromise = cookies.map(({ name }) =>
+      browser.cookies.remove({ name, url: data.url })
+    );
+    await Promise.allSettled(removePromise);
+
+    result = cookies;
+  } else {
+    result = await browser.cookies[key](values);
+  }
 
   if (data.type === 'get') {
     if (data.assignVariable) {

+ 3 - 2
src/components/newtab/workflow/edit/EditCookie.vue

@@ -34,7 +34,9 @@
       />
       <ui-input
         :model-value="data.name"
-        :label="`Name ${isOptional(isGetOrSet)}`"
+        :label="`Name ${
+          data.type === 'get' && !data.getAll ? '' : '(optional)'
+        }`"
         class="mt-2 w-full"
         placeholder="site-cookie"
         @change="updateData({ name: $event })"
@@ -129,7 +131,6 @@ const { t } = useI18n();
 const permission = useHasPermissions(['cookies']);
 
 const types = ['get', 'set', 'remove'];
-const isOptional = (optional = false) => (optional ? '(optional)' : '');
 
 const isGetOrSet = computed(
   () =>