mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-05-20 20:50:17 +09:00
fixed typescript error
This commit is contained in:
parent
a1117cd4ee
commit
b3a324b6f5
@ -152,7 +152,7 @@ export function Sd() {
|
|||||||
db={fileDb}
|
db={fileDb}
|
||||||
src={item.img_data}
|
src={item.img_data}
|
||||||
alt={item.id}
|
alt={item.id}
|
||||||
onClick={(data, e) => {
|
onClick={(data: any, e: any) => {
|
||||||
showImageModal(
|
showImageModal(
|
||||||
data,
|
data,
|
||||||
true,
|
true,
|
||||||
@ -164,7 +164,6 @@ export function Sd() {
|
|||||||
: { width: "100%", height: "100%" },
|
: { width: "100%", height: "100%" },
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
isMobileScreen={isMobileScreen}
|
|
||||||
/>
|
/>
|
||||||
) : item.status === "error" ? (
|
) : item.status === "error" ? (
|
||||||
<div className={styles["pre-img"]}>
|
<div className={styles["pre-img"]}>
|
||||||
|
@ -3,7 +3,6 @@ import { Analytics } from "@vercel/analytics/react";
|
|||||||
import { Home } from "./components/home";
|
import { Home } from "./components/home";
|
||||||
|
|
||||||
import { getServerSideConfig } from "./config/server";
|
import { getServerSideConfig } from "./config/server";
|
||||||
import { SdDbInit } from "@/app/store/sd";
|
|
||||||
|
|
||||||
const serverConfig = getServerSideConfig();
|
const serverConfig = getServerSideConfig();
|
||||||
|
|
||||||
|
@ -42,13 +42,17 @@ export function base64Image2Blob(base64Data: string, contentType: string) {
|
|||||||
return new Blob([byteArray], { type: contentType });
|
return new Blob([byteArray], { type: contentType });
|
||||||
}
|
}
|
||||||
|
|
||||||
export function saveFileData(db, fileId, data) {
|
export function saveFileData(db: any, fileId: string, data: Blob | string) {
|
||||||
// save file content and return url start with `indexeddb://`
|
// save file content and return url start with `indexeddb://`
|
||||||
db.add({ id: fileId, data });
|
db.add({ id: fileId, data });
|
||||||
return `indexeddb://${StoreKey.File}@${fileId}`;
|
return `indexeddb://${StoreKey.File}@${fileId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileData(db, fileId, contentType = "image/png") {
|
export async function getFileData(
|
||||||
|
db: any,
|
||||||
|
fileId: string,
|
||||||
|
contentType = "image/png",
|
||||||
|
) {
|
||||||
const { data } = await db.getByID(fileId);
|
const { data } = await db.getByID(fileId);
|
||||||
if (typeof data == "object") {
|
if (typeof data == "object") {
|
||||||
return URL.createObjectURL(data);
|
return URL.createObjectURL(data);
|
||||||
@ -56,14 +60,26 @@ export async function getFileData(db, fileId, contentType = "image/png") {
|
|||||||
return `data:${contentType};base64,${data}`;
|
return `data:${contentType};base64,${data}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function IndexDBImage({ src, alt, onClick, db, className }) {
|
export function IndexDBImage({
|
||||||
|
src,
|
||||||
|
alt,
|
||||||
|
onClick,
|
||||||
|
db,
|
||||||
|
className,
|
||||||
|
}: {
|
||||||
|
src: string;
|
||||||
|
alt: string;
|
||||||
|
onClick: any;
|
||||||
|
db: any;
|
||||||
|
className: string;
|
||||||
|
}) {
|
||||||
const [data, setData] = useState(src);
|
const [data, setData] = useState(src);
|
||||||
const imgId = useMemo(
|
const imgId = useMemo(
|
||||||
() => src.replace("indexeddb://", "").split("@").pop(),
|
() => src.replace("indexeddb://", "").split("@").pop(),
|
||||||
[src],
|
[src],
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getFileData(db, imgId)
|
getFileData(db, imgId as string)
|
||||||
.then((data) => setData(data))
|
.then((data) => setData(data))
|
||||||
.catch((e) => setData(src));
|
.catch((e) => setData(src));
|
||||||
}, [src, imgId]);
|
}, [src, imgId]);
|
||||||
|
Loading…
Reference in New Issue
Block a user