Skip to content

Commit

Permalink
[CON-544] Add new route to fetch copy320 CIDs using a segment CID (#4604
Browse files Browse the repository at this point in the history
)
  • Loading branch information
jonaylor89 committed Jan 24, 2023
1 parent 558a74d commit c8727ee
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion creator-node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions creator-node/src/routes/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const {
const DBManager = require('../dbManager')
const DiskManager = require('../diskManager')
const { libs } = require('@audius/sdk')
const { sequelize } = require('../models')
const Utils = libs.Utils

const BATCH_CID_ROUTE_LIMIT = 500
Expand Down Expand Up @@ -940,6 +941,54 @@ router.post(
})
)

router.post(
'/segment_to_cid',
handleResponse(async (req, _res) => {
const { cid, wallet } = req.body
if (!cid || !wallet) {
return errorResponseBadRequest(`cid or wallet is missing`)
}

const uuid = await models.CNodeUser.findOne({
attributes: ['cnodeUserUUID'],
raw: true,
where: {
walletPublicKey: wallet
}
})

if (!uuid) {
return errorResponseNotFound(
`could not find the user uuid with the wallet provided`
)
}

const queryResults = await sequelize.query(
`
SELECT multihash, "trackBlockchainId", "sourceFile"
FROM "Files"
WHERE "sourceFile" in (
SELECT "sourceFile"
FROM "Files"
WHERE "multihash" = :trackSegmentCid
)
AND "type" = 'copy320'
AND "cnodeUserUUID" = :cnodeUserUUID
`,
{
replacements: {
trackSegmentCid: cid,
cnodeUserUUID: uuid
}
}
)

const copy320Cid = queryResults

return successResponse(copy320Cid)
})
)

/**
* Serves information on existence of given image cids
* @param req
Expand Down

0 comments on commit c8727ee

Please sign in to comment.