feat: add markdown route
This commit is contained in:
@@ -274,7 +274,10 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (targetUrl) {
|
if (targetUrl) {
|
||||||
|
robot.set('recording_meta', { ...robot.recording_meta, url: targetUrl });
|
||||||
|
|
||||||
const updatedWorkflow = [...robot.recording.workflow];
|
const updatedWorkflow = [...robot.recording.workflow];
|
||||||
|
let foundGoto = false;
|
||||||
|
|
||||||
for (let i = updatedWorkflow.length - 1; i >= 0; i--) {
|
for (let i = updatedWorkflow.length - 1; i >= 0; i--) {
|
||||||
const step = updatedWorkflow[i];
|
const step = updatedWorkflow[i];
|
||||||
@@ -289,6 +292,7 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
|
|||||||
|
|
||||||
robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });
|
robot.set('recording', { ...robot.recording, workflow: updatedWorkflow });
|
||||||
robot.changed('recording', true);
|
robot.changed('recording', true);
|
||||||
|
foundGoto = true;
|
||||||
i = -1;
|
i = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -331,10 +335,11 @@ router.put('/recordings/:id', requireSignIn, async (req: AuthenticatedRequest, r
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (name) {
|
if (name || targetUrl) {
|
||||||
updates.recording_meta = {
|
updates.recording_meta = {
|
||||||
...robot.recording_meta,
|
...robot.recording_meta,
|
||||||
name
|
...(name && { name }),
|
||||||
|
...(targetUrl && { url: targetUrl })
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,6 +437,78 @@ router.post('/recordings/:id/duplicate', requireSignIn, async (req: Authenticate
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST endpoint for creating a markdown robot
|
||||||
|
*/
|
||||||
|
router.post('/recordings/markdown', requireSignIn, async (req: AuthenticatedRequest, res) => {
|
||||||
|
try {
|
||||||
|
const { url, name } = req.body;
|
||||||
|
|
||||||
|
if (!url) {
|
||||||
|
return res.status(400).json({ error: 'The "url" field is required.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.user) {
|
||||||
|
return res.status(401).send({ error: 'Unauthorized' });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate URL format
|
||||||
|
try {
|
||||||
|
new URL(url);
|
||||||
|
} catch (err) {
|
||||||
|
return res.status(400).json({ error: 'Invalid URL format' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const robotName = name || `Markdown Robot - ${new URL(url).hostname}`;
|
||||||
|
const currentTimestamp = new Date().toLocaleString();
|
||||||
|
const robotId = uuid();
|
||||||
|
|
||||||
|
const newRobot = await Robot.create({
|
||||||
|
id: uuid(),
|
||||||
|
userId: req.user.id,
|
||||||
|
recording_meta: {
|
||||||
|
name: robotName,
|
||||||
|
id: robotId,
|
||||||
|
createdAt: currentTimestamp,
|
||||||
|
updatedAt: currentTimestamp,
|
||||||
|
pairs: 0,
|
||||||
|
params: [],
|
||||||
|
type: 'markdown',
|
||||||
|
url: url,
|
||||||
|
},
|
||||||
|
recording: { workflow: [] },
|
||||||
|
google_sheet_email: null,
|
||||||
|
google_sheet_name: null,
|
||||||
|
google_sheet_id: null,
|
||||||
|
google_access_token: null,
|
||||||
|
google_refresh_token: null,
|
||||||
|
schedule: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.log('info', `Markdown robot created with id: ${newRobot.id}`);
|
||||||
|
capture(
|
||||||
|
'maxun-oss-markdown-robot-created',
|
||||||
|
{
|
||||||
|
robot_meta: newRobot.recording_meta,
|
||||||
|
url: url,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return res.status(201).json({
|
||||||
|
message: 'Markdown robot created successfully.',
|
||||||
|
robot: newRobot,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
logger.log('error', `Error creating markdown robot: ${error.message}`);
|
||||||
|
return res.status(500).json({ error: error.message });
|
||||||
|
} else {
|
||||||
|
logger.log('error', 'Unknown error creating markdown robot');
|
||||||
|
return res.status(500).json({ error: 'An unknown error occurred.' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DELETE endpoint for deleting a recording from the storage.
|
* DELETE endpoint for deleting a recording from the storage.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user