Add: migration to new backend

This commit is contained in:
Jose
2026-02-24 03:39:49 +01:00
parent 589215b2bc
commit 4d0c4d3f26
13 changed files with 4686 additions and 222 deletions

View File

@@ -2,13 +2,6 @@ import Editor from "@monaco-editor/react";
import { useTheme } from "@/hooks/useTheme";
import { useRef } from "react";
import PropTypes from "prop-types";
import { loader } from '@monaco-editor/react';
loader.config({
'vs/nls': {
availableLanguages: { '*': 'es' },
},
});
const CodeEditor = ({ className = "", syntax, readOnly, onChange, value }) => {
const { theme } = useTheme();

View File

@@ -11,7 +11,7 @@ import { useDataContext } from "@/hooks/useDataContext";
import PasswordModal from "@/components/Auth/PasswordModal.jsx";
const PastePanel = ({ onSubmit, publicPastes }) => {
const { paste_key } = useParams();
const { pasteKey } = useParams();
const navigate = useNavigate();
const { getData } = useDataContext();
const [title, setTitle] = useState("");
@@ -30,8 +30,8 @@ const PastePanel = ({ onSubmit, publicPastes }) => {
title,
content,
syntax,
burn_after: burnAfter,
is_private: isPrivate,
burnAfter: burnAfter,
isPrivate: isPrivate,
password: password || null,
};
if (onSubmit) onSubmit(paste);
@@ -42,8 +42,11 @@ const PastePanel = ({ onSubmit, publicPastes }) => {
};
const fetchPaste = async (key, pwd = "") => {
const url = `https://api.miarma.net/mpaste/v1/pastes/${key}`;
const { data, error } = await getData(url, {}, {
const url = import.meta.env.MODE === 'production' ?
`https://api.miarma.net/v2/mpaste/pastes/${key}` :
`http://localhost:8081/v2/mpaste/pastes/${key}`;
const { data, error } = await getData(url, {}, false, {
'X-Paste-Password': pwd
});
@@ -66,8 +69,8 @@ const PastePanel = ({ onSubmit, publicPastes }) => {
};
useEffect(() => {
if (paste_key) fetchPaste(paste_key);
}, [paste_key]);
if (pasteKey) fetchPaste(pasteKey);
}, [pasteKey]);
return (
<>
@@ -93,7 +96,7 @@ const PastePanel = ({ onSubmit, publicPastes }) => {
{publicPastes && publicPastes.length > 0 ? (
publicPastes.map((paste) => (
<PublicPasteItem
key={paste.paste_key}
key={paste.pasteKey}
paste={paste}
onSelect={handleSelectPaste}
/>
@@ -224,7 +227,7 @@ const PastePanel = ({ onSubmit, publicPastes }) => {
onClose={() => setShowPasswordModal(false)}
onSubmit={(pwd) => {
setShowPasswordModal(false);
fetchPaste(paste_key, pwd); // reintentas con la pass
fetchPaste(pasteKey, pwd); // reintentas con la pass
}}
/>
</>

View File

@@ -8,11 +8,11 @@ const trimContent = (text, maxLength = 80) => {
const PublicPasteItem = ({ paste, onSelect }) => {
return (
<div className="public-paste-item p-2 mb-2 rounded custom-border" style={{ cursor: "pointer" }} onClick={() => onSelect(paste.paste_key)}>
<div className="public-paste-item p-2 mb-2 rounded custom-border" style={{ cursor: "pointer" }} onClick={() => onSelect(paste.pasteKey)}>
<h5 className="m-0">{paste.title}</h5>
<p className="m-0 text-truncate">{trimContent(paste.content, 100)}</p>
<small className="custom-text-muted">
{new Date(paste.created_at).toLocaleString()}
{new Date(paste.createdAt).toLocaleString()}
</small>
</div>
);
@@ -22,7 +22,7 @@ PublicPasteItem.propTypes = {
paste: PropTypes.shape({
title: PropTypes.string.isRequired,
content: PropTypes.string.isRequired,
created_at: PropTypes.string.isRequired,
createdAt: PropTypes.string.isRequired,
}).isRequired,
};