fully deletable videos -- enable/disable with cli args
This commit is contained in:
parent
7ebc5766e9
commit
543ce5b250
@ -15,7 +15,8 @@ func readVideosFromResultset(rows *sql.Rows) []types.VideoUnloadedType {
|
||||
var vid types.VideoUnloadedType
|
||||
err := rows.Scan(&vid.MovieId, &vid.MovieName)
|
||||
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)
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import (
|
||||
"net/url"
|
||||
"openmediacenter/apiGo/api/types"
|
||||
"openmediacenter/apiGo/database"
|
||||
"openmediacenter/apiGo/database/settings"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
@ -424,6 +426,7 @@ func addToVideoHandlers() {
|
||||
AddHandler("deleteVideo", VideoNode, func(info *HandlerInfo) []byte {
|
||||
var args struct {
|
||||
MovieId int
|
||||
FullyDelete bool
|
||||
}
|
||||
if err := FillStruct(&args, info.Data); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
@ -443,6 +446,22 @@ func addToVideoHandlers() {
|
||||
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)
|
||||
return database.SuccessQuery(query)
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
package settings
|
||||
|
||||
var tvShowEnabled bool
|
||||
var videosDeletable bool
|
||||
|
||||
func TVShowsEnabled() bool {
|
||||
return tvShowEnabled
|
||||
@ -9,3 +10,11 @@ func TVShowsEnabled() bool {
|
||||
func SetTVShowEnabled(enabled bool) {
|
||||
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")
|
||||
|
||||
disableTVShowSupport := flag.Bool("DisableTVSupport", false, "Disable the TVShow support and pages")
|
||||
videosFullyDeletable := flag.Bool("FullyDeletableVideos", false, "Allow deletion from harddisk")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
settings2.SetTVShowEnabled(!*disableTVShowSupport)
|
||||
settings2.SetVideosDeletable(*videosFullyDeletable)
|
||||
|
||||
return &database.DatabaseConfig{
|
||||
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 {VideoTypes} from '../../types/ApiTypes';
|
||||
import GlobalInfos from '../../utils/GlobalInfos';
|
||||
import {FullyDeletePopup} from '../../elements/Popups/FullyDeletePopup/FullyDeletePopup';
|
||||
|
||||
interface Props extends RouteComponentProps<{id: string}> {}
|
||||
|
||||
@ -35,6 +36,7 @@ interface mystate {
|
||||
suggesttag: TagType[];
|
||||
popupvisible: boolean;
|
||||
actorpopupvisible: boolean;
|
||||
deletepopupvisible: boolean;
|
||||
actors: ActorType[];
|
||||
}
|
||||
|
||||
@ -56,6 +58,7 @@ export class Player extends React.Component<Props, mystate> {
|
||||
suggesttag: [],
|
||||
popupvisible: false,
|
||||
actorpopupvisible: false,
|
||||
deletepopupvisible: false,
|
||||
actors: []
|
||||
};
|
||||
|
||||
@ -91,7 +94,7 @@ export class Player extends React.Component<Props, mystate> {
|
||||
<Button
|
||||
title='Delete Video'
|
||||
onClick={(): void => {
|
||||
this.deleteVideo();
|
||||
this.setState({deletepopupvisible: true});
|
||||
}}
|
||||
color={{backgroundColor: 'red'}}
|
||||
/>
|
||||
@ -196,6 +199,19 @@ export class Player extends React.Component<Props, mystate> {
|
||||
movieId={this.state.movieId}
|
||||
/>
|
||||
) : 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
|
||||
*/
|
||||
deleteVideo(): void {
|
||||
deleteVideo(fullyDelete: boolean): void {
|
||||
callAPI(
|
||||
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) => {
|
||||
if (result.result === 'success') {
|
||||
// return to last element if successful
|
||||
|
Loading…
Reference in New Issue
Block a user