Home Manual Reference Source Test Repository
import Util from 'popcorn-api/src/util.js'
public class | source

Util

Class holding the frequently used functions.

Method Summary

Public Methods
public

Create the temporary directory.

public

Execute a command from within the root folder.

public

Export a collection to a JSON file.

public

importCollection(collection: String, jsonFile: String): Promise

Import a json file to a collection.

public

onError(errorMessage: String): Error

Error logger function.

public

Reset the default log file.

public

search(key: String, value: String): Object

Search for a key in an array of object.

public

Updates the lastUpdated.json file.

public

setStatus(status: String)

Updates the status.json file.

Private Methods
private

Create an emty file.

private

_resetTemp(tmpPath: String)

Removes all the files in the temporary directory.

Public Methods

public createTemp() source

Create the temporary directory.

public executeCommand(cmd: String): Promise source

Execute a command from within the root folder.

Params:

NameTypeAttributeDescription
cmd String

The command to execute.

Return:

Promise

The output of the command.

public exportCollection(collection: String): Promise source

Export a collection to a JSON file.

Params:

NameTypeAttributeDescription
collection String

The collection to export.

Return:

Promise

The output of the mongoexport command.

public importCollection(collection: String, jsonFile: String): Promise source

Import a json file to a collection.

Params:

NameTypeAttributeDescription
collection String

The collection to import.

jsonFile String

The json file to import..

Return:

Promise

The output of the mongoimport command.

public onError(errorMessage: String): Error source

Error logger function.

Params:

NameTypeAttributeDescription
errorMessage String

The error message you want to display.

Return:

Error

A new error with the given error message.

public resetLog() source

Reset the default log file.

Search for a key in an array of object.

Params:

NameTypeAttributeDescription
key String

The key to search for.

value String

The value of the key to search for.

Return:

Object

The object with the correct key-value pair.

public setLastUpdated(updated: String) source

Updates the lastUpdated.json file.

Params:

NameTypeAttributeDescription
updated String
  • optional
  • default: Date.now()

The epoch time when the API last started scraping.

public setStatus(status: String) source

Updates the status.json file.

Params:

NameTypeAttributeDescription
status String
  • optional
  • default: Idle

The status which will be set to in the status.json file.

Private Methods

private _createEmptyFile(path: String) source

Create an emty file.

Params:

NameTypeAttributeDescription
path String

The path to the file to create.

private _resetTemp(tmpPath: String) source

Removes all the files in the temporary directory.

Params:

NameTypeAttributeDescription
tmpPath String
  • optional
  • default: popcorn-api/tmp

The path to remove all the files within (Default is set in the config/constants.js).