From 0f1bed6ac75736898eb33e6d7e294bde764e9c65 Mon Sep 17 00:00:00 2001 From: niqzart Date: Wed, 29 Oct 2025 21:50:08 +0300 Subject: [PATCH] feat: fully switch to storage v2 --- src/common/fetcher.ts | 2 +- src/hooks/access.ts | 65 ++++++++++++++----------------------------- 2 files changed, 22 insertions(+), 45 deletions(-) diff --git a/src/common/fetcher.ts b/src/common/fetcher.ts index 8cbc574..8230dac 100644 --- a/src/common/fetcher.ts +++ b/src/common/fetcher.ts @@ -1,7 +1,7 @@ import { logServerError } from "./errors" const back2BaseUrl = process.env.BACK_2_BASE_URL || "http://localhost:5000" -const back2BasePath = "/internal/storage-service" +const back2BasePath = "/internal/storage-service/v2" const back2ApiKey = process.env.BACK_2_API_KEY || "local" export async function fetchStorage(path: string, init?: RequestInit): Promise { diff --git a/src/hooks/access.ts b/src/hooks/access.ts index 7f2d24d..ca0734d 100644 --- a/src/hooks/access.ts +++ b/src/hooks/access.ts @@ -38,54 +38,31 @@ export async function verifyYDocAccess( throw new HocusPocusError("Invalid document name") } - if (token == documentName) { - const response = await fetchStorage( - `/ydocs/${documentName}/access-level/`, - { headers: proxyAuthHeaders } - ) - - if (response?.ok) { - const data = await response.json() - if (data === "read-write") { - return proxyAuthHeaders - } else if (data === "read-only") { - connection.readOnly = true - return proxyAuthHeaders - } else { - throw new HocusPocusError("Access Denied") + const response = await fetchStorage( + `/ydocs/${documentName}/access-level/`, + { + headers: { + "X-Storage-Token": token, + ...proxyAuthHeaders, } - } else if (response?.status === 404) { - throw new HocusPocusError("YDoc not found") - } else { - throw new HocusPocusError() } - } else { - const response = await fetchStorage( - `/v2/ydocs/${documentName}/access-level/`, - { - headers: { - "X-Storage-Token": token, - ...proxyAuthHeaders, - } - } - ) + ) - if (response?.ok) { - const data = await response.json() - if (data === "read-write") { - return proxyAuthHeaders - } else if (data === "read-only") { - connection.readOnly = true - return proxyAuthHeaders - } else { - throw new HocusPocusError("Access Denied") - } - } else if (response?.status === 403) { - throw new HocusPocusError("Invalid storage token") - } else if (response?.status === 404) { - throw new HocusPocusError("YDoc not found") + if (response?.ok) { + const data = await response.json() + if (data === "read-write") { + return proxyAuthHeaders + } else if (data === "read-only") { + connection.readOnly = true + return proxyAuthHeaders } else { - throw new HocusPocusError() + throw new HocusPocusError("Access Denied") } + } else if (response?.status === 403) { + throw new HocusPocusError("Invalid storage token") + } else if (response?.status === 404) { + throw new HocusPocusError("YDoc not found") + } else { + throw new HocusPocusError() } }