mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Adding auth pipe for images but not using it
This commit is contained in:
parent
56b247fcd4
commit
39dc1460e9
@ -45,6 +45,7 @@ import {FallbackDirective} from "./misc/fallback.directive";
|
|||||||
import {AuthGuard} from "./misc/guards/authenticated-guard.service";
|
import {AuthGuard} from "./misc/guards/authenticated-guard.service";
|
||||||
import { AutologinComponent } from './autologin/autologin.component';
|
import { AutologinComponent } from './autologin/autologin.component';
|
||||||
import {AuthorizerInterceptor} from "./misc/authorizer-interceptor.service";
|
import {AuthorizerInterceptor} from "./misc/authorizer-interceptor.service";
|
||||||
|
import { AuthPipe } from './misc/auth.pipe';
|
||||||
|
|
||||||
export function loadConfig(oidcConfigService: OidcConfigService)
|
export function loadConfig(oidcConfigService: OidcConfigService)
|
||||||
{
|
{
|
||||||
@ -69,7 +70,8 @@ export function loadConfig(oidcConfigService: OidcConfigService)
|
|||||||
UnauthorizedComponent,
|
UnauthorizedComponent,
|
||||||
LogoutComponent,
|
LogoutComponent,
|
||||||
FallbackDirective,
|
FallbackDirective,
|
||||||
AutologinComponent
|
AutologinComponent,
|
||||||
|
AuthPipe
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
|
30
src/app/misc/auth.pipe.ts
Normal file
30
src/app/misc/auth.pipe.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import {Injector, Pipe, PipeTransform} from '@angular/core';
|
||||||
|
import {AuthService} from "../services/auth.service";
|
||||||
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
|
||||||
|
import {OidcSecurityService} from "angular-auth-oidc-client";
|
||||||
|
|
||||||
|
@Pipe({
|
||||||
|
name: 'auth'
|
||||||
|
})
|
||||||
|
export class AuthPipe implements PipeTransform
|
||||||
|
{
|
||||||
|
private oidcSecurity: OidcSecurityService
|
||||||
|
|
||||||
|
constructor(private injector: Injector, private http: HttpClient) {}
|
||||||
|
|
||||||
|
async transform(uri: string): Promise<string>
|
||||||
|
{
|
||||||
|
if (this.oidcSecurity === undefined)
|
||||||
|
this.oidcSecurity = this.injector.get(OidcSecurityService);
|
||||||
|
let token = this.oidcSecurity.getToken();
|
||||||
|
if (!token)
|
||||||
|
return uri;
|
||||||
|
const headers = new HttpHeaders({"Authorization": "Bearer " + token});
|
||||||
|
const img = await this.http.get(uri, {headers, responseType: 'blob'}).toPromise();
|
||||||
|
const reader = new FileReader();
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
reader.onloadend = () => resolve(reader.result as string);
|
||||||
|
reader.readAsDataURL(img);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user