diff --git a/apiGo/api/Settings.go b/apiGo/api/Settings.go
index 711d4de..b3a6a63 100644
--- a/apiGo/api/Settings.go
+++ b/apiGo/api/Settings.go
@@ -67,12 +67,13 @@ func getSettingsFromDB() {
sett := settings.LoadSettings()
type InitialDataTypeResponse struct {
- DarkMode bool
- Pasword bool
- MediacenterName string
- VideoPath string
- TVShowPath string
- TVShowEnabled bool
+ DarkMode bool
+ Pasword bool
+ MediacenterName string
+ VideoPath string
+ TVShowPath string
+ 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}")
@@ -82,12 +83,13 @@ func getSettingsFromDB() {
serverTVShowPath := strings.TrimPrefix(sett.TVShowPath, tvshowurl)
res := InitialDataTypeResponse{
- DarkMode: sett.DarkMode,
- Pasword: sett.Pasword != "-1",
- MediacenterName: sett.MediacenterName,
- VideoPath: serverVideoPath,
- TVShowPath: serverTVShowPath,
- TVShowEnabled: settings.TVShowsEnabled(),
+ DarkMode: sett.DarkMode,
+ Pasword: sett.Pasword != "-1",
+ MediacenterName: sett.MediacenterName,
+ VideoPath: serverVideoPath,
+ TVShowPath: serverTVShowPath,
+ TVShowEnabled: settings.TVShowsEnabled(),
+ FullDeleteEnabled: settings.VideosDeletable(),
}
str, _ := json.Marshal(res)
diff --git a/apiGo/api/Video.go b/apiGo/api/Video.go
index 92b5963..b060c19 100644
--- a/apiGo/api/Video.go
+++ b/apiGo/api/Video.go
@@ -420,6 +420,7 @@ func addToVideoHandlers() {
* @apiGroup 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
*/
@@ -446,6 +447,7 @@ func addToVideoHandlers() {
return database.ManualSuccessResponse(err)
}
+ // only allow deletion of video if cli flag is set, independent of passed api arg
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)
@@ -457,7 +459,8 @@ func addToVideoHandlers() {
err = os.Remove(vidpath)
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)
}
}
diff --git a/src/App.tsx b/src/App.tsx
index db339d0..d78d444 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -87,6 +87,7 @@ class App extends React.Component<{}, state> {
GlobalInfos.setVideoPaths(result.VideoPath, result.TVShowPath);
GlobalInfos.setTVShowsEnabled(result.TVShowEnabled);
+ GlobalInfos.setFullDeleteEnabled(result.FullDeleteEnabled);
this.setState({
mediacentername: result.MediacenterName
diff --git a/src/elements/Popups/ButtonPopup/ButtonPopup.tsx b/src/elements/Popups/ButtonPopup/ButtonPopup.tsx
new file mode 100644
index 0000000..3b5b667
--- /dev/null
+++ b/src/elements/Popups/ButtonPopup/ButtonPopup.tsx
@@ -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 (
+ <>
+ props.onDeny()}
+ height='200px'
+ width='400px'
+ ParentSubmit={(): void => {
+ props.onSubmit();
+ }}>
+
+ >
+ );
+};
diff --git a/src/elements/Popups/FullyDeletePopup/FullyDeletePopup.tsx b/src/elements/Popups/FullyDeletePopup/FullyDeletePopup.tsx
deleted file mode 100644
index 6c95295..0000000
--- a/src/elements/Popups/FullyDeletePopup/FullyDeletePopup.tsx
+++ /dev/null
@@ -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 (
- <>
- props.onDiscard()}
- height='200px'
- width='350px'
- ParentSubmit={(): void => {
- props.onSubmit();
- }}>
- {
- props.onSubmit();
- }}
- title='Fully Delete!'
- />
- {
- props.onDeny();
- }}
- title='Only DB Entries'
- />
-
- >
- );
-};
diff --git a/src/pages/Player/Player.test.js b/src/pages/Player/Player.test.js
index aed56cd..254ef73 100644
--- a/src/pages/Player/Player.test.js
+++ b/src/pages/Player/Player.test.js
@@ -90,16 +90,21 @@ describe('', function () {
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');
+ // click the first submit button
+ wrapper.find('ButtonPopup').dive().find('Button').at(0).simulate('click')
+
process.nextTick(() => {
// 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);
- global.fetch.mockClear();
done();
});
});
@@ -152,16 +157,14 @@ describe('', function () {
it('test click of quickadd tag btn', done => {
const wrapper = generatetag();
- global.fetch = prepareFetchApi({result: 'success'});
+ callAPIMock({result: 'success'})
// render tag subcomponent
const tag = wrapper.find('Tag').first().dive();
tag.simulate('click');
process.nextTick(() => {
- expect(global.fetch).toHaveBeenCalledTimes(1);
-
- global.fetch.mockClear();
+ expect(callAPI).toHaveBeenCalledTimes(1);
done();
});
});
@@ -169,7 +172,7 @@ describe('', function () {
it('test failing quickadd', done => {
const wrapper = generatetag();
- global.fetch = prepareFetchApi({result: 'nonsuccess'});
+ callAPIMock({result: 'nonsuccess'});
global.console.error = jest.fn();
// render tag subcomponent
@@ -178,8 +181,6 @@ describe('', function () {
process.nextTick(() => {
expect(global.console.error).toHaveBeenCalledTimes(2);
-
- global.fetch.mockClear();
done();
});
});
diff --git a/src/pages/Player/Player.tsx b/src/pages/Player/Player.tsx
index 9b9830e..99ae64e 100644
--- a/src/pages/Player/Player.tsx
+++ b/src/pages/Player/Player.tsx
@@ -21,7 +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';
+import {ButtonPopup} from '../../elements/Popups/ButtonPopup/ButtonPopup';
interface Props extends RouteComponentProps<{id: string}> {}
@@ -199,23 +199,46 @@ export class Player extends React.Component {
movieId={this.state.movieId}
/>
) : null}
- {this.state.deletepopupvisible ? (
- this.setState({deletepopupvisible: false})}
- onSubmit={(): void => {
- this.setState({deletepopupvisible: false});
- this.deleteVideo(true);
- }}
- onDeny={(): void => {
- this.setState({deletepopupvisible: false});
- this.deleteVideo(false);
- }}
- />
- ) : null}
+ {this.state.deletepopupvisible ? this.renderDeletePopup() : null}
>
);
}
+ renderDeletePopup(): JSX.Element {
+ if (GlobalInfos.isVideoFulldeleteable()) {
+ return (
+ this.setState({deletepopupvisible: false})}
+ onSubmit={(): void => {
+ this.setState({deletepopupvisible: false});
+ this.deleteVideo(true);
+ }}
+ onAlternativeButton={(): void => {
+ this.setState({deletepopupvisible: false});
+ this.deleteVideo(false);
+ }}
+ DenyButtonTitle='Cancel'
+ SubmitButtonTitle='Fully Delete!'
+ Title='Fully Delete Video?'
+ AlternativeButtonTitle='Reference Only'
+ />
+ );
+ } else {
+ return (
+ this.setState({deletepopupvisible: false})}
+ onSubmit={(): void => {
+ this.setState({deletepopupvisible: false});
+ this.deleteVideo(false);
+ }}
+ DenyButtonTitle='Cancel'
+ SubmitButtonTitle='Delete Video Reference!'
+ Title='Delete Video?'
+ />
+ );
+ }
+ }
+
/**
* quick add callback to add tag to db and change gui correctly
* @param tagId id of tag to add
diff --git a/src/types/ApiTypes.ts b/src/types/ApiTypes.ts
index 69b804a..3f5a26f 100644
--- a/src/types/ApiTypes.ts
+++ b/src/types/ApiTypes.ts
@@ -37,6 +37,7 @@ export namespace SettingsTypes {
VideoPath: string;
TVShowPath: string;
TVShowEnabled: boolean;
+ FullDeleteEnabled: boolean;
}
export interface SettingsType {
diff --git a/src/utils/GlobalInfos.ts b/src/utils/GlobalInfos.ts
index c3a588b..170a479 100644
--- a/src/utils/GlobalInfos.ts
+++ b/src/utils/GlobalInfos.ts
@@ -10,6 +10,7 @@ class StaticInfos {
private videopath: string = '';
private tvshowpath: string = '';
private TVShowsEnabled: boolean = false;
+ private fullDeleteable: boolean = false;
/**
* check if the current theme is the dark theme
@@ -80,6 +81,14 @@ class StaticInfos {
isTVShowEnabled(): boolean {
return this.TVShowsEnabled;
}
+
+ setFullDeleteEnabled(FullDeleteEnabled: boolean): void {
+ this.fullDeleteable = FullDeleteEnabled;
+ }
+
+ isVideoFulldeleteable(): boolean {
+ return this.fullDeleteable;
+ }
}
export default new StaticInfos();