From 9eb467ad7245052377895dd9d81bf6e9d5908c3b Mon Sep 17 00:00:00 2001 From: PhilReact Date: Wed, 26 Mar 2025 22:47:20 +0200 Subject: [PATCH] fix name and identifier parsing --- package.json | 2 +- src/hooks/usePublish.tsx | 4 ++-- src/hooks/useResources.tsx | 6 +++--- src/state/auth.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 9569572..64dce5f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "qapp-core", - "version": "1.0.10", + "version": "1.0.11", "description": "Qortal's core React library with global state, UI components, and utilities", "main": "dist/index.js", "module": "dist/index.mjs", diff --git a/src/hooks/usePublish.tsx b/src/hooks/usePublish.tsx index 8e07c99..00fe3b3 100644 --- a/src/hooks/usePublish.tsx +++ b/src/hooks/usePublish.tsx @@ -28,7 +28,7 @@ export const usePublish = ( const [hasResource, setHasResource] = useState(null); const fetchRawData = useCallback(async (item: QortalGetMetadata) => { - const url = `/arbitrary/${item?.service}/${item?.name}/${item?.identifier}?encoding=base64`; + const url = `/arbitrary/${item?.service}/${encodeURIComponent(item?.name)}/${encodeURIComponent(item?.identifier)}?encoding=base64`; const res = await fetch(url); const data = await res.text(); if(returnType === 'BASE64'){ @@ -104,7 +104,7 @@ export const usePublish = ( resourceExists: true } } - const url = `/arbitrary/resources/search?mode=ALL&service=${metadataProp?.service}&limit=1&includemetadata=true&reverse=true&excludeblocked=true&name=${metadataProp?.name}&exactmatchnames=true&offset=0&identifier=${metadataProp?.identifier}`; + const url = `/arbitrary/resources/search?mode=ALL&service=${metadataProp?.service}&limit=1&includemetadata=true&reverse=true&excludeblocked=true&name=${encodeURIComponent(metadataProp?.name)}&exactmatchnames=true&offset=0&identifier=${encodeURIComponent(metadataProp?.identifier)}`; const responseMetadata = await fetch(url, { method: "GET", headers: { diff --git a/src/hooks/useResources.tsx b/src/hooks/useResources.tsx index 03301a0..445717f 100644 --- a/src/hooks/useResources.tsx +++ b/src/hooks/useResources.tsx @@ -88,7 +88,7 @@ export const useResources = (retryAttempts: number = 2) => { let metadata try { if (includeMetadata) { - const url = `/arbitrary/resources/search?mode=ALL&service=${item?.service}&limit=1&includemetadata=true&reverse=true&excludeblocked=true&name=${item?.name}&exactmatchnames=true&offset=0&identifier=${item?.identifier}`; + const url = `/arbitrary/resources/search?mode=ALL&service=${item?.service}&limit=1&includemetadata=true&reverse=true&excludeblocked=true&name=${encodeURIComponent(item?.name)}&exactmatchnames=true&offset=0&identifier=${encodeURIComponent(item?.identifier)}`; const response = await fetch(url, { method: "GET", headers: { @@ -109,7 +109,7 @@ export const useResources = (retryAttempts: number = 2) => { res = await requestQueueProductPublishes.enqueue( (): Promise => { return getArbitraryResource( - `/arbitrary/${item?.service}/${item?.name}/${item?.identifier}?encoding=base64`, + `/arbitrary/${item?.service}/${encodeURIComponent(item?.name)}/${encodeURIComponent(item?.identifier)}?encoding=base64`, key ); } @@ -132,7 +132,7 @@ export const useResources = (retryAttempts: number = 2) => { return await requestQueueProductPublishesBackup.enqueue( (): Promise => { return getArbitraryResource( - `/arbitrary/${item?.service}/${item?.name}/${item?.identifier}?encoding=base64`, + `/arbitrary/${item?.service}/${encodeURIComponent(item?.name)}/${encodeURIComponent(item?.identifier)}?encoding=base64`, key ); } diff --git a/src/state/auth.ts b/src/state/auth.ts index 8e1e7c5..cf293ca 100644 --- a/src/state/auth.ts +++ b/src/state/auth.ts @@ -38,7 +38,7 @@ export const useAuthStore = create((set) => ({ // Methods setUser: (user) => - set({ address: user.address, publicKey: user.publicKey, name: user.name || null, avatarUrl: !user?.name ? null : `/arbitrary/THUMBNAIL/${user.name}/qortal_avatar?async=true` }), + set({ address: user.address, publicKey: user.publicKey, name: user.name || null, avatarUrl: !user?.name ? null : `/arbitrary/THUMBNAIL/${encodeURIComponent(user.name)}/qortal_avatar?async=true` }), setBalance: (balance) => set({ balance }), setIsLoadingUser: (loading) => set({ isLoadingUser: loading }), setIsLoadingBalance: (loading) => set({ isLoadingInitialBalance: loading }),