Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions modules/tool/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ export const toolContract = c.router(
}
},
{
pathPrefix: '/tool',
commonResponse: {
401: z.object({
error: z.string()
}),
404: z.object({
error: z.string()
}),
500: z.object({
error: z.string()
})
}
pathPrefix: '/tool'
}
);
1 change: 1 addition & 0 deletions modules/tool/type/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export const ToolListItemSchema = z.object({
.optional()
.describe('The secret input list of the tool')
});

export type ToolListItemType = z.infer<typeof ToolListItemSchema>;
2 changes: 1 addition & 1 deletion modules/tool/utils/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface CopyIconOptions {
* @param options CopyIconOptions
* @returns Count of copied icons
*/
export async function copyToolIcons(options: CopyIconOptions): Promise<number> {
export async function copyIcons(options: CopyIconOptions): Promise<number> {
const { sourceDir, targetDir, items, logPrefix = 'Copied icon' } = options;

const itemList = items || fs.readdirSync(sourceDir);
Expand Down
18 changes: 18 additions & 0 deletions modules/workflow/api/getTemplateList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { s } from '@/router/init';
import { contract } from '@/contract';
import { workflows } from '../init';

export const getTemplateList = s.route(contract.workflow.getTemplateList, async () => {
if (workflows)
return {
status: 200,
body: workflows
};
else
return {
status: 500,
body: {
error: 'Templates init failed'
}
};
});
18 changes: 18 additions & 0 deletions modules/workflow/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { c } from '@/contract/init';
import { TemplateListSchema } from './type';

export const workflowContract = c.router(
{
getTemplateList: {
path: '/list',
method: 'GET',
description: 'Get template list',
responses: {
200: TemplateListSchema
}
}
},
{
pathPrefix: '/workflow'
}
);
37 changes: 37 additions & 0 deletions modules/workflow/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { isProd } from '@/constants';
import { addLog } from '@/utils/log';
import { readFile } from 'fs/promises';
import { readdir } from 'fs/promises';
import { join } from 'path';
import type { TemplateItemType, TemplateListType } from './type';

export const workflows: TemplateListType = [];

export const initWorkflowTemplates = async () => {
const publicWorkflowsPath = isProd
? join(process.cwd(), 'dist', 'workflows')
: join(process.cwd(), 'modules', 'workflow', 'templates');

// according to the environment to decide to read the way
const items = await readdir(publicWorkflowsPath, { withFileTypes: true });
const templateItems = items.filter((item) => item.isFile() && item.name.endsWith('.json'));

for (const item of templateItems) {
const dirName = isProd ? item.name.replace('.json', '') : item.name; // hack: Bun and Node.js diff

const templatePath = join(publicWorkflowsPath, item.name);

const fileContent = await readFile(templatePath, 'utf-8');
const templateData = JSON.parse(fileContent);

const template = {
...templateData,
templateId: dirName,
isActive: true
} as TemplateItemType;

workflows.push(template);
}

addLog.info(`[init] workflow templates count: ${workflows.length}`);
};
7 changes: 7 additions & 0 deletions modules/workflow/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { s } from '@/router/init';
import { contract } from '@/contract';
import { getTemplateList } from './api/getTemplateList';

export const workflowRouter = s.router(contract.workflow, {
getTemplateList
});
Loading