diff --git a/creator-node/package-lock.json b/creator-node/package-lock.json index 7fa276f3d4e..46e85aae98e 100644 --- a/creator-node/package-lock.json +++ b/creator-node/package-lock.json @@ -3939,7 +3939,7 @@ "bmp-js": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz", - "integrity": "sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw==" + "integrity": "sha1-4Fpj95amwf8l9Hcex62twUjAcjM=" }, "bn.js": { "version": "4.12.0", @@ -4197,7 +4197,7 @@ "buffer-equal": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-0.0.1.tgz", - "integrity": "sha512-RgSV6InVQ9ODPdLWJ5UAqBqJBOg370Nz6ZQtRzpt6nUjc8v0St97uJ4PYC6NztqIScrAXafKM3mZPMygSe1ggA==" + "integrity": "sha1-kbx0sR6kBbyRa8aqkI+q+ltKrEs=" }, "buffer-layout": { "version": "1.2.2", diff --git a/creator-node/src/components/healthCheck/healthCheckController.js b/creator-node/src/components/healthCheck/healthCheckController.js index fd3c0b3ddc8..124b9492856 100644 --- a/creator-node/src/components/healthCheck/healthCheckController.js +++ b/creator-node/src/components/healthCheck/healthCheckController.js @@ -19,11 +19,7 @@ const { sequelize } = require('../../models') const { getMonitors } = require('../../monitors/monitors') const TranscodingQueue = require('../../TranscodingQueue') -const { recoverWallet } = require('../../apiSigning') -const { - handleTrackContentUpload, - removeTrackFolder -} = require('../../fileManager') +const { ensureValidSPMiddleware } = require('../../middlewares') const config = require('../../config') @@ -42,53 +38,6 @@ const FIND_SYNC_REQUESTS_JOB_MAX_LAST_SUCCESSFUL_RUN_DELAY_MS = config.get( const FIND_REPLICA_SET_UPDATES_JOB_MAX_LAST_SUCCESSFUL_RUN_DELAY_MS = config.get('findReplicaSetUpdatesJobLastSuccessfulRunDelayMs') -// Helper Functions -/** - * Verifies that the request is made by the delegate Owner - */ -const healthCheckVerifySignature = (req, res, next) => { - const { timestamp, randomBytes, signature } = req.query - if (!timestamp || !randomBytes || !signature) { - return sendResponse( - req, - res, - errorResponseBadRequest('Missing required query parameters') - ) - } - - const recoveryObject = { randomBytesToSign: randomBytes, timestamp } - const recoveredPublicWallet = recoverWallet( - recoveryObject, - signature - ).toLowerCase() - const recoveredTimestampDate = new Date(timestamp) - const currentTimestampDate = new Date() - const requestAge = currentTimestampDate - recoveredTimestampDate - if (requestAge >= MAX_HEALTH_CHECK_TIMESTAMP_AGE_MS) { - return sendResponse( - req, - res, - errorResponseBadRequest( - `Submitted timestamp=${recoveredTimestampDate}, current timestamp=${currentTimestampDate}. Maximum age =${MAX_HEALTH_CHECK_TIMESTAMP_AGE_MS}` - ) - ) - } - const delegateOwnerWallet = config.get('delegateOwnerWallet').toLowerCase() - if (recoveredPublicWallet !== delegateOwnerWallet) { - return sendResponse( - req, - res, - errorResponseBadRequest( - "Requester's public key does does not match Creator Node's delegate owner wallet." - ) - ) - } - - next() -} - -// Controllers - /** * Controller for `health_check` route, calls * `healthCheckComponentService`. @@ -245,45 +194,22 @@ const healthCheckVerboseController = async (req) => { }) } -/** - * Controller for `health_check/fileupload` route * - * Perform a file upload health check limited to configured delegateOwnerWallet. - * This prunes the disc artifacts created by the process after. - */ -const healthCheckFileUploadController = async (req) => { - const err = - req.fileFilterError || - req.fileSizeError || - (await removeTrackFolder(req, req.fileDir)) - if (err) { - return errorResponseServerError(err) - } - return successResponse({ success: true }) -} - // Routes router.get('/health_check', handleResponse(healthCheckController)) router.get('/health_check/sync', handleResponse(syncHealthCheckController)) router.get( '/health_check/duration', - healthCheckVerifySignature, + ensureValidSPMiddleware, handleResponse(healthCheckDurationController) ) router.get( '/health_check/duration/heartbeat', - healthCheckVerifySignature, + ensureValidSPMiddleware, handleResponseWithHeartbeat(healthCheckDurationController) ) router.get( '/health_check/verbose', handleResponse(healthCheckVerboseController) ) -router.post( - '/health_check/fileupload', - healthCheckVerifySignature, - handleTrackContentUpload, - handleResponseWithHeartbeat(healthCheckFileUploadController) -) - module.exports = router diff --git a/creator-node/src/routes/tracks.js b/creator-node/src/routes/tracks.js index 128bd0ea763..3fda9b372cd 100644 --- a/creator-node/src/routes/tracks.js +++ b/creator-node/src/routes/tracks.js @@ -94,6 +94,27 @@ module.exports = function (app) { }) ) + /** + * Delete all temporary transcode artifacts from track transcode handoff flow. + * This is called on the node that was handed off the transcode to clear the state from disk + */ + app.post( + '/clear_transcode_and_segment_artifacts', + ensureValidSPMiddleware, + handleResponse(async (req, res) => { + const fileDir = req.body.fileDir + req.logger.info('Clearing filesystem fileDir', fileDir) + if (!fileDir.includes('tmp_track_artifacts')) { + return errorResponseBadRequest( + 'Cannot remove track folder outside temporary track artifacts' + ) + } + await removeTrackFolder({ logContext: req.logContext }, fileDir) + + return successResponse() + }) + ) + /** * Given that the requester is a valid SP, the current Content Node has enough storage, * upload the track to the current node and add a transcode and segmenting job to the queue. @@ -127,7 +148,7 @@ module.exports = function (app) { * Given that the request is coming from a valid SP, serve the corresponding file * from the transcode handoff * - * This route is used on an available SP when the primary requests the transcoded files after + * This route is called from the primary to request the transcoded files after * sending the first request for the transcode handoff. This route does not run on the primary. */ app.get(