Bläddra i källkod

mercure functional in anonymous mode

Olivier Massot 3 år sedan
förälder
incheckning
64c57d930d
3 ändrade filer med 33 tillägg och 15 borttagningar
  1. 2 2
      .env.local
  2. 4 2
      config/nuxtConfig/env.js
  3. 27 11
      pages/cmf_licence/organization.vue

+ 2 - 2
.env.local

@@ -19,6 +19,6 @@ SSR_TYPO3_BASE_URL=https://local.sub.opentalent.fr/###subDomain###
 CLIENT_TYPO3_BASE_URL=https://local.sub.opentalent.fr/###subDomain###
 
 # Mercure push events
-MERCURE_URL=http://local.mercure.opentalent.fr/.well-known/mercure
+MERCURE_URL=https://local.mercure.opentalent.fr/.well-known/mercure
 MERCURE_PUBLIC_URL=https://local.mercure.opentalent.fr/.well-known/mercure
-MERCURE_JWT_SECRET="8Kimwk38Kpv@JN04vE,iXM"
+MERCURE_JWT_SECRET=UfQm7bdbXSO0TDnxGREM6BPtwUgls7ZWJhAl21VsuwW8rSvyHG3yqOkPEpr9sEmo

+ 4 - 2
config/nuxtConfig/env.js

@@ -22,7 +22,8 @@ export default {
     },
     baseURL_Legacy: process.env.CLIENT_APILEG_BASE_URL,
     baseURL_adminLegacy: process.env.CLIENT_ADMINLEG_BASE_URL,
-    baseURL_typo3: process.env.CLIENT_TYPO3_BASE_URL
+    baseURL_typo3: process.env.CLIENT_TYPO3_BASE_URL,
+    baseUrl_mercure: process.env.MERCURE_URL
   },
   privateRuntimeConfig: {
     http: {
@@ -34,6 +35,7 @@ export default {
     },
     baseURL_Legacy: process.env.SSR_APILEG_BASE_URL,
     baseURL_adminLegacy: process.env.SSR_ADMINLEG_BASE_URL,
-    baseURL_typo3: process.env.SSR_TYPO3_BASE_URL
+    baseURL_typo3: process.env.SSR_TYPO3_BASE_URL,
+    baseUrl_mercure: process.env.MERCURE_URL
   }
 }

+ 27 - 11
pages/cmf_licence/organization.vue

@@ -12,15 +12,19 @@
       ref="form"
       lazy-validation
     >
-
       <v-btn class="ma-12" @click="submit">{{ $t('generate') }}</v-btn>
-
     </v-form>
+    <span v-if="pending">
+      Loading...
+    </span>
+    <span v-if="fileUrl !== null">
+      <a :href="fileUrl">{{ fileUrl }}</a>
+    </span>
   </div>
 </template>
 
 <script lang="ts">
-import {defineComponent, useContext} from "@nuxtjs/composition-api";
+import {defineComponent, Ref, ref, useContext} from "@nuxtjs/composition-api";
 import {HTTP_METHOD, QUERY_TYPE} from "~/types/enums";
 import DataPersister from "~/services/data/dataPersister";
 import {DataPersisterArgs} from "~/types/interfaces";
@@ -28,23 +32,35 @@ import {DataPersisterArgs} from "~/types/interfaces";
 export default defineComponent({
   name: 'OrganizationCmfLicence',
   setup() {
+    const { $config } = useContext()
+    let pending: Ref<boolean> = ref(false)
+    let fileUrl: Ref<string | null> = ref(null)
+    console.log($config.baseUrl_mercure)
     const submit = async () => {
+
+      const url = new URL($config.baseUrl_mercure)
+      url.searchParams.append('topic', "files")
+      // const eventSource = new EventSource(url.toString(), { withCredentials: true });
+      const eventSource = new EventSource(url.toString());
+      eventSource.onmessage = event => {
+        // Will be called every time an update is published by the server
+        const data = JSON.parse(event.data)
+        fileUrl.value = data.url
+        pending.value = false
+      }
+
       const response = await DataPersister.request(
         '/api/export/cmf-licence/organization',
         HTTP_METHOD.POST,
         { type: QUERY_TYPE.DEFAULT, data: { format: 'pdf', async: true } } as DataPersisterArgs
       )
-      console.debug(response)
-
-      const eventSource = new EventSource("https://local.mercure.opentalent.fr/.well-known/mercure/ui/files/602066");
-      eventSource.onmessage = event => {
-        // Will be called every time an update is published by the server
-        console.log(JSON.parse(event.data));
-      }
+      pending.value = true
     }
 
     return {
-      submit
+      submit,
+      pending,
+      fileUrl
     }
   }
 })