2021-03-31 09:38:22 +02:00
|
|
|
// @flow
|
|
|
|
import * as ACTIONS from 'constants/action_types';
|
|
|
|
import { COPYRIGHT_ISSUES, OTHER_LEGAL_ISSUES } from 'constants/report_content';
|
|
|
|
|
|
|
|
type Dispatch = (action: any) => any;
|
|
|
|
|
|
|
|
export const doReportContent = (category: string, params: string) => (dispatch: Dispatch) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.REPORT_CONTENT_STARTED,
|
|
|
|
});
|
|
|
|
|
|
|
|
let REPORT_URL;
|
|
|
|
switch (category) {
|
|
|
|
case COPYRIGHT_ISSUES:
|
2022-02-09 21:06:38 +01:00
|
|
|
REPORT_URL = 'https://reports.odysee.tv/copyright_issue/new';
|
2021-03-31 09:38:22 +02:00
|
|
|
break;
|
|
|
|
case OTHER_LEGAL_ISSUES:
|
2022-02-09 21:06:38 +01:00
|
|
|
REPORT_URL = 'https://reports.odysee.tv/other_legal_issue/new';
|
2021-03-31 09:38:22 +02:00
|
|
|
break;
|
|
|
|
default:
|
2022-02-09 21:06:38 +01:00
|
|
|
REPORT_URL = 'https://reports.odysee.tv/common/new';
|
2021-03-31 09:38:22 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
fetch(`${REPORT_URL}?${params}`, { method: 'POST' })
|
|
|
|
.then((response) => {
|
|
|
|
if (response) {
|
|
|
|
response
|
|
|
|
.json()
|
|
|
|
.then((json) => {
|
|
|
|
if (json.success) {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.REPORT_CONTENT_COMPLETED,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.REPORT_CONTENT_FAILED,
|
|
|
|
data: json.error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.REPORT_CONTENT_FAILED,
|
|
|
|
data: 'Server error: Invalid response',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.REPORT_CONTENT_FAILED,
|
|
|
|
data: 'Server error: No response',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
dispatch({
|
|
|
|
type: ACTIONS.REPORT_CONTENT_FAILED,
|
|
|
|
data: err,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|