|
@@ -6,25 +6,51 @@ const logger = require('@alias/logger')('growi:InterceptorManager');
|
|
|
class InterceptorManager {
|
|
class InterceptorManager {
|
|
|
|
|
|
|
|
constructor() {
|
|
constructor() {
|
|
|
|
|
+ this.interceptorAndOrders = []; /* [
|
|
|
|
|
+ {interceptor: instanceA, order: 200 },
|
|
|
|
|
+ {interceptor: instanceB, order: 100 },
|
|
|
|
|
+ ...
|
|
|
|
|
+ ] */
|
|
|
this.interceptors = [];
|
|
this.interceptors = [];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* add an Interceptor
|
|
* add an Interceptor
|
|
|
* @param {BasicInterceptor} interceptor
|
|
* @param {BasicInterceptor} interceptor
|
|
|
|
|
+ * @param {number} order
|
|
|
*/
|
|
*/
|
|
|
- addInterceptor(interceptor) {
|
|
|
|
|
- this.addInterceptors([interceptor]);
|
|
|
|
|
|
|
+ addInterceptor(interceptor, order) {
|
|
|
|
|
+ this.addInterceptors([interceptor], order);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* add Interceptors
|
|
* add Interceptors
|
|
|
* @param {BasicInterceptor[]} interceptors
|
|
* @param {BasicInterceptor[]} interceptors
|
|
|
|
|
+ * @param {number} order
|
|
|
*/
|
|
*/
|
|
|
- addInterceptors(interceptors) {
|
|
|
|
|
|
|
+ addInterceptors(interceptors, order) {
|
|
|
|
|
+ let isDefaultOrder = false;
|
|
|
|
|
+ if (order == null) {
|
|
|
|
|
+ order = 100;
|
|
|
|
|
+ isDefaultOrder = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const interceptorIds = interceptors.map((i) => i.getId());
|
|
const interceptorIds = interceptors.map((i) => i.getId());
|
|
|
- logger.debug(`adding interceptors '${interceptorIds}'`);
|
|
|
|
|
- this.interceptors = this.interceptors.concat(interceptors);
|
|
|
|
|
|
|
+ logger.info(`'addInterceptors' invoked. adding interceptors '${interceptorIds}' at order=${order}${isDefaultOrder ? '(default)' : ''}`);
|
|
|
|
|
+
|
|
|
|
|
+ this.interceptorAndOrders = this.interceptorAndOrders.concat(
|
|
|
|
|
+ interceptors.map(interceptor => {
|
|
|
|
|
+ return { interceptor, order };
|
|
|
|
|
+ })
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // sort asc
|
|
|
|
|
+ this.interceptorAndOrders.sort((a, b) => a.order - b.order);
|
|
|
|
|
+ // store sorted list
|
|
|
|
|
+ this.interceptors = this.interceptorAndOrders.map(obj => obj.interceptor);
|
|
|
|
|
+
|
|
|
|
|
+ const thisInterceptorIds = this.interceptors.map((i) => i.getId());
|
|
|
|
|
+ logger.info(`interceptors list has initialized: ${thisInterceptorIds}`);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|