Task Writing Guide

  1. Language:

    • Scripts are written in JavaScript.

    • TypeScript can be used and compiled to JavaScript.

  2. Development Environment:

    • Simple scripts can be written and tested directly in the task's script editor.

    • Complex scripts or those requiring third-party libraries should be compiled before importing.

    • Templates are available for reference (Template Link).

  3. Module Standard:

    • Scripts follow the ES module standard.

    • Export the task module using syntax like: export default async function (files, params)

  4. Function Type:

    • Task function is asynchronous.

    • await syntax is supported within the function.

  5. Function Parameters:

    • Two parameters: files and params

    • files: Type FileList (even for single input, it's a FileList with length 1)

    • params: An object containing task or workflow parameters, accessed via keys (e.g., params.quality)

    • onProgressMsg: A callback function (progressMsg: string) => void

  6. Function Return:

    • Return a Promise of a processed FileList or File array.

    • If nothing is returned, the input files will be returned.

  7. Error Handling:

    • Throw errors directly, e.g., throw new Error("The quality in the parameters is invalid.")

  8. Important Notes:

    • Do not include sensitive/confidential data in scripts. Use environment variables for such data.

    • Optimize scripts to run within 5 minutes. Executions exceeding 5 minutes will fail.

    • Keep script size under 10MB.

Following these guidelines will help ensure your scripts are efficient, secure, and compatible with the FilesWorkflow platform.

Last updated