feat: use requireSignIn for /storage routes

This commit is contained in:
karishmas6
2024-10-06 04:11:50 +05:30
parent ad9b701193
commit 5d8cc4a091

View File

@@ -15,13 +15,14 @@ import moment from 'moment-timezone';
import cron from 'node-cron'; import cron from 'node-cron';
import { googleSheetUpdateTasks, processGoogleSheetUpdates } from '../workflow-management/integrations/gsheet'; import { googleSheetUpdateTasks, processGoogleSheetUpdates } from '../workflow-management/integrations/gsheet';
import { getDecryptedProxyConfig } from './proxy'; import { getDecryptedProxyConfig } from './proxy';
import { requireSignIn } from '../middlewares/auth';
export const router = Router(); export const router = Router();
/** /**
* Logs information about recordings API. * Logs information about recordings API.
*/ */
router.all('/', (req, res, next) => { router.all('/', requireSignIn, (req, res, next) => {
logger.log('debug', `The recordings API was invoked: ${req.url}`) logger.log('debug', `The recordings API was invoked: ${req.url}`)
next() // pass control to the next handler next() // pass control to the next handler
}) })
@@ -29,7 +30,7 @@ router.all('/', (req, res, next) => {
/** /**
* GET endpoint for getting an array of all stored recordings. * GET endpoint for getting an array of all stored recordings.
*/ */
router.get('/recordings', async (req, res) => { router.get('/recordings', requireSignIn, async (req, res) => {
try { try {
const data = await readFiles('./../storage/recordings/'); const data = await readFiles('./../storage/recordings/');
return res.send(data); return res.send(data);
@@ -42,7 +43,7 @@ router.get('/recordings', async (req, res) => {
/** /**
* DELETE endpoint for deleting a recording from the storage. * DELETE endpoint for deleting a recording from the storage.
*/ */
router.delete('/recordings/:fileName', async (req, res) => { router.delete('/recordings/:fileName', requireSignIn, async (req, res) => {
try { try {
await deleteFile(`./../storage/recordings/${req.params.fileName}.waw.json`); await deleteFile(`./../storage/recordings/${req.params.fileName}.waw.json`);
return res.send(true); return res.send(true);
@@ -56,7 +57,7 @@ router.delete('/recordings/:fileName', async (req, res) => {
/** /**
* GET endpoint for getting an array of runs from the storage. * GET endpoint for getting an array of runs from the storage.
*/ */
router.get('/runs', async (req, res) => { router.get('/runs', requireSignIn, async (req, res) => {
try { try {
const data = await readFiles('./../storage/runs/'); const data = await readFiles('./../storage/runs/');
return res.send(data); return res.send(data);
@@ -69,7 +70,7 @@ router.get('/runs', async (req, res) => {
/** /**
* DELETE endpoint for deleting a run from the storage. * DELETE endpoint for deleting a run from the storage.
*/ */
router.delete('/runs/:fileName', async (req, res) => { router.delete('/runs/:fileName', requireSignIn, async (req, res) => {
try { try {
await deleteFile(`./../storage/runs/${req.params.fileName}.json`); await deleteFile(`./../storage/runs/${req.params.fileName}.json`);
return res.send(true); return res.send(true);
@@ -84,7 +85,7 @@ router.delete('/runs/:fileName', async (req, res) => {
* PUT endpoint for starting a remote browser instance and saving run metadata to the storage. * PUT endpoint for starting a remote browser instance and saving run metadata to the storage.
* Making it ready for interpretation and returning a runId. * Making it ready for interpretation and returning a runId.
*/ */
router.put('/runs/:fileName', async (req, res) => { router.put('/runs/:fileName', requireSignIn, async (req, res) => {
try { try {
const proxyConfig = await getDecryptedProxyConfig(req.user.id); const proxyConfig = await getDecryptedProxyConfig(req.user.id);
let proxyOptions: any = {}; let proxyOptions: any = {};
@@ -144,7 +145,7 @@ router.put('/runs/:fileName', async (req, res) => {
/** /**
* GET endpoint for getting a run from the storage. * GET endpoint for getting a run from the storage.
*/ */
router.get('/runs/run/:fileName/:runId', async (req, res) => { router.get('/runs/run/:fileName/:runId', requireSignIn, async (req, res) => {
try { try {
// read the run from storage // read the run from storage
const run = await readFile(`./../storage/runs/${req.params.fileName}_${req.params.runId}.json`) const run = await readFile(`./../storage/runs/${req.params.fileName}_${req.params.runId}.json`)
@@ -160,7 +161,7 @@ router.get('/runs/run/:fileName/:runId', async (req, res) => {
/** /**
* PUT endpoint for finishing a run and saving it to the storage. * PUT endpoint for finishing a run and saving it to the storage.
*/ */
router.post('/runs/run/:fileName/:runId', async (req, res) => { router.post('/runs/run/:fileName/:runId', requireSignIn, async (req, res) => {
try { try {
const recording = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`) const recording = await readFile(`./../storage/recordings/${req.params.fileName}.waw.json`)
const parsedRecording = JSON.parse(recording); const parsedRecording = JSON.parse(recording);
@@ -218,7 +219,7 @@ router.post('/runs/run/:fileName/:runId', async (req, res) => {
} }
}); });
router.put('/schedule/:fileName/', async (req, res) => { router.put('/schedule/:fileName/', requireSignIn, async (req, res) => {
console.log(req.body); console.log(req.body);
try { try {
const { fileName } = req.params; const { fileName } = req.params;
@@ -313,7 +314,7 @@ router.put('/schedule/:fileName/', async (req, res) => {
/** /**
* POST endpoint for aborting a current interpretation of the run. * POST endpoint for aborting a current interpretation of the run.
*/ */
router.post('/runs/abort/:fileName/:runId', async (req, res) => { router.post('/runs/abort/:fileName/:runId', requireSignIn, async (req, res) => {
try { try {
const run = await readFile(`./../storage/runs/${req.params.fileName}_${req.params.runId}.json`) const run = await readFile(`./../storage/runs/${req.params.fileName}_${req.params.runId}.json`)
const parsedRun = JSON.parse(run); const parsedRun = JSON.parse(run);