From 77f5651fc6c7053a305b0b563bfc7268d2cccd1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Thu, 17 Oct 2024 11:17:20 +0200 Subject: [PATCH 1/3] feature/Add VITE_OBP_REDIS_USERNAME env property --- package.json | 2 +- server/app.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index ac880c5..f72be63 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "api-explorer", - "version": "1.0.20", + "version": "1.0.21", "private": true, "scripts": { "dev": "vite & ts-node server/app.ts", diff --git a/server/app.ts b/server/app.ts index 23dfff5..46e3ba6 100644 --- a/server/app.ts +++ b/server/app.ts @@ -44,15 +44,25 @@ process.env.VITE_OBP_REDIS_URL ? console.log(`VITE_OBP_REDIS_URL: ${process.env.VITE_OBP_REDIS_URL}`) : console.log(`VITE_OBP_REDIS_URL: undefined connects to localhost on port 6379`) -const redisPassword = process.env.VITE_OBP_REDIS_PASSWORD +const redisPassword = process.env.VITE_OBP_REDIS_PASSWORD ? process.env.VITE_OBP_REDIS_PASSWORD // Redis instance is protected with a password : '' // Specify an empty password (i.e., no password) when connecting to Redis -if(!redisPassword) { +if (!redisPassword) { console.warn(`VITE_OBP_REDIS_PASSWORD is not provided.`) } +const redisUsername = process.env.VITE_OBP_REDIS_USERNAME + ? process.env.VITE_OBP_REDIS_USERNAME // Redis instance is protected with a username/password + : '' // Specify an empty username (i.e., no username) when connecting to Redis +if (!redisUsername) { + console.warn(`VITE_OBP_REDIS_USERNAME is not provided.`) +} console.log(`-----------------------------------------------------------------`) const redisClient = process.env.VITE_OBP_REDIS_URL - ? createClient({ url: process.env.VITE_OBP_REDIS_URL, password: redisPassword }) + ? createClient({ + url: process.env.VITE_OBP_REDIS_URL, + username: redisUsername, + password: redisPassword + }) : createClient() redisClient.connect().catch(console.error) From 73cb983cecf1e9572697ef0db3dac53188a9d302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Mili=C4=87?= Date: Fri, 8 Nov 2024 09:00:30 +0100 Subject: [PATCH 2/3] feature/Add copy to clipboard for successful response --- package.json | 2 +- src/components/Preview.vue | 42 +++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 35300ee..85f86d1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name": "api-explorer", "version": "1.0.20", - "type": "module", "private": true, "scripts": { "dev": "vite & ts-node server/app.ts", @@ -19,6 +18,7 @@ "@fontsource/roboto": "^5.0.0", "@highlightjs/vue-plugin": "^2.1.0", "axios": "^1.7.2", + "cheerio": "^1.0.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "connect-redis": "^7.1.1", diff --git a/src/components/Preview.vue b/src/components/Preview.vue index b6458e6..2c493b3 100644 --- a/src/components/Preview.vue +++ b/src/components/Preview.vue @@ -29,9 +29,10 @@ import { ref, reactive, inject, onBeforeMount } from 'vue' import { onBeforeRouteUpdate, useRoute } from 'vue-router' import { getOperationDetails } from '../obp/resource-docs' -import type { ElNotification, FormInstance } from 'element-plus' +import { ElNotification, FormInstance } from 'element-plus' import { OBP_API_VERSION, get, create, update, discard, createEntitlement, getCurrentUser } from '../obp' import { obpResourceDocsKey } from '@/obp/keys' +import * as cheerio from 'cheerio' const elMessageDuration = 5500 const configVersion = 'OBP' + OBP_API_VERSION @@ -202,6 +203,39 @@ onBeforeRouteUpdate((to) => { responseHeaderTitle.value = 'TYPICAL SUCCESSFUL RESPONSE' setRoleForm() }) + +const copyToClipboard = () => { + // Create a temporary text area to hold the content + const textArea = document.createElement('textarea'); + + // Parse the HTML content with Cheerio + const $ = cheerio.load(successResponseBody.value); + + // Extract all JSON lines + const jsonLines: string[] = []; + $('.hljs-ln-code').each((_, element) => { + jsonLines.push($(element).text()); + }); + + // Combine lines to form raw JSON + const rawJson = jsonLines.join('\n'); + console.log(rawJson); + + textArea.value = rawJson; // Set the text to copy + document.body.appendChild(textArea); // Append the text area to the DOM + textArea.select(); // Select the text inside the text area + document.execCommand('copy'); // Execute the copy command + document.body.removeChild(textArea); // Remove the text area from the DOM + + // Show feedback to the user + ElNotification({ + message: 'Response copied to clipboard!', + type: 'success', + duration: elMessageDuration + }); +}; + +