MOBILE-2404 pluginfile: Fix plugin file handlers

main
Dani Palou 2018-06-01 12:32:22 +02:00
parent 30f850a9b3
commit 0c59a6c7c4
6 changed files with 21 additions and 10 deletions

View File

@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate';
@Injectable()
export class AddonModFolderPluginFileHandler implements CorePluginFileHandler {
name = 'AddonModFolderPluginFileHandler';
component = 'mod_folder';
/**
* Return the RegExp to match the revision on pluginfile URLs.

View File

@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate';
@Injectable()
export class AddonModImscpPluginFileHandler implements CorePluginFileHandler {
name = 'AddonModImscpPluginFileHandler';
component = 'mod_imscp';
/**
* Return the RegExp to match the revision on pluginfile URLs.

View File

@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate';
@Injectable()
export class AddonModPagePluginFileHandler implements CorePluginFileHandler {
name = 'AddonModPagePluginFileHandler';
component = 'mod_page';
/**
* Return the RegExp to match the revision on pluginfile URLs.

View File

@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate';
@Injectable()
export class AddonModResourcePluginFileHandler implements CorePluginFileHandler {
name = 'AddonModResourcePluginFileHandler';
component = 'mod_resource';
/**
* Return the RegExp to match the revision on pluginfile URLs.

View File

@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate';
@Injectable()
export class AddonModScormPluginFileHandler implements CorePluginFileHandler {
name = 'AddonModScormPluginFileHandler';
component = 'mod_scorm';
/**
* Return the RegExp to match the revision on pluginfile URLs.
@ -32,7 +33,7 @@ export class AddonModScormPluginFileHandler implements CorePluginFileHandler {
// Check filearea.
if (args[2] == 'content') {
// Component + Filearea + Revision
return new RegExp('/mod_resource/content/([0-9]+)/');
return new RegExp('/mod_scorm/content/([0-9]+)/');
}
}

View File

@ -20,11 +20,17 @@ import { CoreLoggerProvider } from './logger';
*/
export interface CorePluginFileHandler {
/**
* A name to identify the handler. It should match the "component" of pluginfile URLs.
* A name to identify the handler.
* @type {string}
*/
name: string;
/**
* The "component" of the handler. It should match the "component" of pluginfile URLs.
* @type {string}
*/
component: string;
/**
* Return the RegExp to match the revision on pluginfile URLs.
*
@ -57,12 +63,12 @@ export class CorePluginFileDelegate {
/**
* Get the handler for a certain pluginfile url.
*
* @param {string} pluginType Type of the plugin.
* @param {string} component Component of the plugin.
* @return {CorePluginFileHandler} Handler. Undefined if no handler found for the plugin.
*/
protected getPluginHandler(pluginType: string): CorePluginFileHandler {
if (typeof this.handlers[pluginType] != 'undefined') {
return this.handlers[pluginType];
protected getPluginHandler(component: string): CorePluginFileHandler {
if (typeof this.handlers[component] != 'undefined') {
return this.handlers[component];
}
}
@ -88,14 +94,14 @@ export class CorePluginFileDelegate {
* @return {boolean} True if registered successfully, false otherwise.
*/
registerHandler(handler: CorePluginFileHandler): boolean {
if (typeof this.handlers[handler.name] !== 'undefined') {
this.logger.log(`Addon '${handler.name}' already registered`);
if (typeof this.handlers[handler.component] !== 'undefined') {
this.logger.log(`Handler '${handler.component}' already registered`);
return false;
}
this.logger.log(`Registered addon '${handler.name}'`);
this.handlers[handler.name] = handler;
this.logger.log(`Registered handler '${handler.component}'`);
this.handlers[handler.component] = handler;
return true;
}