-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import fs from 'fs/promises'; | ||
import { join } from 'path'; | ||
|
||
export const deleteFile = async(options: { | ||
path: string, | ||
done?: () => {}, | ||
error?: (err) => {} | ||
}) => { | ||
const path = options.path; | ||
const done = options.done || (() => {}); | ||
const error = options.error; | ||
|
||
try { | ||
await fs.unlink(join('../../', path)); | ||
done(); // File successfully deleted | ||
return; | ||
} catch (err) { | ||
if (error) { | ||
error(err); | ||
} else { | ||
throw err; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Node, NodeOutput, NodeParams, filterObject, restoreObject } from 'protoflow'; | ||
import { useColorFromPalette } from 'protoflow/src/diagram/Theme'; | ||
import { FileX } from 'lucide-react'; | ||
|
||
const DeleteFile = ({ node = {}, nodeData = {}, children }: any) => { | ||
const color = useColorFromPalette(3); // Un color que pueda indicar alerta o eliminación | ||
return ( | ||
<Node icon={FileX} node={node} isPreview={!node.id} title='Delete File' color={color} id={node.id} skipCustom={true}> | ||
<NodeParams id={node.id} params={[{ label: 'Path', field: 'mask-path', type: 'input' }]} /> | ||
<div style={{height: '30px'}} /> | ||
<NodeOutput id={node.id} type={'input'} label={'Done'} vars={[]} handleId={'mask-done'} /> | ||
<NodeOutput id={node.id} type={'input'} label={'Error'} vars={['err']} handleId={'mask-error'} /> | ||
</Node> | ||
) | ||
} | ||
|
||
export default { | ||
id: 'os2.deleteFile', | ||
type: 'CallExpression', | ||
category: "OS", | ||
keywords: ['fs', 'os', 'file', 'delete', 'remove'], | ||
check: (node, nodeData) => { | ||
return node.type == "CallExpression" && nodeData.to?.startsWith('context.os2.deleteFile') | ||
}, | ||
getComponent: (node, nodeData, children) => <DeleteFile node={node} nodeData={nodeData} children={children} />, | ||
filterChildren: filterObject({keys: { | ||
path: 'input', | ||
done: 'output', | ||
error: 'output' | ||
}}), | ||
restoreChildren: restoreObject({keys: { | ||
path: 'input', | ||
done: { params: {'param-done': { key: ""}}}, | ||
error: { params: { 'param-error': { key: "err"}}} | ||
}}), | ||
getInitialData: () => { | ||
return { | ||
await: true, | ||
to: 'context.os2.deleteFile', | ||
"mask-path": { | ||
value: "", | ||
kind: "StringLiteral" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters