mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-02-24 16:45:02 +01:00
19 lines
561 B
TypeScript
19 lines
561 B
TypeScript
import { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
|
|
import fs from 'node:fs';
|
|
|
|
export const plugin: PluginDefinition = {
|
|
templateFunctions: [{
|
|
name: 'fs.readFile',
|
|
args: [{ title: 'Select File', type: 'file', name: 'path', label: 'File' }],
|
|
async onRender(_ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
|
|
if (!args.values.path) return null;
|
|
|
|
try {
|
|
return fs.promises.readFile(args.values.path, 'utf-8');
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
},
|
|
}],
|
|
};
|