mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-11 17:46:41 -05:00
(feat) Add ability to disable plugins and show bundled plugins (#337)
This commit is contained in:
16
plugins/action-send-folder/package.json
Normal file
16
plugins/action-send-folder/package.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "@yaak/action-send-folder",
|
||||
"displayName": "Send All",
|
||||
"description": "Send all HTTP requests in a folder sequentially",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mountain-loop/yaak.git",
|
||||
"directory": "plugins/action-send-folder"
|
||||
},
|
||||
"private": true,
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"build": "yaakcli build",
|
||||
"dev": "yaakcli dev"
|
||||
}
|
||||
}
|
||||
74
plugins/action-send-folder/src/index.ts
Normal file
74
plugins/action-send-folder/src/index.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import type { PluginDefinition } from '@yaakapp/api';
|
||||
|
||||
export const plugin: PluginDefinition = {
|
||||
folderActions: [
|
||||
{
|
||||
label: 'Send All',
|
||||
icon: 'send_horizontal',
|
||||
async onSelect(ctx, args) {
|
||||
const targetFolder = args.folder;
|
||||
|
||||
// Get all folders and HTTP requests
|
||||
const [allFolders, allRequests] = await Promise.all([
|
||||
ctx.folder.list(),
|
||||
ctx.httpRequest.list(),
|
||||
]);
|
||||
|
||||
// Build a set of all folder IDs that are descendants of the target folder
|
||||
const folderIds = new Set<string>([targetFolder.id]);
|
||||
const addDescendants = (parentId: string) => {
|
||||
for (const folder of allFolders) {
|
||||
if (folder.folderId === parentId && !folderIds.has(folder.id)) {
|
||||
folderIds.add(folder.id);
|
||||
addDescendants(folder.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
addDescendants(targetFolder.id);
|
||||
|
||||
// Filter HTTP requests to those in the target folder or its descendants
|
||||
const requestsToSend = allRequests.filter(
|
||||
(req) => req.folderId != null && folderIds.has(req.folderId),
|
||||
);
|
||||
|
||||
if (requestsToSend.length === 0) {
|
||||
await ctx.toast.show({
|
||||
message: 'No requests in folder',
|
||||
icon: 'info',
|
||||
color: 'info',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Send each request sequentially
|
||||
let successCount = 0;
|
||||
let errorCount = 0;
|
||||
|
||||
for (const request of requestsToSend) {
|
||||
try {
|
||||
await ctx.httpRequest.send({ httpRequest: request });
|
||||
successCount++;
|
||||
} catch (error) {
|
||||
errorCount++;
|
||||
console.error(`Failed to send request ${request.id}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
// Show summary toast
|
||||
if (errorCount === 0) {
|
||||
await ctx.toast.show({
|
||||
message: `Sent ${successCount} request${successCount !== 1 ? 's' : ''}`,
|
||||
icon: 'send_horizontal',
|
||||
color: 'success',
|
||||
});
|
||||
} else {
|
||||
await ctx.toast.show({
|
||||
message: `Sent ${successCount}, failed ${errorCount}`,
|
||||
icon: 'alert_triangle',
|
||||
color: 'warning',
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
3
plugins/action-send-folder/tsconfig.json
Normal file
3
plugins/action-send-folder/tsconfig.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json"
|
||||
}
|
||||
Reference in New Issue
Block a user