refactor: rename MovieService to VideoService and remove 'movie' from backend URLs
This commit is contained in:
parent
8deb9c6bdb
commit
7e08f6379f
5 changed files with 33 additions and 33 deletions
|
|
@ -21,9 +21,9 @@ urlpatterns = [
|
||||||
path('django-rq/', include('django_rq.urls')),
|
path('django-rq/', include('django_rq.urls')),
|
||||||
|
|
||||||
# Content URLs
|
# Content URLs
|
||||||
path('video/', video_views.video_list, name='video_list'),
|
path('videos/', video_views.video_list, name='video_list'),
|
||||||
path('video/upload/', video_views.video_upload, name='video_upload'),
|
path('video/upload/', video_views.video_upload, name='video_upload'),
|
||||||
path('video/movie/<int:id>/', video_views.check_video_resolutions, name='check_video_resolutions'),
|
path('video/<int:id>/', video_views.check_video_resolutions, name='check_video_resolutions'),
|
||||||
|
|
||||||
# Users URLs
|
# Users URLs
|
||||||
path('users/', user_views.user_list, name='user_list'),
|
path('users/', user_views.user_list, name='user_list'),
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import {
|
||||||
ViewChild,
|
ViewChild,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component';
|
import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component';
|
||||||
import { MovieService } from '../../../services/movie.service';
|
import { VideoService } from '../../../services/video.service';
|
||||||
import { environment } from '../../../../environments/environment';
|
import { environment } from '../../../../environments/environment';
|
||||||
import { BtnSmallComponent } from '../../../shared/components/buttons/btn-small/btn-small.component';
|
import { BtnSmallComponent } from '../../../shared/components/buttons/btn-small/btn-small.component';
|
||||||
import { UserService } from '../../../services/user.service';
|
import { UserService } from '../../../services/user.service';
|
||||||
|
|
@ -47,7 +47,7 @@ export class HeroBannerComponent implements OnChanges {
|
||||||
movieIsUploaded: { [resolution: string]: boolean };
|
movieIsUploaded: { [resolution: string]: boolean };
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private movieService: MovieService,
|
private videoService: VideoService,
|
||||||
private resolutionService: ResolutionService,
|
private resolutionService: ResolutionService,
|
||||||
public userService: UserService
|
public userService: UserService
|
||||||
) {
|
) {
|
||||||
|
|
@ -78,8 +78,8 @@ export class HeroBannerComponent implements OnChanges {
|
||||||
if (changes['currentMovie'] && this.currentMovie.length > 0) {
|
if (changes['currentMovie'] && this.currentMovie.length > 0) {
|
||||||
const movieId = this.currentMovie[0]?.id;
|
const movieId = this.currentMovie[0]?.id;
|
||||||
if (movieId) {
|
if (movieId) {
|
||||||
this.movieService
|
this.videoService
|
||||||
.isMovieResolutionUploaded(movieId)
|
.isVideoResolutionUploaded(movieId)
|
||||||
.subscribe((resolutions) => {
|
.subscribe((resolutions) => {
|
||||||
this.movieIsUploaded = resolutions;
|
this.movieIsUploaded = resolutions;
|
||||||
this.movieIsUploadedChange.emit(this.movieIsUploaded);
|
this.movieIsUploadedChange.emit(this.movieIsUploaded);
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { HeaderComponent } from '../../shared/components/header/header.component';
|
import { HeaderComponent } from '../../shared/components/header/header.component';
|
||||||
import { HeroBannerComponent } from './hero-banner/hero-banner.component';
|
import { HeroBannerComponent } from './hero-banner/hero-banner.component';
|
||||||
import { CategoriesComponent } from './categories/categories.component';
|
import { CategoriesComponent } from './categories/categories.component';
|
||||||
import { MovieService } from '../../services/movie.service';
|
import { VideoService } from '../../services/video.service';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { VideoPlayerComponent } from './video-player/video-player.component';
|
import { VideoPlayerComponent } from './video-player/video-player.component';
|
||||||
import { BtnSmallComponent } from '../../shared/components/buttons/btn-small/btn-small.component';
|
import { BtnSmallComponent } from '../../shared/components/buttons/btn-small/btn-small.component';
|
||||||
|
|
@ -40,7 +40,7 @@ export class HomeComponent implements OnInit {
|
||||||
movieIsUploaded: { [resolution: string]: boolean };
|
movieIsUploaded: { [resolution: string]: boolean };
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private movieService: MovieService,
|
private videoService: VideoService,
|
||||||
public userService: UserService,
|
public userService: UserService,
|
||||||
private resolutionService: ResolutionService
|
private resolutionService: ResolutionService
|
||||||
) {
|
) {
|
||||||
|
|
@ -113,7 +113,7 @@ export class HomeComponent implements OnInit {
|
||||||
async loadAllMovies() {
|
async loadAllMovies() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
try {
|
try {
|
||||||
this.movies = await this.movieService.getAllMovies();
|
this.movies = await this.videoService.getAllVideos();
|
||||||
} finally {
|
} finally {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Component, EventEmitter, Output } from '@angular/core';
|
||||||
import { FormsModule, NgForm } from '@angular/forms';
|
import { FormsModule, NgForm } from '@angular/forms';
|
||||||
import { ErrorService } from '../../../services/error.service';
|
import { ErrorService } from '../../../services/error.service';
|
||||||
import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component';
|
import { BtnLargeComponent } from '../../../shared/components/buttons/btn-large/btn-large.component';
|
||||||
import { MovieService } from '../../../services/movie.service';
|
import { VideoService } from '../../../services/video.service';
|
||||||
import { LoadingDialogComponent } from '../../../shared/components/loading-dialog/loading-dialog.component';
|
import { LoadingDialogComponent } from '../../../shared/components/loading-dialog/loading-dialog.component';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
|
|
@ -33,7 +33,7 @@ export class UploadMovieComponent {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public errorService: ErrorService,
|
public errorService: ErrorService,
|
||||||
private movieService: MovieService
|
private videoService: VideoService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
stopPropagation(event: MouseEvent) {
|
stopPropagation(event: MouseEvent) {
|
||||||
|
|
@ -74,7 +74,7 @@ export class UploadMovieComponent {
|
||||||
try {
|
try {
|
||||||
this.movieData.send = true;
|
this.movieData.send = true;
|
||||||
let formData = this.createFormData();
|
let formData = this.createFormData();
|
||||||
await this.movieService.uploadMovie(formData);
|
await this.videoService.uploadVideo(formData);
|
||||||
ngForm.resetForm();
|
ngForm.resetForm();
|
||||||
this.closeMovieUploadOverview();
|
this.closeMovieUploadOverview();
|
||||||
this.movieData.send = false;
|
this.movieData.send = false;
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,14 @@ import { ResolutionService } from './resolution.service';
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
})
|
})
|
||||||
export class MovieService {
|
export class VideoService {
|
||||||
private movieCache: {
|
private videoCache: {
|
||||||
[key: number]: { [resolution: string]: boolean };
|
[key: number]: { [resolution: string]: boolean };
|
||||||
} = {};
|
} = {};
|
||||||
private availableResolutions: string[];
|
private availableResolutions: string[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the MovieService with ApiService, AuthService, and ResolutionService
|
* Initializes the VideoService with ApiService, AuthService, and ResolutionService
|
||||||
*
|
*
|
||||||
* It fetches the available resolutions from the ResolutionService and stores
|
* It fetches the available resolutions from the ResolutionService and stores
|
||||||
* them in the availableResolutions field.
|
* them in the availableResolutions field.
|
||||||
|
|
@ -29,63 +29,63 @@ export class MovieService {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch all movies available on the server
|
* Fetch all videos available on the server
|
||||||
*
|
*
|
||||||
* @returns a promise resolving to an array of movie objects
|
* @returns a promise resolving to an array of video objects
|
||||||
*/
|
*/
|
||||||
getAllMovies(): Promise<any> {
|
getAllVideos(): Promise<any> {
|
||||||
return firstValueFrom(this.apiService.get('/video/', true));
|
return firstValueFrom(this.apiService.get('/videos/', true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a movie by its video URL
|
* Fetch a video by its video URL
|
||||||
*
|
*
|
||||||
* @param videoUrl the ID of the movie to fetch
|
* @param videoUrl the ID of the video to fetch
|
||||||
* @returns a promise resolving to the movie object
|
* @returns a promise resolving to the video object
|
||||||
*/
|
*/
|
||||||
getMovieFiles(videoUrl: number): Promise<any> {
|
getVideoFiles(videoUrl: number): Promise<any> {
|
||||||
return firstValueFrom(this.apiService.get(`/${videoUrl}`, true));
|
return firstValueFrom(this.apiService.get(`/${videoUrl}`, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload a movie to the server
|
* Upload a video to the server
|
||||||
*
|
*
|
||||||
* @param formData the FormData object representing the movie to upload
|
* @param formData the FormData object representing the video to upload
|
||||||
* @returns a promise resolved when the upload is successful
|
* @returns a promise resolved when the upload is successful
|
||||||
*/
|
*/
|
||||||
uploadMovie(formData: FormData): Promise<any> {
|
uploadVideo(formData: FormData): Promise<any> {
|
||||||
return firstValueFrom(
|
return firstValueFrom(
|
||||||
this.apiService.post('/video/upload/', formData, true)
|
this.apiService.post('/video/upload/', formData, true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a movie is available in all resolutions on the server.
|
* Check if a video is available in all resolutions on the server.
|
||||||
* This method caches the result to avoid unnecessary requests.
|
* This method caches the result to avoid unnecessary requests.
|
||||||
*
|
*
|
||||||
* @param videoID the ID of the movie to check
|
* @param videoID the ID of the video to check
|
||||||
* @returns a promise resolving to an object with the available resolutions
|
* @returns a promise resolving to an object with the available resolutions
|
||||||
* as keys and booleans indicating the availability as values.
|
* as keys and booleans indicating the availability as values.
|
||||||
*/
|
*/
|
||||||
isMovieResolutionUploaded(
|
isVideoResolutionUploaded(
|
||||||
videoID: number
|
videoID: number
|
||||||
): Observable<{ [resolution: string]: boolean }> {
|
): Observable<{ [resolution: string]: boolean }> {
|
||||||
const cachedResolutions = this.movieCache[videoID];
|
const cachedResolutions = this.videoCache[videoID];
|
||||||
|
|
||||||
if (cachedResolutions && Object.values(cachedResolutions).every(Boolean)) {
|
if (cachedResolutions && Object.values(cachedResolutions).every(Boolean)) {
|
||||||
return of(cachedResolutions);
|
return of(cachedResolutions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.apiService.get(`/video/movie/${videoID}/`, true).pipe(
|
return this.apiService.get(`/video/${videoID}/`, true).pipe(
|
||||||
map((res: any) => {
|
map((res: any) => {
|
||||||
const resolutions = Object.fromEntries(
|
const resolutions = Object.fromEntries(
|
||||||
this.availableResolutions.map((r) => [r, !!res[r]])
|
this.availableResolutions.map((r) => [r, !!res[r]])
|
||||||
);
|
);
|
||||||
this.movieCache[videoID] = resolutions;
|
this.videoCache[videoID] = resolutions;
|
||||||
return resolutions;
|
return resolutions;
|
||||||
}),
|
}),
|
||||||
catchError((error) => {
|
catchError((error) => {
|
||||||
console.error('Failed to fetch movie resolutions', error);
|
console.error('Failed to fetch video resolutions', error);
|
||||||
this.authService.logout();
|
this.authService.logout();
|
||||||
return of(
|
return of(
|
||||||
Object.fromEntries(this.availableResolutions.map((r) => [r, false]))
|
Object.fromEntries(this.availableResolutions.map((r) => [r, false]))
|
||||||
Loading…
Reference in a new issue