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')),
|
||||
|
||||
# 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/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
|
||||
path('users/', user_views.user_list, name='user_list'),
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import {
|
|||
ViewChild,
|
||||
} from '@angular/core';
|
||||
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 { BtnSmallComponent } from '../../../shared/components/buttons/btn-small/btn-small.component';
|
||||
import { UserService } from '../../../services/user.service';
|
||||
|
|
@ -47,7 +47,7 @@ export class HeroBannerComponent implements OnChanges {
|
|||
movieIsUploaded: { [resolution: string]: boolean };
|
||||
|
||||
constructor(
|
||||
private movieService: MovieService,
|
||||
private videoService: VideoService,
|
||||
private resolutionService: ResolutionService,
|
||||
public userService: UserService
|
||||
) {
|
||||
|
|
@ -78,8 +78,8 @@ export class HeroBannerComponent implements OnChanges {
|
|||
if (changes['currentMovie'] && this.currentMovie.length > 0) {
|
||||
const movieId = this.currentMovie[0]?.id;
|
||||
if (movieId) {
|
||||
this.movieService
|
||||
.isMovieResolutionUploaded(movieId)
|
||||
this.videoService
|
||||
.isVideoResolutionUploaded(movieId)
|
||||
.subscribe((resolutions) => {
|
||||
this.movieIsUploaded = resolutions;
|
||||
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 { HeroBannerComponent } from './hero-banner/hero-banner.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 { VideoPlayerComponent } from './video-player/video-player.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 };
|
||||
|
||||
constructor(
|
||||
private movieService: MovieService,
|
||||
private videoService: VideoService,
|
||||
public userService: UserService,
|
||||
private resolutionService: ResolutionService
|
||||
) {
|
||||
|
|
@ -113,7 +113,7 @@ export class HomeComponent implements OnInit {
|
|||
async loadAllMovies() {
|
||||
this.isLoading = true;
|
||||
try {
|
||||
this.movies = await this.movieService.getAllMovies();
|
||||
this.movies = await this.videoService.getAllVideos();
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Component, EventEmitter, Output } from '@angular/core';
|
|||
import { FormsModule, NgForm } from '@angular/forms';
|
||||
import { ErrorService } from '../../../services/error.service';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
|
|
@ -33,7 +33,7 @@ export class UploadMovieComponent {
|
|||
|
||||
constructor(
|
||||
public errorService: ErrorService,
|
||||
private movieService: MovieService
|
||||
private videoService: VideoService
|
||||
) {}
|
||||
|
||||
stopPropagation(event: MouseEvent) {
|
||||
|
|
@ -74,7 +74,7 @@ export class UploadMovieComponent {
|
|||
try {
|
||||
this.movieData.send = true;
|
||||
let formData = this.createFormData();
|
||||
await this.movieService.uploadMovie(formData);
|
||||
await this.videoService.uploadVideo(formData);
|
||||
ngForm.resetForm();
|
||||
this.closeMovieUploadOverview();
|
||||
this.movieData.send = false;
|
||||
|
|
|
|||
|
|
@ -7,14 +7,14 @@ import { ResolutionService } from './resolution.service';
|
|||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MovieService {
|
||||
private movieCache: {
|
||||
export class VideoService {
|
||||
private videoCache: {
|
||||
[key: number]: { [resolution: string]: boolean };
|
||||
} = {};
|
||||
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
|
||||
* 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> {
|
||||
return firstValueFrom(this.apiService.get('/video/', true));
|
||||
getAllVideos(): Promise<any> {
|
||||
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
|
||||
* @returns a promise resolving to the movie object
|
||||
* @param videoUrl the ID of the video to fetch
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uploadMovie(formData: FormData): Promise<any> {
|
||||
uploadVideo(formData: FormData): Promise<any> {
|
||||
return firstValueFrom(
|
||||
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.
|
||||
*
|
||||
* @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
|
||||
* as keys and booleans indicating the availability as values.
|
||||
*/
|
||||
isMovieResolutionUploaded(
|
||||
isVideoResolutionUploaded(
|
||||
videoID: number
|
||||
): Observable<{ [resolution: string]: boolean }> {
|
||||
const cachedResolutions = this.movieCache[videoID];
|
||||
const cachedResolutions = this.videoCache[videoID];
|
||||
|
||||
if (cachedResolutions && Object.values(cachedResolutions).every(Boolean)) {
|
||||
return of(cachedResolutions);
|
||||
}
|
||||
|
||||
return this.apiService.get(`/video/movie/${videoID}/`, true).pipe(
|
||||
return this.apiService.get(`/video/${videoID}/`, true).pipe(
|
||||
map((res: any) => {
|
||||
const resolutions = Object.fromEntries(
|
||||
this.availableResolutions.map((r) => [r, !!res[r]])
|
||||
);
|
||||
this.movieCache[videoID] = resolutions;
|
||||
this.videoCache[videoID] = resolutions;
|
||||
return resolutions;
|
||||
}),
|
||||
catchError((error) => {
|
||||
console.error('Failed to fetch movie resolutions', error);
|
||||
console.error('Failed to fetch video resolutions', error);
|
||||
this.authService.logout();
|
||||
return of(
|
||||
Object.fromEntries(this.availableResolutions.map((r) => [r, false]))
|
||||
Loading…
Reference in a new issue