fully deletable videos -- enable/disable with cli args
This commit is contained in:
		@@ -15,7 +15,8 @@ func readVideosFromResultset(rows *sql.Rows) []types.VideoUnloadedType {
 | 
				
			|||||||
		var vid types.VideoUnloadedType
 | 
							var vid types.VideoUnloadedType
 | 
				
			||||||
		err := rows.Scan(&vid.MovieId, &vid.MovieName)
 | 
							err := rows.Scan(&vid.MovieId, &vid.MovieName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			panic(err.Error()) // proper error handling instead of panic in your app
 | 
								fmt.Println(err.Error())
 | 
				
			||||||
 | 
								return nil
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result = append(result, vid)
 | 
							result = append(result, vid)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,6 +6,8 @@ import (
 | 
				
			|||||||
	"net/url"
 | 
						"net/url"
 | 
				
			||||||
	"openmediacenter/apiGo/api/types"
 | 
						"openmediacenter/apiGo/api/types"
 | 
				
			||||||
	"openmediacenter/apiGo/database"
 | 
						"openmediacenter/apiGo/database"
 | 
				
			||||||
 | 
						"openmediacenter/apiGo/database/settings"
 | 
				
			||||||
 | 
						"os"
 | 
				
			||||||
	"strconv"
 | 
						"strconv"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -423,7 +425,8 @@ func addToVideoHandlers() {
 | 
				
			|||||||
	 */
 | 
						 */
 | 
				
			||||||
	AddHandler("deleteVideo", VideoNode, func(info *HandlerInfo) []byte {
 | 
						AddHandler("deleteVideo", VideoNode, func(info *HandlerInfo) []byte {
 | 
				
			||||||
		var args struct {
 | 
							var args struct {
 | 
				
			||||||
			MovieId int
 | 
								MovieId     int
 | 
				
			||||||
 | 
								FullyDelete bool
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if err := FillStruct(&args, info.Data); err != nil {
 | 
							if err := FillStruct(&args, info.Data); err != nil {
 | 
				
			||||||
			fmt.Println(err.Error())
 | 
								fmt.Println(err.Error())
 | 
				
			||||||
@@ -443,6 +446,22 @@ func addToVideoHandlers() {
 | 
				
			|||||||
			return database.ManualSuccessResponse(err)
 | 
								return database.ManualSuccessResponse(err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if settings.VideosDeletable() && args.FullyDelete {
 | 
				
			||||||
 | 
								// get physical path of video to delete
 | 
				
			||||||
 | 
								query = fmt.Sprintf("SELECT movie_url FROM videos WHERE movie_id=%d", args.MovieId)
 | 
				
			||||||
 | 
								var vidpath string
 | 
				
			||||||
 | 
								err := database.QueryRow(query).Scan(&vidpath)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return database.ManualSuccessResponse(err)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								err = os.Remove(vidpath)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									fmt.Printf("unable to delete file: %s\n", vidpath)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// delete video row from db
 | 
				
			||||||
		query = fmt.Sprintf("DELETE FROM videos WHERE movie_id=%d", args.MovieId)
 | 
							query = fmt.Sprintf("DELETE FROM videos WHERE movie_id=%d", args.MovieId)
 | 
				
			||||||
		return database.SuccessQuery(query)
 | 
							return database.SuccessQuery(query)
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
package settings
 | 
					package settings
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var tvShowEnabled bool
 | 
					var tvShowEnabled bool
 | 
				
			||||||
 | 
					var videosDeletable bool
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func TVShowsEnabled() bool {
 | 
					func TVShowsEnabled() bool {
 | 
				
			||||||
	return tvShowEnabled
 | 
						return tvShowEnabled
 | 
				
			||||||
@@ -9,3 +10,11 @@ func TVShowsEnabled() bool {
 | 
				
			|||||||
func SetTVShowEnabled(enabled bool) {
 | 
					func SetTVShowEnabled(enabled bool) {
 | 
				
			||||||
	tvShowEnabled = enabled
 | 
						tvShowEnabled = enabled
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func VideosDeletable() bool {
 | 
				
			||||||
 | 
						return videosDeletable
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func SetVideosDeletable(deletable bool) {
 | 
				
			||||||
 | 
						videosDeletable = deletable
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,10 +57,12 @@ func handleCommandLineArguments() (*database.DatabaseConfig, bool, *string) {
 | 
				
			|||||||
	pathPrefix := flag.String("ReindexPrefix", "/var/www/openmediacenter", "Prefix path for videos to reindex")
 | 
						pathPrefix := flag.String("ReindexPrefix", "/var/www/openmediacenter", "Prefix path for videos to reindex")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	disableTVShowSupport := flag.Bool("DisableTVSupport", false, "Disable the TVShow support and pages")
 | 
						disableTVShowSupport := flag.Bool("DisableTVSupport", false, "Disable the TVShow support and pages")
 | 
				
			||||||
 | 
						videosFullyDeletable := flag.Bool("FullyDeletableVideos", false, "Allow deletion from harddisk")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	flag.Parse()
 | 
						flag.Parse()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	settings2.SetTVShowEnabled(!*disableTVShowSupport)
 | 
						settings2.SetTVShowEnabled(!*disableTVShowSupport)
 | 
				
			||||||
 | 
						settings2.SetVideosDeletable(*videosFullyDeletable)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &database.DatabaseConfig{
 | 
						return &database.DatabaseConfig{
 | 
				
			||||||
		DBHost:     *dbhostPtr,
 | 
							DBHost:     *dbhostPtr,
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										37
									
								
								src/elements/Popups/FullyDeletePopup/FullyDeletePopup.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/elements/Popups/FullyDeletePopup/FullyDeletePopup.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					import React from 'react';
 | 
				
			||||||
 | 
					import PopupBase from '../PopupBase';
 | 
				
			||||||
 | 
					import {Button} from '../../GPElements/Button';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * Delete Video popup
 | 
				
			||||||
 | 
					 * can only be rendered once!
 | 
				
			||||||
 | 
					 * @constructor
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					export const FullyDeletePopup = (props: {onSubmit: () => void; onDeny: () => void; onDiscard: () => void}): JSX.Element => {
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					        <>
 | 
				
			||||||
 | 
					            <PopupBase
 | 
				
			||||||
 | 
					                title='Fully Delete Video?'
 | 
				
			||||||
 | 
					                onHide={(): void => props.onDiscard()}
 | 
				
			||||||
 | 
					                height='200px'
 | 
				
			||||||
 | 
					                width='350px'
 | 
				
			||||||
 | 
					                ParentSubmit={(): void => {
 | 
				
			||||||
 | 
					                    props.onSubmit();
 | 
				
			||||||
 | 
					                }}>
 | 
				
			||||||
 | 
					                <Button
 | 
				
			||||||
 | 
					                    onClick={(): void => {
 | 
				
			||||||
 | 
					                        props.onSubmit();
 | 
				
			||||||
 | 
					                    }}
 | 
				
			||||||
 | 
					                    title='Fully Delete!'
 | 
				
			||||||
 | 
					                />
 | 
				
			||||||
 | 
					                <Button
 | 
				
			||||||
 | 
					                    color={{backgroundColor: 'red'}}
 | 
				
			||||||
 | 
					                    onClick={(): void => {
 | 
				
			||||||
 | 
					                        props.onDeny();
 | 
				
			||||||
 | 
					                    }}
 | 
				
			||||||
 | 
					                    title='Only DB Entries'
 | 
				
			||||||
 | 
					                />
 | 
				
			||||||
 | 
					            </PopupBase>
 | 
				
			||||||
 | 
					        </>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -21,6 +21,7 @@ import PlyrJS from 'plyr';
 | 
				
			|||||||
import {Button} from '../../elements/GPElements/Button';
 | 
					import {Button} from '../../elements/GPElements/Button';
 | 
				
			||||||
import {VideoTypes} from '../../types/ApiTypes';
 | 
					import {VideoTypes} from '../../types/ApiTypes';
 | 
				
			||||||
import GlobalInfos from '../../utils/GlobalInfos';
 | 
					import GlobalInfos from '../../utils/GlobalInfos';
 | 
				
			||||||
 | 
					import {FullyDeletePopup} from '../../elements/Popups/FullyDeletePopup/FullyDeletePopup';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface Props extends RouteComponentProps<{id: string}> {}
 | 
					interface Props extends RouteComponentProps<{id: string}> {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -35,6 +36,7 @@ interface mystate {
 | 
				
			|||||||
    suggesttag: TagType[];
 | 
					    suggesttag: TagType[];
 | 
				
			||||||
    popupvisible: boolean;
 | 
					    popupvisible: boolean;
 | 
				
			||||||
    actorpopupvisible: boolean;
 | 
					    actorpopupvisible: boolean;
 | 
				
			||||||
 | 
					    deletepopupvisible: boolean;
 | 
				
			||||||
    actors: ActorType[];
 | 
					    actors: ActorType[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -56,6 +58,7 @@ export class Player extends React.Component<Props, mystate> {
 | 
				
			|||||||
            suggesttag: [],
 | 
					            suggesttag: [],
 | 
				
			||||||
            popupvisible: false,
 | 
					            popupvisible: false,
 | 
				
			||||||
            actorpopupvisible: false,
 | 
					            actorpopupvisible: false,
 | 
				
			||||||
 | 
					            deletepopupvisible: false,
 | 
				
			||||||
            actors: []
 | 
					            actors: []
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -91,7 +94,7 @@ export class Player extends React.Component<Props, mystate> {
 | 
				
			|||||||
                        <Button
 | 
					                        <Button
 | 
				
			||||||
                            title='Delete Video'
 | 
					                            title='Delete Video'
 | 
				
			||||||
                            onClick={(): void => {
 | 
					                            onClick={(): void => {
 | 
				
			||||||
                                this.deleteVideo();
 | 
					                                this.setState({deletepopupvisible: true});
 | 
				
			||||||
                            }}
 | 
					                            }}
 | 
				
			||||||
                            color={{backgroundColor: 'red'}}
 | 
					                            color={{backgroundColor: 'red'}}
 | 
				
			||||||
                        />
 | 
					                        />
 | 
				
			||||||
@@ -196,6 +199,19 @@ export class Player extends React.Component<Props, mystate> {
 | 
				
			|||||||
                        movieId={this.state.movieId}
 | 
					                        movieId={this.state.movieId}
 | 
				
			||||||
                    />
 | 
					                    />
 | 
				
			||||||
                ) : null}
 | 
					                ) : null}
 | 
				
			||||||
 | 
					                {this.state.deletepopupvisible ? (
 | 
				
			||||||
 | 
					                    <FullyDeletePopup
 | 
				
			||||||
 | 
					                        onDiscard={(): void => this.setState({deletepopupvisible: false})}
 | 
				
			||||||
 | 
					                        onSubmit={(): void => {
 | 
				
			||||||
 | 
					                            this.setState({deletepopupvisible: false});
 | 
				
			||||||
 | 
					                            this.deleteVideo(true);
 | 
				
			||||||
 | 
					                        }}
 | 
				
			||||||
 | 
					                        onDeny={(): void => {
 | 
				
			||||||
 | 
					                            this.setState({deletepopupvisible: false});
 | 
				
			||||||
 | 
					                            this.deleteVideo(false);
 | 
				
			||||||
 | 
					                        }}
 | 
				
			||||||
 | 
					                    />
 | 
				
			||||||
 | 
					                ) : null}
 | 
				
			||||||
            </>
 | 
					            </>
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -325,10 +341,10 @@ export class Player extends React.Component<Props, mystate> {
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * delete the current video and return to last page
 | 
					     * delete the current video and return to last page
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    deleteVideo(): void {
 | 
					    deleteVideo(fullyDelete: boolean): void {
 | 
				
			||||||
        callAPI(
 | 
					        callAPI(
 | 
				
			||||||
            APINode.Video,
 | 
					            APINode.Video,
 | 
				
			||||||
            {action: 'deleteVideo', MovieId: parseInt(this.props.match.params.id, 10)},
 | 
					            {action: 'deleteVideo', MovieId: parseInt(this.props.match.params.id, 10), FullyDelete: fullyDelete},
 | 
				
			||||||
            (result: GeneralSuccess) => {
 | 
					            (result: GeneralSuccess) => {
 | 
				
			||||||
                if (result.result === 'success') {
 | 
					                if (result.result === 'success') {
 | 
				
			||||||
                    // return to last element if successful
 | 
					                    // return to last element if successful
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user