mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-24 17:47:46 +01:00
Switch APIs to v2.0
Signed-off-by: AllForNothing <sshijun@vmware.com>
This commit is contained in:
parent
94787ea60d
commit
121314358a
@ -45,6 +45,7 @@ import { LabelsComponent } from './labels/labels.component';
|
||||
import { ProjectQuotasComponent } from './project-quotas/project-quotas.component';
|
||||
import { HarborLibraryModule } from "../lib/harbor-library.module";
|
||||
import { HTTP_INTERCEPTORS } from '@angular/common/http';
|
||||
import { BaseHrefInterceptService } from "./base-href-intercept.service";
|
||||
|
||||
registerLocaleData(zh, 'zh-cn');
|
||||
registerLocaleData(es, 'es-es');
|
||||
@ -98,6 +99,7 @@ export function getCurrentLanguage(translateService: TranslateService) {
|
||||
multi: true
|
||||
},
|
||||
{ provide: LOCALE_ID, useValue: "en-US" },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: BaseHrefInterceptService, multi: true },
|
||||
{ provide: HTTP_INTERCEPTORS, useClass: InterceptHttpService, multi: true }
|
||||
|
||||
],
|
||||
|
18
src/portal/src/app/base-href-intercept.service.spec.ts
Normal file
18
src/portal/src/app/base-href-intercept.service.spec.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { BaseHrefInterceptService } from "./base-href-intercept.service";
|
||||
|
||||
|
||||
describe('BaseHrefSwitchService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
BaseHrefInterceptService
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
const service: BaseHrefInterceptService = TestBed.get(BaseHrefInterceptService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
22
src/portal/src/app/base-href-intercept.service.ts
Normal file
22
src/portal/src/app/base-href-intercept.service.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
const BASE_HREF = '/api';
|
||||
enum APILevels {
|
||||
'V1.0' = '',
|
||||
'V2.0' = '/v2.0'
|
||||
}
|
||||
@Injectable()
|
||||
export class BaseHrefInterceptService implements HttpInterceptor {
|
||||
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<any> {
|
||||
let url: string = req.url;
|
||||
// use API level v2.0
|
||||
if (url && url.indexOf(BASE_HREF) !== -1 && url.indexOf(BASE_HREF + APILevels["V2.0"]) === -1) {
|
||||
url = BASE_HREF + APILevels["V2.0"] + url.split(BASE_HREF)[1];
|
||||
}
|
||||
const apiReq = req.clone({url});
|
||||
return next.handle(apiReq);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user