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 { MatButtonModule } from "@angular/material/button";
|
||||
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 { StartupService } from "./services/startup.service";
|
||||
import { LongPressDirective } from "./misc/long-press.directive";
|
||||
import { DatetimeInterceptorService } from "./services/datetime-interceptor.service";
|
||||
|
||||
|
||||
@NgModule({
|
||||
@ -115,6 +116,11 @@ import { LongPressDirective } from "./misc/long-press.directive";
|
||||
useFactory: (startup: StartupService) => () => startup.load(),
|
||||
deps: [StartupService],
|
||||
multi: true
|
||||
},
|
||||
{
|
||||
provide: HTTP_INTERCEPTORS,
|
||||
useClass: DatetimeInterceptorService,
|
||||
multi: true
|
||||
}
|
||||
]
|
||||
})
|
||||
|
@ -226,25 +226,22 @@ export class ItemsGridComponent implements OnInit
|
||||
replaceUrl: true,
|
||||
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], {
|
||||
replaceUrl: true,
|
||||
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], {
|
||||
replaceUrl: true,
|
||||
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};
|
||||
if (this.router.url.startsWith("/studio") && category !== "studio")
|
||||
@ -259,15 +256,17 @@ export class ItemsGridComponent implements OnInit
|
||||
replaceUrl: true,
|
||||
queryParamsHandling: "merge"
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {[category]: param},
|
||||
replaceUrl: true,
|
||||
queryParamsHandling: "merge"
|
||||
});
|
||||
else
|
||||
{
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: {[category]: param},
|
||||
replaceUrl: true,
|
||||
queryParamsHandling: "merge"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
nameGetter(obj: Studio): string
|
||||
|
@ -24,10 +24,10 @@ export class ItemsUtils
|
||||
if ("type" in item && item.type && typeof item.type === "string")
|
||||
return item.type;
|
||||
|
||||
if (!("startYear" in item))
|
||||
if (!("startAir" in item))
|
||||
return "";
|
||||
if (item.endYear && item.startYear !== item.endYear)
|
||||
return `${item.startYear} - ${item.endYear}`;
|
||||
return item.startYear?.toString();
|
||||
if (item.endAir && item.startAir !== item.endAir)
|
||||
return `${item.startAir.getFullYear()} - ${item.endAir.getFullYear()}`;
|
||||
return item.startAir?.getFullYear().toString();
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ export interface Collection extends IResource
|
||||
name: string;
|
||||
poster: string;
|
||||
overview: string;
|
||||
startYear: number;
|
||||
endYear: number;
|
||||
startAir: Date;
|
||||
endAir: Date;
|
||||
shows: Show[];
|
||||
}
|
||||
|
@ -13,8 +13,8 @@ export interface LibraryItem extends IResource
|
||||
overview: string;
|
||||
status: string;
|
||||
trailerUrl: string;
|
||||
startYear: number;
|
||||
endYear: number;
|
||||
startAir: Date;
|
||||
endAir: Date;
|
||||
poster: string;
|
||||
type: ItemType;
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ export interface Show extends IResource
|
||||
seasons: Season[];
|
||||
trailerUrl: string;
|
||||
isMovie: boolean;
|
||||
startYear: number;
|
||||
endYear: number;
|
||||
startAir: Date;
|
||||
endAir: Date;
|
||||
poster: string;
|
||||
logo: string;
|
||||
backdrop: string;
|
||||
@ -37,8 +37,8 @@ export interface ShowRole extends IResource
|
||||
status: string;
|
||||
trailerUrl: string;
|
||||
isMovie: boolean;
|
||||
startYear: number;
|
||||
endYear: number;
|
||||
startAir: Date;
|
||||
endAir: Date;
|
||||
poster: string;
|
||||
logo: 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