Skip to content

Commit

Permalink
fix(portal): bug in redirects (#255)
Browse files Browse the repository at this point in the history
Signed-off-by: giac-mysten <[email protected]>
  • Loading branch information
giac-mysten authored Oct 16, 2024
1 parent b16f441 commit cb0658b
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions portal/common/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import { Resource, VersionedResource } from "./types";
import { MAX_REDIRECT_DEPTH, RESOURCE_PATH_MOVE_TYPE } from "./constants";
import { checkRedirect } from "./redirects";
import { fromBase64 } from "@mysten/bcs";
import {
ResourcePathStruct,
DynamicFieldStruct,
ResourceStruct
} from "./bcs_data_parsing";
import { ResourcePathStruct, DynamicFieldStruct, ResourceStruct } from "./bcs_data_parsing";
import { deriveDynamicFieldID } from "@mysten/sui/utils";
import { bcs } from "@mysten/bcs";

Expand Down Expand Up @@ -47,11 +43,13 @@ export async function fetchResource(
return HttpStatusCodes.TOO_MANY_REDIRECTS;
}

const redirectPromise = checkRedirect(client, objectId);
const redirectPromise = checkRedirect(client, objectId);
seenResources.add(objectId);

const dynamicFieldId = deriveDynamicFieldID(
objectId, RESOURCE_PATH_MOVE_TYPE, bcs.string().serialize(path).toBytes()
objectId,
RESOURCE_PATH_MOVE_TYPE,
bcs.string().serialize(path).toBytes(),
);
console.log("Derived dynamic field objectID: ", dynamicFieldId);

Expand All @@ -62,10 +60,10 @@ export async function fetchResource(
});

// If no page data found.
if (!pageData || !( pageData.data )) {
if (!pageData || !pageData.data) {
const redirectId = await redirectPromise;
if (redirectId) {
fetchResource(client, redirectId, path, seenResources, depth + 1)
return fetchResource(client, redirectId, path, seenResources, depth + 1);
}
console.log("No page data found");
return HttpStatusCodes.NOT_FOUND;
Expand Down

0 comments on commit cb0658b

Please sign in to comment.