fix(api): Use POST instead of GET for API endpoints that mutate state (#877)

This commit is contained in:
TheCatLady
2021-02-08 20:27:48 -05:00
committed by GitHub
parent d163e29459
commit ff0b5ed441
16 changed files with 101 additions and 73 deletions

View File

@@ -16,7 +16,7 @@ const UserDropdown: React.FC = () => {
useClickOutside(dropdownRef, () => setDropdownOpen(false));
const logout = async () => {
const response = await axios.get('/api/v1/auth/logout');
const response = await axios.post('/api/v1/auth/logout');
if (response.data?.status === 'ok') {
revalidate();
@@ -24,16 +24,16 @@ const UserDropdown: React.FC = () => {
};
return (
<div className="ml-3 relative">
<div className="relative ml-3">
<div>
<button
className="max-w-xs flex items-center text-sm rounded-full focus:outline-none focus:ring"
className="flex items-center max-w-xs text-sm rounded-full focus:outline-none focus:ring"
id="user-menu"
aria-label="User menu"
aria-haspopup="true"
onClick={() => setDropdownOpen(true)}
>
<img className="h-8 w-8 rounded-full" src={user?.avatar} alt="" />
<img className="w-8 h-8 rounded-full" src={user?.avatar} alt="" />
</button>
</div>
<Transition
@@ -46,18 +46,18 @@ const UserDropdown: React.FC = () => {
leaveTo="transform opacity-0 scale-95"
>
<div
className="origin-top-right absolute right-0 mt-2 w-48 rounded-md shadow-lg"
className="absolute right-0 w-48 mt-2 origin-top-right rounded-md shadow-lg"
ref={dropdownRef}
>
<div
className="py-1 rounded-md bg-gray-700 ring-1 ring-black ring-opacity-5"
className="py-1 bg-gray-700 rounded-md ring-1 ring-black ring-opacity-5"
role="menu"
aria-orientation="vertical"
aria-labelledby="user-menu"
>
<a
href="#"
className="block px-4 py-2 text-sm text-gray-200 hover:bg-gray-600 transition ease-in-out duration-150"
className="block px-4 py-2 text-sm text-gray-200 transition duration-150 ease-in-out hover:bg-gray-600"
role="menuitem"
onClick={() => logout()}
>

View File

@@ -123,10 +123,8 @@ const MovieDetails: React.FC<MovieDetailsProps> = ({ movie }) => {
};
const markAvailable = async (is4k = false) => {
await axios.get(`/api/v1/media/${data?.mediaInfo?.id}/available`, {
params: {
is4k,
},
await axios.post(`/api/v1/media/${data?.mediaInfo?.id}/available`, {
is4k,
});
revalidate();
};

View File

@@ -30,7 +30,7 @@ const RequestBlock: React.FC<RequestBlockProps> = ({ request, onUpdate }) => {
const updateRequest = async (type: 'approve' | 'decline'): Promise<void> => {
setIsUpdating(true);
await axios.get(`/api/v1/request/${request.id}/${type}`);
await axios.post(`/api/v1/request/${request.id}/${type}`);
if (onUpdate) {
onUpdate();

View File

@@ -83,7 +83,7 @@ const RequestButton: React.FC<RequestButtonProps> = ({
request: MediaRequest,
type: 'approve' | 'decline'
) => {
const response = await axios.get(`/api/v1/request/${request.id}/${type}`);
const response = await axios.post(`/api/v1/request/${request.id}/${type}`);
if (response) {
onUpdate();
@@ -100,7 +100,7 @@ const RequestButton: React.FC<RequestButtonProps> = ({
await Promise.all(
requests.map(async (request) => {
return axios.get(`/api/v1/request/${request.id}/${type}`);
return axios.post(`/api/v1/request/${request.id}/${type}`);
})
);

View File

@@ -62,7 +62,7 @@ const RequestCard: React.FC<RequestCardProps> = ({ request }) => {
});
const modifyRequest = async (type: 'approve' | 'decline') => {
const response = await axios.get(`/api/v1/request/${request.id}/${type}`);
const response = await axios.post(`/api/v1/request/${request.id}/${type}`);
if (response) {
revalidate();

View File

@@ -70,7 +70,7 @@ const RequestItem: React.FC<RequestItemProps> = ({
const [isRetrying, setRetrying] = useState(false);
const modifyRequest = async (type: 'approve' | 'decline') => {
const response = await axios.get(`/api/v1/request/${request.id}/${type}`);
const response = await axios.post(`/api/v1/request/${request.id}/${type}`);
if (response) {
revalidate();

View File

@@ -63,7 +63,7 @@ const SettingsJobs: React.FC = () => {
}
const runJob = async (job: Job) => {
await axios.get(`/api/v1/settings/jobs/${job.id}/run`);
await axios.post(`/api/v1/settings/jobs/${job.id}/run`);
addToast(
intl.formatMessage(messages.jobstarted, {
jobname: job.name,
@@ -77,7 +77,7 @@ const SettingsJobs: React.FC = () => {
};
const cancelJob = async (job: Job) => {
await axios.get(`/api/v1/settings/jobs/${job.id}/cancel`);
await axios.post(`/api/v1/settings/jobs/${job.id}/cancel`);
addToast(intl.formatMessage(messages.jobcancelled, { jobname: job.name }), {
appearance: 'error',
autoDismiss: true,
@@ -86,7 +86,7 @@ const SettingsJobs: React.FC = () => {
};
const flushCache = async (cache: CacheItem) => {
await axios.get(`/api/v1/settings/cache/${cache.id}/flush`);
await axios.post(`/api/v1/settings/cache/${cache.id}/flush`);
addToast(
intl.formatMessage(messages.cacheflushed, { cachename: cache.name }),
{

View File

@@ -70,7 +70,7 @@ const SettingsMain: React.FC = () => {
const regenerate = async () => {
try {
await axios.get('/api/v1/settings/main/regenerate');
await axios.post('/api/v1/settings/main/regenerate');
revalidate();
addToast(intl.formatMessage(messages.toastApiKeySuccess), {

View File

@@ -212,19 +212,15 @@ const SettingsPlex: React.FC<SettingsPlexProps> = ({ onComplete }) => {
};
const startScan = async () => {
await axios.get('/api/v1/settings/plex/sync', {
params: {
start: true,
},
await axios.post('/api/v1/settings/plex/sync', {
start: true,
});
revalidateSync();
};
const cancelScan = async () => {
await axios.get('/api/v1/settings/plex/sync', {
params: {
cancel: true,
},
await axios.post('/api/v1/settings/plex/sync', {
cancel: true,
});
revalidateSync();
};

View File

@@ -35,7 +35,7 @@ const Setup: React.FC = () => {
const finishSetup = async () => {
setIsUpdating(false);
const response = await axios.get<{ initialized: boolean }>(
const response = await axios.post<{ initialized: boolean }>(
'/api/v1/settings/initialize'
);

View File

@@ -127,10 +127,8 @@ const TvDetails: React.FC<TvDetailsProps> = ({ tv }) => {
};
const markAvailable = async (is4k = false) => {
await axios.get(`/api/v1/media/${data?.mediaInfo?.id}/available`, {
params: {
is4k,
},
await axios.post(`/api/v1/media/${data?.mediaInfo?.id}/available`, {
is4k,
});
revalidate();
};