Skip to content

Commit

Permalink
Merge pull request #208 from desci-labs/hotfix-remove-msftcid
Browse files Browse the repository at this point in the history
Hotfix: retrieveTree pass
  • Loading branch information
hubsmoke authored Feb 15, 2024
2 parents 266f460 + e80451d commit 7d3aeca
Showing 1 changed file with 5 additions and 39 deletions.
44 changes: 5 additions & 39 deletions desci-server/src/controllers/data/retrieve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import tar from 'tar';
import { prisma } from '../../client.js';
import { logger as parentLogger } from '../../logger.js';
import redisClient, { getOrCache } from '../../redisClient.js';
import { getLatestDriveTime } from '../../services/draftTrees.js';
import { getDatasetTar } from '../../services/ipfs.js';
import { getLatestManifestFromNode } from '../../services/manifestRepo.js';
import { NodeUuid, getLatestManifestFromNode } from '../../services/manifestRepo.js';
import { getTreeAndFill, getTreeAndFillDeprecated } from '../../utils/driveUtils.js';
import { cleanupManifestUrl } from '../../utils/manifest.js';
import { ensureUuidEndsWithDot } from '../../utils.js';

import { ErrorResponse } from './update.js';
// import { getLatestManifest } from './utils.js';

export enum DataReferenceSrc {
PRIVATE = 'private',
Expand All @@ -33,7 +33,7 @@ interface RetrieveResponse {

export const retrieveTree = async (req: Request, res: Response<RetrieveResponse | ErrorResponse | string>) => {
let ownerId = (req as any).user?.id;
const manifestCid: string = req.params.manifestCid;
const manifestCid: string = req.params.manifestCid; // unused param
const uuid: string = req.params.nodeUuid;
const shareId: string = req.params.shareId;

Expand Down Expand Up @@ -89,48 +89,14 @@ export const retrieveTree = async (req: Request, res: Response<RetrieveResponse
return res.status(400).send({ error: 'Node not found' });
}

if (!manifestCid) {
return res.status(400).json({ error: 'no manifest CID provided' });
}
if (!uuid) {
return res.status(400).json({ error: 'no UUID provided' });
}

// TODOD: Pull data references from publishDataReferences table
// TODO: Later expand to never require auth from publicDataRefs
let dataSource = DataReferenceSrc.PRIVATE;
const dataset = await prisma.dataReference.findFirst({
where: {
type: DataType.MANIFEST,
userId: ownerId,
cid: manifestCid,
node: {
uuid: ensureUuidEndsWithDot(uuid),
},
},
});
const publicDataset = await prisma.publicDataReference.findFirst({
where: {
cid: manifestCid,
type: DataType.MANIFEST,
node: {
uuid: ensureUuidEndsWithDot(uuid),
},
},
});

if (publicDataset) dataSource = DataReferenceSrc.PUBLIC;

if (!dataset && dataSource === DataReferenceSrc.PRIVATE) {
logger.warn(`unauthed access user: ${ownerId}, cid provided: ${manifestCid}, nodeUuid provided: ${uuid}`);
return res.status(400).json({ error: 'failed' });
}

// const depthCacheKey = `depth-${depth}-${manifestCid}-${dataPath};

try {
const manifest = await getLatestManifestFromNode(node);
const filledTree = (await getTreeAndFill(manifest, uuid, ownerId)) ?? [];
const latestDriveClock = getLatestDriveTime(node.uuid as NodeUuid);

let tree = findAndPruneNode(filledTree[0], dataPath, depth);
if (tree?.type === 'file' || tree === undefined) {
Expand All @@ -140,7 +106,7 @@ export const retrieveTree = async (req: Request, res: Response<RetrieveResponse
tree = findAndPruneNode(filledTree[0], poppedDataPath, depth);
}

return res.status(200).json({ tree: [tree], date: dataset?.updatedAt.toString() });
return res.status(200).json({ tree: [tree], date: await latestDriveClock });
} catch (err) {
logger.error({ err }, 'Failed to retrieve tree');
return res.status(400).json({ error: 'failed' });
Expand Down

0 comments on commit 7d3aeca

Please sign in to comment.