From 641f92da4a5b797b652f07d4b924b34eb52b7f01 Mon Sep 17 00:00:00 2001 From: amvanbaren Date: Tue, 28 Jan 2025 13:30:11 +0200 Subject: [PATCH] Use detailsUrl to update namespace details --- .../java/org/eclipse/openvsx/UserAPI.java | 1 + .../eclipse/openvsx/json/NamespaceJson.java | 11 ++++++++ webui/src/extension-registry-service.ts | 7 +++-- webui/src/extension-registry-types.ts | 1 + .../src/pages/user/user-namespace-details.tsx | 4 +-- .../user/user-settings-namespace-detail.tsx | 26 ++++++++++--------- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/server/src/main/java/org/eclipse/openvsx/UserAPI.java b/server/src/main/java/org/eclipse/openvsx/UserAPI.java index a9e12d53..1ed50c1f 100644 --- a/server/src/main/java/org/eclipse/openvsx/UserAPI.java +++ b/server/src/main/java/org/eclipse/openvsx/UserAPI.java @@ -230,6 +230,7 @@ public List getOwnNamespaces() { if(isOwner) { json.setMembersUrl(createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "members")); json.setRoleUrl(createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "role")); + json.setDetailsUrl(createApiUrl(serverUrl, "user", "namespace", namespace.getName(), "details")); } return json; diff --git a/server/src/main/java/org/eclipse/openvsx/json/NamespaceJson.java b/server/src/main/java/org/eclipse/openvsx/json/NamespaceJson.java index 154652f2..c0b1a80e 100644 --- a/server/src/main/java/org/eclipse/openvsx/json/NamespaceJson.java +++ b/server/src/main/java/org/eclipse/openvsx/json/NamespaceJson.java @@ -55,6 +55,9 @@ public static NamespaceJson error(String message) { @Schema(hidden = true) private String roleUrl; + @Schema(hidden = true) + private String detailsUrl; + public String getName() { return name; } @@ -102,4 +105,12 @@ public String getRoleUrl() { public void setRoleUrl(String roleUrl) { this.roleUrl = roleUrl; } + + public String getDetailsUrl() { + return detailsUrl; + } + + public void setDetailsUrl(String detailsUrl) { + this.detailsUrl = detailsUrl; + } } \ No newline at end of file diff --git a/webui/src/extension-registry-service.ts b/webui/src/extension-registry-service.ts index 6bb3144f..ff872535 100644 --- a/webui/src/extension-registry-service.ts +++ b/webui/src/extension-registry-service.ts @@ -49,7 +49,7 @@ export class ExtensionRegistryService { return sendRequest({ abortController, endpoint }); } - async setNamespaceDetails(abortController: AbortController, details: NamespaceDetails): Promise> { + async setNamespaceDetails(abortController: AbortController, endpoint: string, details: NamespaceDetails): Promise> { const csrfResponse = await this.getCsrfToken(abortController); const headers: Record = { 'Content-Type': 'application/json;charset=UTF-8' @@ -59,7 +59,6 @@ export class ExtensionRegistryService { headers[csrfToken.header] = csrfToken.value; } - const endpoint = createAbsoluteURL([this.serverUrl, 'user', 'namespace', details.name, 'details']); return sendRequest({ abortController, method: 'POST', @@ -70,7 +69,7 @@ export class ExtensionRegistryService { }); } - async setNamespaceLogo(abortController: AbortController, namespace: string, logoFile: Blob, logoName: string): Promise> { + async setNamespaceLogo(abortController: AbortController, endpoint: string, logoFile: Blob, logoName: string): Promise> { const csrfResponse = await this.getCsrfToken(abortController); const headers: Record = {}; if (!isError(csrfResponse)) { @@ -80,7 +79,7 @@ export class ExtensionRegistryService { const form = new FormData(); form.append('file', logoFile, logoName); - const endpoint = createAbsoluteURL([this.serverUrl, 'user', 'namespace', namespace, 'details', 'logo']); + endpoint = createAbsoluteURL([endpoint, 'logo']); return sendRequest({ abortController, method: 'POST', diff --git a/webui/src/extension-registry-types.ts b/webui/src/extension-registry-types.ts index 45fecbe0..cd8b862a 100644 --- a/webui/src/extension-registry-types.ts +++ b/webui/src/extension-registry-types.ts @@ -220,6 +220,7 @@ export interface Namespace { verified: boolean; membersUrl: UrlString; roleUrl: UrlString; + detailsUrl: UrlString; } export interface NamespaceDetails { diff --git a/webui/src/pages/user/user-namespace-details.tsx b/webui/src/pages/user/user-namespace-details.tsx index a2821514..35c29c72 100644 --- a/webui/src/pages/user/user-namespace-details.tsx +++ b/webui/src/pages/user/user-namespace-details.tsx @@ -194,14 +194,14 @@ export const UserNamespaceDetails: FunctionComponent ? 'https://twitter.com/' + details.socialLinks.twitter : undefined; - const result = await context.service.setNamespaceDetails(abortController.current, details); + const result = await context.service.setNamespaceDetails(abortController.current, props.namespace.detailsUrl, details); if (isError(result)) { throw result; } if (logoPreview) { const logoFile = await (await fetch(logoPreview)).blob(); - await context.service.setNamespaceLogo(abortController.current, details.name, logoFile, details.logo as string); + await context.service.setNamespaceLogo(abortController.current, props.namespace.detailsUrl, logoFile, details.logo as string); await getNamespaceDetails(); } else { setCurrentDetails(copy(newDetails)); diff --git a/webui/src/pages/user/user-settings-namespace-detail.tsx b/webui/src/pages/user/user-settings-namespace-detail.tsx index b23beba1..68f75286 100644 --- a/webui/src/pages/user/user-settings-namespace-detail.tsx +++ b/webui/src/pages/user/user-settings-namespace-detail.tsx @@ -108,18 +108,20 @@ export const NamespaceDetail: FunctionComponent = props => { props.namespace.membersUrl - ? <> - - - - - - - + ? + + + : null + } + { + props.namespace.detailsUrl + ? + + : null }