mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	add versioning support to the API
This commit is contained in:
		| @@ -62,6 +62,7 @@ import { CustomDatePipe } from './pipes/custom-date.pipe'; | ||||
| import { DateComponent } from './components/common/input/date/date.component'; | ||||
| import { ISODateTimeAdapter } from './utils/ngb-iso-date-time-adapter'; | ||||
| import { LocalizedDateParserFormatter } from './utils/ngb-date-parser-formatter'; | ||||
| import { ApiVersionInterceptor } from './interceptors/api-version.interceptor'; | ||||
|  | ||||
| import localeFr from '@angular/common/locales/fr'; | ||||
| import localeNl from '@angular/common/locales/nl'; | ||||
| @@ -144,6 +145,10 @@ registerLocaleData(localeEnGb) | ||||
|       provide: HTTP_INTERCEPTORS, | ||||
|       useClass: CsrfInterceptor, | ||||
|       multi: true | ||||
|     },{ | ||||
|       provide: HTTP_INTERCEPTORS, | ||||
|       useClass: ApiVersionInterceptor, | ||||
|       multi: true | ||||
|     }, | ||||
|     FilterPipe, | ||||
|     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 = { | ||||
|   production: true, | ||||
|   apiBaseUrl: "/api/", | ||||
|   apiVersion: "1", | ||||
|   appTitle: "Paperless-ng", | ||||
|   version: "1.2.1", | ||||
|   webSocketHost: window.location.host, | ||||
|   | ||||
| @@ -5,6 +5,7 @@ | ||||
| export const environment = { | ||||
|   production: false, | ||||
|   apiBaseUrl: "http://localhost:8000/api/", | ||||
|   apiVersion: "1", | ||||
|   appTitle: "Paperless-ng", | ||||
|   version: "DEVELOPMENT", | ||||
|   webSocketHost: "localhost:8000", | ||||
|   | ||||
| @@ -112,7 +112,10 @@ REST_FRAMEWORK = { | ||||
|         'rest_framework.authentication.BasicAuthentication', | ||||
|         'rest_framework.authentication.SessionAuthentication', | ||||
|         'rest_framework.authentication.TokenAuthentication' | ||||
|     ] | ||||
|     ], | ||||
|     'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.AcceptHeaderVersioning', | ||||
|     'DEFAULT_VERSION': 'v1', | ||||
|     'ALLOWED_VERSIONS': ['1', '2'] | ||||
| } | ||||
|  | ||||
| if DEBUG: | ||||
| @@ -142,7 +145,7 @@ ASGI_APPLICATION = "paperless.asgi.application" | ||||
|  | ||||
| STATIC_URL = os.getenv("PAPERLESS_STATIC_URL", "/static/") | ||||
|  | ||||
| # what is this used for? | ||||
| # TODO: what is this used for? | ||||
| TEMPLATES = [ | ||||
|     { | ||||
|         'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 jonaswinkler
					jonaswinkler