mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
add versioning support to the API
This commit is contained in:
parent
df87599f1b
commit
3d3300ac32
@ -62,6 +62,7 @@ import { CustomDatePipe } from './pipes/custom-date.pipe';
|
|||||||
import { DateComponent } from './components/common/input/date/date.component';
|
import { DateComponent } from './components/common/input/date/date.component';
|
||||||
import { ISODateTimeAdapter } from './utils/ngb-iso-date-time-adapter';
|
import { ISODateTimeAdapter } from './utils/ngb-iso-date-time-adapter';
|
||||||
import { LocalizedDateParserFormatter } from './utils/ngb-date-parser-formatter';
|
import { LocalizedDateParserFormatter } from './utils/ngb-date-parser-formatter';
|
||||||
|
import { ApiVersionInterceptor } from './interceptors/api-version.interceptor';
|
||||||
|
|
||||||
import localeFr from '@angular/common/locales/fr';
|
import localeFr from '@angular/common/locales/fr';
|
||||||
import localeNl from '@angular/common/locales/nl';
|
import localeNl from '@angular/common/locales/nl';
|
||||||
@ -144,6 +145,10 @@ registerLocaleData(localeEnGb)
|
|||||||
provide: HTTP_INTERCEPTORS,
|
provide: HTTP_INTERCEPTORS,
|
||||||
useClass: CsrfInterceptor,
|
useClass: CsrfInterceptor,
|
||||||
multi: true
|
multi: true
|
||||||
|
},{
|
||||||
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
useClass: ApiVersionInterceptor,
|
||||||
|
multi: true
|
||||||
},
|
},
|
||||||
FilterPipe,
|
FilterPipe,
|
||||||
DocumentTitlePipe,
|
DocumentTitlePipe,
|
||||||
|
16
src-ui/src/app/interceptors/api-version.interceptor.spec.ts
Normal file
16
src-ui/src/app/interceptors/api-version.interceptor.spec.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ApiVersionInterceptor } from './api-version.interceptor';
|
||||||
|
|
||||||
|
describe('ApiVersionInterceptor', () => {
|
||||||
|
beforeEach(() => TestBed.configureTestingModule({
|
||||||
|
providers: [
|
||||||
|
ApiVersionInterceptor
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
const interceptor: ApiVersionInterceptor = TestBed.inject(ApiVersionInterceptor);
|
||||||
|
expect(interceptor).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
25
src-ui/src/app/interceptors/api-version.interceptor.ts
Normal file
25
src-ui/src/app/interceptors/api-version.interceptor.ts
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import {
|
||||||
|
HttpRequest,
|
||||||
|
HttpHandler,
|
||||||
|
HttpEvent,
|
||||||
|
HttpInterceptor
|
||||||
|
} from '@angular/common/http';
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ApiVersionInterceptor implements HttpInterceptor {
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
|
||||||
|
intercept(request: HttpRequest<unknown>, next: HttpHandler): Observable<HttpEvent<unknown>> {
|
||||||
|
request = request.clone({
|
||||||
|
setHeaders: {
|
||||||
|
'Accept': `application/json; version=${environment.apiVersion}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return next.handle(request);
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: true,
|
production: true,
|
||||||
apiBaseUrl: "/api/",
|
apiBaseUrl: "/api/",
|
||||||
|
apiVersion: "1",
|
||||||
appTitle: "Paperless-ng",
|
appTitle: "Paperless-ng",
|
||||||
version: "1.2.1",
|
version: "1.2.1",
|
||||||
webSocketHost: window.location.host,
|
webSocketHost: window.location.host,
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
apiBaseUrl: "http://localhost:8000/api/",
|
apiBaseUrl: "http://localhost:8000/api/",
|
||||||
|
apiVersion: "1",
|
||||||
appTitle: "Paperless-ng",
|
appTitle: "Paperless-ng",
|
||||||
version: "DEVELOPMENT",
|
version: "DEVELOPMENT",
|
||||||
webSocketHost: "localhost:8000",
|
webSocketHost: "localhost:8000",
|
||||||
|
@ -112,7 +112,10 @@ REST_FRAMEWORK = {
|
|||||||
'rest_framework.authentication.BasicAuthentication',
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
'rest_framework.authentication.SessionAuthentication',
|
'rest_framework.authentication.SessionAuthentication',
|
||||||
'rest_framework.authentication.TokenAuthentication'
|
'rest_framework.authentication.TokenAuthentication'
|
||||||
]
|
],
|
||||||
|
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning',
|
||||||
|
'DEFAULT_VERSION': 'v1',
|
||||||
|
'ALLOWED_VERSIONS': ['1', '2']
|
||||||
}
|
}
|
||||||
|
|
||||||
if DEBUG:
|
if DEBUG:
|
||||||
@ -142,7 +145,7 @@ ASGI_APPLICATION = "paperless.asgi.application"
|
|||||||
|
|
||||||
STATIC_URL = os.getenv("PAPERLESS_STATIC_URL", "/static/")
|
STATIC_URL = os.getenv("PAPERLESS_STATIC_URL", "/static/")
|
||||||
|
|
||||||
# what is this used for?
|
# TODO: what is this used for?
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user