mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Udating to the new api
This commit is contained in:
parent
dcdebad14c
commit
87783a5bfd
@ -1,4 +1,4 @@
|
|||||||
import { HttpClientModule } from "@angular/common/http";
|
import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http";
|
||||||
import { APP_INITIALIZER, NgModule } from "@angular/core";
|
import { APP_INITIALIZER, NgModule } from "@angular/core";
|
||||||
import { MatButtonModule } from "@angular/material/button";
|
import { MatButtonModule } from "@angular/material/button";
|
||||||
import { MatCardModule } from "@angular/material/card";
|
import { MatCardModule } from "@angular/material/card";
|
||||||
@ -48,6 +48,7 @@ import { ShowGridComponent } from "./components/show-grid/show-grid.component";
|
|||||||
import { MatBadgeModule } from "@angular/material/badge";
|
import { MatBadgeModule } from "@angular/material/badge";
|
||||||
import { StartupService } from "./services/startup.service";
|
import { StartupService } from "./services/startup.service";
|
||||||
import { LongPressDirective } from "./misc/long-press.directive";
|
import { LongPressDirective } from "./misc/long-press.directive";
|
||||||
|
import { DatetimeInterceptorService } from "./services/datetime-interceptor.service";
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
@ -115,6 +116,11 @@ import { LongPressDirective } from "./misc/long-press.directive";
|
|||||||
useFactory: (startup: StartupService) => () => startup.load(),
|
useFactory: (startup: StartupService) => () => startup.load(),
|
||||||
deps: [StartupService],
|
deps: [StartupService],
|
||||||
multi: true
|
multi: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: HTTP_INTERCEPTORS,
|
||||||
|
useClass: DatetimeInterceptorService,
|
||||||
|
multi: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
@ -226,25 +226,22 @@ export class ItemsGridComponent implements OnInit
|
|||||||
replaceUrl: true,
|
replaceUrl: true,
|
||||||
queryParams: {sortBy: this.route.snapshot.queryParams.sortBy}
|
queryParams: {sortBy: this.route.snapshot.queryParams.sortBy}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (this.filters.studio != null && this.getFilterCount() === 1)
|
else if (this.filters.studio != null && this.getFilterCount() === 1)
|
||||||
{
|
{
|
||||||
this.router.navigate(["studio", this.filters.studio.slug], {
|
this.router.navigate(["studio", this.filters.studio.slug], {
|
||||||
replaceUrl: true,
|
replaceUrl: true,
|
||||||
queryParams: {sortBy: this.route.snapshot.queryParams.sortBy}
|
queryParams: {sortBy: this.route.snapshot.queryParams.sortBy}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (this.filters.people.length === 1 && this.getFilterCount() === 1)
|
else if (this.filters.people.length === 1 && this.getFilterCount() === 1)
|
||||||
{
|
{
|
||||||
this.router.navigate(["people", this.filters.people[0].slug], {
|
this.router.navigate(["people", this.filters.people[0].slug], {
|
||||||
replaceUrl: true,
|
replaceUrl: true,
|
||||||
queryParams: {sortBy: this.route.snapshot.queryParams.sortBy}
|
queryParams: {sortBy: this.route.snapshot.queryParams.sortBy}
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (this.getFilterCount() === 0 || this.router.url !== "/browse")
|
else if (this.getFilterCount() === 0 || this.router.url !== "/browse")
|
||||||
{
|
{
|
||||||
const params: {[key: string]: string} = {[category]: param};
|
const params: {[key: string]: string} = {[category]: param};
|
||||||
if (this.router.url.startsWith("/studio") && category !== "studio")
|
if (this.router.url.startsWith("/studio") && category !== "studio")
|
||||||
@ -259,15 +256,17 @@ export class ItemsGridComponent implements OnInit
|
|||||||
replaceUrl: true,
|
replaceUrl: true,
|
||||||
queryParamsHandling: "merge"
|
queryParamsHandling: "merge"
|
||||||
});
|
});
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.router.navigate([], {
|
else
|
||||||
relativeTo: this.route,
|
{
|
||||||
queryParams: {[category]: param},
|
this.router.navigate([], {
|
||||||
replaceUrl: true,
|
relativeTo: this.route,
|
||||||
queryParamsHandling: "merge"
|
queryParams: {[category]: param},
|
||||||
});
|
replaceUrl: true,
|
||||||
|
queryParamsHandling: "merge"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nameGetter(obj: Studio): string
|
nameGetter(obj: Studio): string
|
||||||
|
@ -24,10 +24,10 @@ export class ItemsUtils
|
|||||||
if ("type" in item && item.type && typeof item.type === "string")
|
if ("type" in item && item.type && typeof item.type === "string")
|
||||||
return item.type;
|
return item.type;
|
||||||
|
|
||||||
if (!("startYear" in item))
|
if (!("startAir" in item))
|
||||||
return "";
|
return "";
|
||||||
if (item.endYear && item.startYear !== item.endYear)
|
if (item.endAir && item.startAir !== item.endAir)
|
||||||
return `${item.startYear} - ${item.endYear}`;
|
return `${item.startAir.getFullYear()} - ${item.endAir.getFullYear()}`;
|
||||||
return item.startYear?.toString();
|
return item.startAir?.getFullYear().toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ export interface Collection extends IResource
|
|||||||
name: string;
|
name: string;
|
||||||
poster: string;
|
poster: string;
|
||||||
overview: string;
|
overview: string;
|
||||||
startYear: number;
|
startAir: Date;
|
||||||
endYear: number;
|
endAir: Date;
|
||||||
shows: Show[];
|
shows: Show[];
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,8 @@ export interface LibraryItem extends IResource
|
|||||||
overview: string;
|
overview: string;
|
||||||
status: string;
|
status: string;
|
||||||
trailerUrl: string;
|
trailerUrl: string;
|
||||||
startYear: number;
|
startAir: Date;
|
||||||
endYear: number;
|
endAir: Date;
|
||||||
poster: string;
|
poster: string;
|
||||||
type: ItemType;
|
type: ItemType;
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,8 @@ export interface Show extends IResource
|
|||||||
seasons: Season[];
|
seasons: Season[];
|
||||||
trailerUrl: string;
|
trailerUrl: string;
|
||||||
isMovie: boolean;
|
isMovie: boolean;
|
||||||
startYear: number;
|
startAir: Date;
|
||||||
endYear: number;
|
endAir: Date;
|
||||||
poster: string;
|
poster: string;
|
||||||
logo: string;
|
logo: string;
|
||||||
backdrop: string;
|
backdrop: string;
|
||||||
@ -37,8 +37,8 @@ export interface ShowRole extends IResource
|
|||||||
status: string;
|
status: string;
|
||||||
trailerUrl: string;
|
trailerUrl: string;
|
||||||
isMovie: boolean;
|
isMovie: boolean;
|
||||||
startYear: number;
|
startAir: Date;
|
||||||
endYear: number;
|
endAir: Date;
|
||||||
poster: string;
|
poster: string;
|
||||||
logo: string;
|
logo: string;
|
||||||
backdrop: string;
|
backdrop: string;
|
||||||
|
40
src/app/services/datetime-interceptor.service.ts
Normal file
40
src/app/services/datetime-interceptor.service.ts
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from "@angular/common/http";
|
||||||
|
import { Observable } from "rxjs";
|
||||||
|
import { map } from "rxjs/operators";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class DatetimeInterceptorService implements HttpInterceptor
|
||||||
|
{
|
||||||
|
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>
|
||||||
|
{
|
||||||
|
return next.handle(request)
|
||||||
|
.pipe(map((event: HttpEvent<any>) =>
|
||||||
|
{
|
||||||
|
if (event instanceof HttpResponse)
|
||||||
|
return event.clone({body: this.convertDates(event.body)});
|
||||||
|
return event;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private convertDates<T>(object: T): T | Date
|
||||||
|
{
|
||||||
|
if (typeof(object) === "string" && /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z?$/.exec(object))
|
||||||
|
{
|
||||||
|
return new Date(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object instanceof Array)
|
||||||
|
{
|
||||||
|
for (const i in object)
|
||||||
|
object[i] = this.convertDates(object[i]);
|
||||||
|
}
|
||||||
|
else if (object instanceof Object)
|
||||||
|
{
|
||||||
|
for (const key of Object.keys(object))
|
||||||
|
object[key] = this.convertDates(object[key]);
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user