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() @Injectable()
export class AddonModFolderPluginFileHandler implements CorePluginFileHandler { export class AddonModFolderPluginFileHandler implements CorePluginFileHandler {
name = 'AddonModFolderPluginFileHandler'; name = 'AddonModFolderPluginFileHandler';
component = 'mod_folder';
/** /**
* Return the RegExp to match the revision on pluginfile URLs. * Return the RegExp to match the revision on pluginfile URLs.

View File

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

View File

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

View File

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

View File

@ -21,6 +21,7 @@ import { CorePluginFileHandler } from '@providers/plugin-file-delegate';
@Injectable() @Injectable()
export class AddonModScormPluginFileHandler implements CorePluginFileHandler { export class AddonModScormPluginFileHandler implements CorePluginFileHandler {
name = 'AddonModScormPluginFileHandler'; name = 'AddonModScormPluginFileHandler';
component = 'mod_scorm';
/** /**
* Return the RegExp to match the revision on pluginfile URLs. * Return the RegExp to match the revision on pluginfile URLs.
@ -32,7 +33,7 @@ export class AddonModScormPluginFileHandler implements CorePluginFileHandler {
// Check filearea. // Check filearea.
if (args[2] == 'content') { if (args[2] == 'content') {
// Component + Filearea + Revision // 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 { 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} * @type {string}
*/ */
name: 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. * 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. * 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. * @return {CorePluginFileHandler} Handler. Undefined if no handler found for the plugin.
*/ */
protected getPluginHandler(pluginType: string): CorePluginFileHandler { protected getPluginHandler(component: string): CorePluginFileHandler {
if (typeof this.handlers[pluginType] != 'undefined') { if (typeof this.handlers[component] != 'undefined') {
return this.handlers[pluginType]; return this.handlers[component];
} }
} }
@ -88,14 +94,14 @@ export class CorePluginFileDelegate {
* @return {boolean} True if registered successfully, false otherwise. * @return {boolean} True if registered successfully, false otherwise.
*/ */
registerHandler(handler: CorePluginFileHandler): boolean { registerHandler(handler: CorePluginFileHandler): boolean {
if (typeof this.handlers[handler.name] !== 'undefined') { if (typeof this.handlers[handler.component] !== 'undefined') {
this.logger.log(`Addon '${handler.name}' already registered`); this.logger.log(`Handler '${handler.component}' already registered`);
return false; return false;
} }
this.logger.log(`Registered addon '${handler.name}'`); this.logger.log(`Registered handler '${handler.component}'`);
this.handlers[handler.name] = handler; this.handlers[handler.component] = handler;
return true; return true;
} }