Skip to content

Commit

Permalink
fix sessionStorage limit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsPi3141 committed Dec 8, 2024
1 parent eba9c47 commit bdfee30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
5 changes: 3 additions & 2 deletions app/gif-extractor/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Image from "../components/image.jsx";

import { printMsg } from "../print.js";
import { Icons } from "../components/icons.jsx";
import { clearData, getData } from "../utils/dataHandler.js";

export default function GifExtractor() {
const isServer = typeof window === "undefined";
Expand Down Expand Up @@ -47,9 +48,9 @@ export default function GifExtractor() {
setLoaded(true);

if (!isServer) {
const i = sessionStorage.getItem("image");
const i = getData("image");
if (i) setFile(i);
sessionStorage.removeItem("image");
clearData("image");
}
});

Expand Down
3 changes: 2 additions & 1 deletion app/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "react-tooltip/dist/react-tooltip.css";
import { Tooltip } from "react-tooltip";
import { Icons } from "./components/icons.jsx";
import { LoadingCircle, LoadingCubes } from "./components/spinner.jsx";
import { storeData } from "./utils/dataHandler.js";

const decorationsData = require("../decorations.json");
const avatarsData = require("../avatars.json");
Expand Down Expand Up @@ -766,7 +767,7 @@ const App = ({ ffmpegRef, isServer }) => {
onClick={() => {
if (!isServer) {
try {
sessionStorage.setItem("image", finishedAv);
storeData("image", finishedAv);
router.push("/gif-extractor");
} catch {
setFileTooBig(true);
Expand Down
9 changes: 9 additions & 0 deletions app/utils/dataHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const tempStorage = {};

export const storeData = (key, data) => {
tempStorage[key] = data;
};
export const clearData = (key) => {
delete tempStorage[key];
};
export const getData = (key) => tempStorage[key];

0 comments on commit bdfee30

Please sign in to comment.