fileManager

Handles downloading and deleting files from folders (Especially the designated downloads folder)

Source:

Members

(static) FAILED_DOWNLOAD_IMAGE_PATH :string

Source:

Absolute path of a default image to send when the download fails

Type:
  • string

(inner, constant) DOWNLOADS_FOLDER :string

Source:

Absolute path to the folder for downloaded files

Type:
  • string

Methods

(async, static) fileDownload(fileObj, fileNameopt, authopt) → {Promise.<FileData>}

Source:

Downloads a file from a Slack file object. File name may change if a file by the same name already exists according to getValidFileName

Parameters:
Name Type Attributes Description
fileObj Object

Slack file details object (Found in event.files[])

fileName string <optional>

Name for file (Defaults to the name provided by Slack)

auth string <optional>

Alternative token to use (in place of the environment variables)

Returns:

An object containing details on where the file is, what it is called, the original Slack file object, and more

Type
Promise.<FileData>

(async, inner) completeDownload(saveTo, downloadFromURL, headersopt, rejectOnRedirectopt) → {Promise.<string>}

Source:

Downloads a file from a given URL and save it to a given location

Parameters:
Name Type Attributes Default Description
saveTo string

File save location (Absolute Path Only)

downloadFromURL string

The URL to download from

headers Object <optional>
{}

Optional http request headers

rejectOnRedirect boolean <optional>
false

Reject promise on redirects instead of following

Returns:

Returns the path where the file was saved if successful

Type
Promise.<string>

(async, inner) completeDownloadErrorHandler(err, unlinkLocationopt) → {Promise}

Source:

Error handler for completeDownload. Tries to delete file on a failed download

Parameters:
Name Type Attributes Description
err Error

Error from completeDownload

unlinkLocation string <optional>

Path of intended file to unlink

Returns:

Throws errors through the Promise

Type
Promise

(inner) fileDelete(fileName) → {Promise}

Source:

Deletes a file from the downloads folder specifically

Parameters:
Name Type Description
fileName string

Name of file to delete from the downloads folder

Returns:

Returns the promise from fs.promises.unlink

Type
Promise

(async, inner) fileSize(filePath) → {Promise.<number>}

Source:

Returns the size of a file in megabytes

Parameters:
Name Type Description
filePath string

Absolute path to file to check the size of

Returns:

Size in megabytes (Includes decimals)

Type
Promise.<number>

(async, inner) getValidFileName(rootPath, fileName, fileExtension) → {Promise.<string>}

Source:

Checks if a specified file name is available in a given folder path. If not, a number in parentheses will be appended to it If 'image.png' does not already exist, inputting 'image.png' into this function will return 'image.png' If 'image.png' already exists, inputting 'image.png' into this function will return 'image (1).png' instead

Parameters:
Name Type Description
rootPath string

The location of the folder to check (Absolute Path Only)

fileName string

Name to give the file

fileExtension string

File extension

Returns:

Returns a file name that isn't already being used in the folder

Type
Promise.<string>