mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-21 23:15:05 +00:00
30 lines
768 B
JavaScript
30 lines
768 B
JavaScript
![]() |
import { useState } from 'react';
|
||
|
import axios from 'axios';
|
||
|
|
||
|
export const useDecryptContent = () => {
|
||
|
const [isLoading, setIsLoading] = useState(false);
|
||
|
const [error, setError] = useState(null);
|
||
|
|
||
|
const decryptContent = async (encryptedContent) => {
|
||
|
setIsLoading(true);
|
||
|
setError(null);
|
||
|
|
||
|
try {
|
||
|
const response = await axios.post('/api/decrypt', { encryptedContent });
|
||
|
|
||
|
if (response.status !== 200) {
|
||
|
throw new Error('Failed to decrypt content');
|
||
|
}
|
||
|
|
||
|
const decryptedContent = response.data.decryptedContent;
|
||
|
setIsLoading(false);
|
||
|
return decryptedContent;
|
||
|
} catch (err) {
|
||
|
setError(err.message);
|
||
|
setIsLoading(false);
|
||
|
return null;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return { decryptContent, isLoading, error };
|
||
|
};
|