-
Notifications
You must be signed in to change notification settings - Fork 246
Developer manual: Helper functions
jansmolders86 edited this page Nov 23, 2014
·
7 revisions
Several helper functions are at your disposal so you don't have to reinvent the wheel every time you write something for MediacenterJS.
The following are an explanation of the "most usefull" helper functions available. These functions are all stored in the /lib/utils and /lib/handler folders. Be sure to examine them while writing your code.
Include:
var ajax_utils = require('/ajax-utils');
Utilize:
ajax_utils.xhrCall(apiUrl, function(response) { ... });
Parameters:
- URL for AJAX GET.
- Callback
Result:
Data served by call.
Include:
var file_utils = require('/file-utils');
Utilize:
file_utils.getLocalFiles(PATH, FILETYPES, function(err, files) { ... });
Parameters:
- PATH on disk
- Filetypes needed to be retrieved
- Callback
Result:
An object with arrays consisting of:
'href': filePath, 'dir': rootdirectory, 'file': file.name
Include:
var configuration_handler = require('/handlers/configuration-handler'),
var config = configuration_handler.initializeConfiguration();
Utilize:
config.xxxx
Parameters:
none
Result:
all configuration items as string. eg config.moviepath
The app cache helper consists of several small helpful functions for writing and getting data from and to the local disk like metadata, images etc.
Include:
var app_cache_handler = require('/handlers/app-cache-handler');
Utilize:
* app_cache_handler.ensureCacheDirExists(DIR, SUBFOLDER);
* app_cache_handler.getCacheDir(DIR, SUBFOLDER);
* app_cache_handler.getCachePath(DIR, SUBFOLDER, FILE);
Get frontend friendly URL to cached file
@param app app cache dir
@param subdir subdir within app cache dir
@param filename Name of file
* app_cache_handler.getFrontendCachePath(APP, SUBFOLDER, FILE);
* app_cache_handler.clearCache(APP, callback);
Download images to cache dir
@param app app cache dir
@param subdir subdir within app cache dir
@param url URL of image to be downloaded
@param callback The Callback (returns the contents as string)
* app_cache_handler.downloadDataToCache(APP,SUBFOLDER, URL callback);