fix tests and send feature support within first api call

This commit is contained in:
lukas 2021-09-03 12:09:51 +02:00
parent 543ce5b250
commit 924f05b2d2
9 changed files with 135 additions and 74 deletions

View File

@ -73,6 +73,7 @@ func getSettingsFromDB() {
VideoPath string VideoPath string
TVShowPath string TVShowPath string
TVShowEnabled bool TVShowEnabled bool
FullDeleteEnabled bool
} }
regexMatchUrl := regexp.MustCompile("^http(|s)://([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}") regexMatchUrl := regexp.MustCompile("^http(|s)://([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}")
@ -88,6 +89,7 @@ func getSettingsFromDB() {
VideoPath: serverVideoPath, VideoPath: serverVideoPath,
TVShowPath: serverTVShowPath, TVShowPath: serverTVShowPath,
TVShowEnabled: settings.TVShowsEnabled(), TVShowEnabled: settings.TVShowsEnabled(),
FullDeleteEnabled: settings.VideosDeletable(),
} }
str, _ := json.Marshal(res) str, _ := json.Marshal(res)

View File

@ -420,6 +420,7 @@ func addToVideoHandlers() {
* @apiGroup video * @apiGroup video
* *
* @apiParam {int} MovieId ID of video * @apiParam {int} MovieId ID of video
* @apiParam {bool} FullyDelete Delete video from disk?
* *
* @apiSuccess {string} result 'success' if successfully or error message if not * @apiSuccess {string} result 'success' if successfully or error message if not
*/ */
@ -446,6 +447,7 @@ func addToVideoHandlers() {
return database.ManualSuccessResponse(err) return database.ManualSuccessResponse(err)
} }
// only allow deletion of video if cli flag is set, independent of passed api arg
if settings.VideosDeletable() && args.FullyDelete { if settings.VideosDeletable() && args.FullyDelete {
// get physical path of video to delete // get physical path of video to delete
query = fmt.Sprintf("SELECT movie_url FROM videos WHERE movie_id=%d", args.MovieId) query = fmt.Sprintf("SELECT movie_url FROM videos WHERE movie_id=%d", args.MovieId)
@ -457,7 +459,8 @@ func addToVideoHandlers() {
err = os.Remove(vidpath) err = os.Remove(vidpath)
if err != nil { if err != nil {
fmt.Printf("unable to delete file: %s\n", vidpath) fmt.Printf("unable to delete file: %s -- %s\n", vidpath, err.Error())
return database.ManualSuccessResponse(err)
} }
} }

View File

@ -87,6 +87,7 @@ class App extends React.Component<{}, state> {
GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath); GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath);
GlobalInfos.setTVShowsEnabled(result.TVShowEnabled); GlobalInfos.setTVShowsEnabled(result.TVShowEnabled);
GlobalInfos.setFullDeleteEnabled(result.FullDeleteEnabled);
this.setState({ this.setState({
mediacentername: result.MediacenterName mediacentername: result.MediacenterName

View File

@ -0,0 +1,58 @@
import React from 'react';
import PopupBase from '../PopupBase';
import {Button} from '../../GPElements/Button';
/**
* Delete Video popup
* can only be rendered once!
* @constructor
*/
export const ButtonPopup = (props: {
onSubmit: () => void;
onDeny: () => void;
onAlternativeButton?: () => void;
SubmitButtonTitle: string;
DenyButtonTitle: string;
AlternativeButtonTitle?: string;
Title: string;
}): JSX.Element => {
return (
<>
<PopupBase
title={props.Title}
onHide={(): void => props.onDeny()}
height='200px'
width='400px'
ParentSubmit={(): void => {
props.onSubmit();
}}>
<Button
onClick={(): void => {
props.onSubmit();
}}
title={props.SubmitButtonTitle}
/>
{props.AlternativeButtonTitle ? (
<Button
color={{backgroundColor: 'darkorange'}}
onClick={(): void => {
props.onAlternativeButton ? props.onAlternativeButton() : null;
}}
title={props.AlternativeButtonTitle}
/>
) : (
<></>
)}
<Button
color={{backgroundColor: 'red'}}
onClick={(): void => {
props.onDeny();
}}
title={props.DenyButtonTitle}
/>
</PopupBase>
</>
);
};

View File

@ -1,37 +0,0 @@
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>
</>
);
};

View File

@ -90,16 +90,21 @@ describe('<Player/>', function () {
wrapper.setProps({history: {goBack: jest.fn()}}); wrapper.setProps({history: {goBack: jest.fn()}});
global.fetch = prepareFetchApi({result: 'success'}); // global.fetch = prepareFetchApi({result: 'success'});
callAPIMock({result: 'success'})
// request the popup to pop
wrapper.find('.videoactions').find('Button').at(2).simulate('click'); wrapper.find('.videoactions').find('Button').at(2).simulate('click');
// click the first submit button
wrapper.find('ButtonPopup').dive().find('Button').at(0).simulate('click')
process.nextTick(() => { process.nextTick(() => {
// refetch is called so fetch called 3 times // refetch is called so fetch called 3 times
expect(global.fetch).toHaveBeenCalledTimes(1); expect(callAPI).toHaveBeenCalledTimes(1);
expect(wrapper.instance().props.history.goBack).toHaveBeenCalledTimes(1); expect(wrapper.instance().props.history.goBack).toHaveBeenCalledTimes(1);
global.fetch.mockClear();
done(); done();
}); });
}); });
@ -152,16 +157,14 @@ describe('<Player/>', function () {
it('test click of quickadd tag btn', done => { it('test click of quickadd tag btn', done => {
const wrapper = generatetag(); const wrapper = generatetag();
global.fetch = prepareFetchApi({result: 'success'}); callAPIMock({result: 'success'})
// render tag subcomponent // render tag subcomponent
const tag = wrapper.find('Tag').first().dive(); const tag = wrapper.find('Tag').first().dive();
tag.simulate('click'); tag.simulate('click');
process.nextTick(() => { process.nextTick(() => {
expect(global.fetch).toHaveBeenCalledTimes(1); expect(callAPI).toHaveBeenCalledTimes(1);
global.fetch.mockClear();
done(); done();
}); });
}); });
@ -169,7 +172,7 @@ describe('<Player/>', function () {
it('test failing quickadd', done => { it('test failing quickadd', done => {
const wrapper = generatetag(); const wrapper = generatetag();
global.fetch = prepareFetchApi({result: 'nonsuccess'}); callAPIMock({result: 'nonsuccess'});
global.console.error = jest.fn(); global.console.error = jest.fn();
// render tag subcomponent // render tag subcomponent
@ -178,8 +181,6 @@ describe('<Player/>', function () {
process.nextTick(() => { process.nextTick(() => {
expect(global.console.error).toHaveBeenCalledTimes(2); expect(global.console.error).toHaveBeenCalledTimes(2);
global.fetch.mockClear();
done(); done();
}); });
}); });

View File

@ -21,7 +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'; import {ButtonPopup} from '../../elements/Popups/ButtonPopup/ButtonPopup';
interface Props extends RouteComponentProps<{id: string}> {} interface Props extends RouteComponentProps<{id: string}> {}
@ -199,21 +199,44 @@ export class Player extends React.Component<Props, mystate> {
movieId={this.state.movieId} movieId={this.state.movieId}
/> />
) : null} ) : null}
{this.state.deletepopupvisible ? ( {this.state.deletepopupvisible ? this.renderDeletePopup() : null}
<FullyDeletePopup </>
onDiscard={(): void => this.setState({deletepopupvisible: false})} );
}
renderDeletePopup(): JSX.Element {
if (GlobalInfos.isVideoFulldeleteable()) {
return (
<ButtonPopup
onDeny={(): void => this.setState({deletepopupvisible: false})}
onSubmit={(): void => { onSubmit={(): void => {
this.setState({deletepopupvisible: false}); this.setState({deletepopupvisible: false});
this.deleteVideo(true); this.deleteVideo(true);
}} }}
onDeny={(): void => { onAlternativeButton={(): void => {
this.setState({deletepopupvisible: false}); this.setState({deletepopupvisible: false});
this.deleteVideo(false); this.deleteVideo(false);
}} }}
DenyButtonTitle='Cancel'
SubmitButtonTitle='Fully Delete!'
Title='Fully Delete Video?'
AlternativeButtonTitle='Reference Only'
/> />
) : null}
</>
); );
} else {
return (
<ButtonPopup
onDeny={(): void => this.setState({deletepopupvisible: false})}
onSubmit={(): void => {
this.setState({deletepopupvisible: false});
this.deleteVideo(false);
}}
DenyButtonTitle='Cancel'
SubmitButtonTitle='Delete Video Reference!'
Title='Delete Video?'
/>
);
}
} }
/** /**

View File

@ -37,6 +37,7 @@ export namespace SettingsTypes {
VideoPath: string; VideoPath: string;
TVShowPath: string; TVShowPath: string;
TVShowEnabled: boolean; TVShowEnabled: boolean;
FullDeleteEnabled: boolean;
} }
export interface SettingsType { export interface SettingsType {

View File

@ -10,6 +10,7 @@ class StaticInfos {
private videopath: string = ''; private videopath: string = '';
private tvshowpath: string = ''; private tvshowpath: string = '';
private TVShowsEnabled: boolean = false; private TVShowsEnabled: boolean = false;
private fullDeleteable: boolean = false;
/** /**
* check if the current theme is the dark theme * check if the current theme is the dark theme
@ -80,6 +81,14 @@ class StaticInfos {
isTVShowEnabled(): boolean { isTVShowEnabled(): boolean {
return this.TVShowsEnabled; return this.TVShowsEnabled;
} }
setFullDeleteEnabled(FullDeleteEnabled: boolean): void {
this.fullDeleteable = FullDeleteEnabled;
}
isVideoFulldeleteable(): boolean {
return this.fullDeleteable;
}
} }
export default new StaticInfos(); export default new StaticInfos();