Skip to content

Commit

Permalink
Merge pull request #602 from desci-labs/develop
Browse files Browse the repository at this point in the history
Merge debug changes to prod
  • Loading branch information
kadamidev authored Oct 29, 2024
2 parents 6ba04d2 + b194ac3 commit 13709b2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions desci-server/src/controllers/admin/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { logger as parentLogger } from '../../logger.js';
import { directStreamLookup, RawStream } from '../../services/ceramic.js';
import { getAliasRegistry, getHotWallet } from '../../services/chain.js';
import { _getIndexedResearchObjects, getIndexedResearchObjects, IndexedResearchObject } from '../../theGraph.js';
import { ensureUuidEndsWithDot } from '../../utils.js';
import { ensureUuidEndsWithDot, hexToCid } from '../../utils.js';

const logger = parentLogger.child({ module: 'ADMIN::DebugController' });

Expand Down Expand Up @@ -119,6 +119,7 @@ type NodeDebugReport =
| {
createdAt: Date;
updatedAt: Date;
uuid: string;
hasError: boolean;
nVersionsAgree: boolean;
stream: any;
Expand Down Expand Up @@ -165,6 +166,7 @@ const debugNode = async (uuid: string): Promise<NodeDebugReport> => {
return {
createdAt: node.createdAt,
updatedAt: node.updatedAt,
uuid: node.uuid,
hasError,
nVersionsAgree,
stream,
Expand Down Expand Up @@ -233,15 +235,15 @@ const debugStream = async (stream?: string): Promise<DebugStreamResponse> => {
};
};

const debugDpid = async (dpid?: number) => {
if (!dpid) return { present: false, error: false };
const debugDpid = async (dpidAlias?: number) => {
if (!dpidAlias) return { present: false, error: false };

let mappedStream: string;
try {
const wallet = await getHotWallet();
const registry = getAliasRegistry(wallet);

mappedStream = await registry.resolve(dpid);
mappedStream = await registry.resolve(dpidAlias);
} catch (e) {
const err = e as Error;
return { present: true, error: true, name: err.name, msg: err.message, stack: err.stack };
Expand All @@ -251,7 +253,7 @@ const debugDpid = async (dpid?: number) => {
return { present: true, error: true, mappedStream: null };
}

return { present: true, error: false, mappedStream };
return { present: true, dpidAlias, error: false, mappedStream };
};

type DebugMigrationReponse =
Expand Down Expand Up @@ -309,8 +311,8 @@ const debugMigration = async (uuid?: string, stream?: DebugStreamResponse): Prom
const ownerMatches = streamController?.toLowerCase() === legacyOwner?.toLowerCase();

// All Versions Migrated check
const streamManifestCids = streamResearchObject.versions.map((v) => v.cid);
const legacyManifestCids = legacyHistory.versions.map((v) => v.cid);
const streamManifestCids = streamResearchObject.versions.map((v) => hexToCid(v.cid)).reverse();
const legacyManifestCids = legacyHistory.versions.map((v) => hexToCid(v.cid)).reverse();

const zipped = Array.from(
Array(Math.max(streamManifestCids.length, legacyManifestCids.length)),
Expand Down Expand Up @@ -345,7 +347,15 @@ const debugIndexer = async (uuid: string, shouldExist: boolean) => {
return { error: shouldExist, result: null };
}

return { error: false, nVersions: result.versions.length, result };
const withDecodedCid = {
...result,
versions: result.versions.map((v) => ({
...v,
_decoded: hexToCid(v.cid),
})),
};

return { error: false, nVersions: result.versions.length, result: withDecodedCid };
};

const debugDb = async (node: NodeDbClosure) => {
Expand Down
4 changes: 2 additions & 2 deletions desci-server/src/routes/v1/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ router.get('/analytics', [ensureUser, ensureAdmin], getAnalytics);
router.get('/analytics/csv', [ensureUser, ensureAdmin], createCsv);
router.get('/doi/list', [ensureUser, ensureAdmin], listDoiRecords);

router.get('/debug', [ensureUser, ensureAdmin], debugAllNodesHandler);
router.get('/debug/:uuid', [ensureUser, ensureAdmin], debugNodeHandler);
router.get('/debug', [ensureUser, ensureAdmin], asyncHandler(debugAllNodesHandler));
router.get('/debug/:uuid', [ensureUser, ensureAdmin], asyncHandler(debugNodeHandler));

router.use('/communities', [ensureUser, ensureAdmin], communities);
router.get('/attestations', [ensureUser, ensureAdmin], asyncHandler(listAttestations));
Expand Down

0 comments on commit 13709b2

Please sign in to comment.