Added npdi service

This commit is contained in:
Jonathan Barrow
2021-12-05 11:04:27 -05:00
parent 9f9ecf5ef1
commit ae9b6f5ec0
7 changed files with 54 additions and 0 deletions

Binary file not shown.

21
encrypt-contents.js Normal file
View File

@@ -0,0 +1,21 @@
const BOSS = require('boss-js');
const path = require('path');
const fs = require('fs-extra');
const crypto = require('crypto');
require('dotenv').config();
// PROVIDE THESE KEYS YOURSELF
const { BOSS_AES_KEY, BOSS_HMAC_KEY } = process.env;
const decryptedFilePath = path.normalize(path.resolve(__dirname, process.argv[2]));
const encryptedFolderName = path.basename(path.dirname(decryptedFilePath));
const encryptedFolderPath = path.normalize(path.resolve(decryptedFilePath, '../../../encrypted', encryptedFolderName));
fs.ensureDirSync(encryptedFolderPath);
const encryptedContents = BOSS.encryptWiiU(decryptedFilePath, BOSS_AES_KEY, BOSS_HMAC_KEY);
const hash = crypto.createHash('md5').update(encryptedContents).digest('hex');
const encryptedFilePath = path.normalize(path.resolve(encryptedFolderPath, hash));
fs.writeFileSync(encryptedFilePath, encryptedContents);

View File

@@ -10,6 +10,7 @@ const app = express();
const nptsService = require('./services/npts');
const npplService = require('./services/nppl');
const npdiService = require('./services/npdi');
// START APPLICATION
app.set('etag', false);
@@ -25,6 +26,7 @@ app.use(express.urlencoded({
app.use(nptsService);
app.use(npplService);
app.use(npdiService);
// 404 handler
logger.info('Creating 404 status handler');

31
src/services/npdi.js Normal file
View File

@@ -0,0 +1,31 @@
const path = require('path');
const fs = require('fs-extra');
const express = require('express');
const subdomain = require('express-subdomain');
// Router to handle the subdomain restriction
const npdi = express.Router();
// Setup routes
npdi.get('/p01/data/1/:titleHash/:fileVersion/:fileHash', (request, response) => {
const { titleHash, fileHash } = request.params;
const contentPath = path.normalize(`${__dirname}/../../cdn/content/encrypted/${titleHash}/${fileHash}`);
if (fs.existsSync(contentPath)) {
response.set('Content-Type', 'applicatoin/octet-stream');
response.set('Content-Disposition', 'attachment');
response.set('Content-Transfer-Encoding', 'binary');
response.set('Content-Type', 'applicatoin/octet-stream');
response.sendFile(contentPath);
} else {
response.sendStatus(404);
}
});
// Main router for endpoints
const router = express.Router();
// Create subdomain
router.use(subdomain('npdi.app', npdi));
module.exports = router;