Bläddra i källkod

清理了没用的 Stable Diffusion 模块

Ryuiso 7 månader sedan
förälder
incheckning
e6bfae35e5

+ 2 - 13
app/components/home.tsx

@@ -159,15 +159,6 @@ const MaskPage = dynamic(
   }
 );
 
-const Sd = dynamic(
-  async () => {
-    await delayer();
-    return (await import("./sd")).Sd
-  },
-  {
-    loading: () => <Loading />,
-  }
-);
 
 export function useSwitchTheme() {
   const config = useAppConfig();
@@ -249,8 +240,7 @@ function Screen() {
   const location = useLocation();
   const isArtifact = location.pathname.includes(Path.Artifacts);
   const isAuth = location.pathname === Path.Auth;
-  const isSd = location.pathname === Path.Sd;
-  const isSdNew = location.pathname === Path.SdNew;
+
 
   const isMobileScreen = useMobileScreen();
   const shouldTightBorder =
@@ -270,8 +260,7 @@ function Screen() {
 
   const renderContent = () => {
     if (isAuth) return <AuthPage />;
-    if (isSd) return <Sd />;
-    if (isSdNew) return <Sd />;
+
 
     return (
       <>

+ 0 - 2
app/components/sd/index.tsx

@@ -1,2 +0,0 @@
-export * from "./sd";
-export * from "./sd-panel";

+ 0 - 45
app/components/sd/sd-panel.module.scss

@@ -1,45 +0,0 @@
-.ctrl-param-item {
-  display: flex;
-  justify-content: space-between;
-  min-height: 40px;
-  padding: 10px 0;
-  animation: slide-in ease 0.6s;
-  flex-direction: column;
-
-  .ctrl-param-item-header {
-    display: flex;
-    align-items: center;
-
-    .ctrl-param-item-title {
-      font-size: 14px;
-      font-weight: bolder;
-      margin-bottom: 5px;
-    }
-  }
-
-  .ctrl-param-item-sub-title {
-    font-size: 12px;
-    font-weight: normal;
-    margin-top: 3px;
-  }
-  textarea {
-    appearance: none;
-    border-radius: 10px;
-    border: var(--border-in-light);
-    min-height: 36px;
-    box-sizing: border-box;
-    background: var(--white);
-    color: var(--black);
-    padding: 0 10px;
-    max-width: 50%;
-    font-family: inherit;
-  }
-}
-
-.ai-models {
-  button {
-    margin-bottom: 10px;
-    padding: 10px;
-    width: 100%;
-  }
-}

+ 0 - 320
app/components/sd/sd-panel.tsx

@@ -1,320 +0,0 @@
-import styles from "./sd-panel.module.scss";
-import React from "react";
-import { Select } from "@/app/components/ui-lib";
-import { IconButton } from "@/app/components/button";
-import Locale from "@/app/locales";
-import { useSdStore } from "@/app/store/sd";
-
-export const params = [
-  {
-    name: Locale.SdPanel.Prompt,
-    value: "prompt",
-    type: "textarea",
-    placeholder: Locale.SdPanel.PleaseInput(Locale.SdPanel.Prompt),
-    required: true,
-  },
-  {
-    name: Locale.SdPanel.ModelVersion,
-    value: "model",
-    type: "select",
-    default: "sd3-medium",
-    support: ["sd3"],
-    options: [
-      { name: "SD3 Medium", value: "sd3-medium" },
-      { name: "SD3 Large", value: "sd3-large" },
-      { name: "SD3 Large Turbo", value: "sd3-large-turbo" },
-    ],
-  },
-  {
-    name: Locale.SdPanel.NegativePrompt,
-    value: "negative_prompt",
-    type: "textarea",
-    placeholder: Locale.SdPanel.PleaseInput(Locale.SdPanel.NegativePrompt),
-  },
-  {
-    name: Locale.SdPanel.AspectRatio,
-    value: "aspect_ratio",
-    type: "select",
-    default: "1:1",
-    options: [
-      { name: "1:1", value: "1:1" },
-      { name: "16:9", value: "16:9" },
-      { name: "21:9", value: "21:9" },
-      { name: "2:3", value: "2:3" },
-      { name: "3:2", value: "3:2" },
-      { name: "4:5", value: "4:5" },
-      { name: "5:4", value: "5:4" },
-      { name: "9:16", value: "9:16" },
-      { name: "9:21", value: "9:21" },
-    ],
-  },
-  {
-    name: Locale.SdPanel.ImageStyle,
-    value: "style",
-    type: "select",
-    default: "3d-model",
-    support: ["core"],
-    options: [
-      { name: Locale.SdPanel.Styles.D3Model, value: "3d-model" },
-      { name: Locale.SdPanel.Styles.AnalogFilm, value: "analog-film" },
-      { name: Locale.SdPanel.Styles.Anime, value: "anime" },
-      { name: Locale.SdPanel.Styles.Cinematic, value: "cinematic" },
-      { name: Locale.SdPanel.Styles.ComicBook, value: "comic-book" },
-      { name: Locale.SdPanel.Styles.DigitalArt, value: "digital-art" },
-      { name: Locale.SdPanel.Styles.Enhance, value: "enhance" },
-      { name: Locale.SdPanel.Styles.FantasyArt, value: "fantasy-art" },
-      { name: Locale.SdPanel.Styles.Isometric, value: "isometric" },
-      { name: Locale.SdPanel.Styles.LineArt, value: "line-art" },
-      { name: Locale.SdPanel.Styles.LowPoly, value: "low-poly" },
-      {
-        name: Locale.SdPanel.Styles.ModelingCompound,
-        value: "modeling-compound",
-      },
-      { name: Locale.SdPanel.Styles.NeonPunk, value: "neon-punk" },
-      { name: Locale.SdPanel.Styles.Origami, value: "origami" },
-      { name: Locale.SdPanel.Styles.Photographic, value: "photographic" },
-      { name: Locale.SdPanel.Styles.PixelArt, value: "pixel-art" },
-      { name: Locale.SdPanel.Styles.TileTexture, value: "tile-texture" },
-    ],
-  },
-  {
-    name: "Seed",
-    value: "seed",
-    type: "number",
-    default: 0,
-    min: 0,
-    max: 4294967294,
-  },
-  {
-    name: Locale.SdPanel.OutFormat,
-    value: "output_format",
-    type: "select",
-    default: "png",
-    options: [
-      { name: "PNG", value: "png" },
-      { name: "JPEG", value: "jpeg" },
-      { name: "WebP", value: "webp" },
-    ],
-  },
-];
-
-const sdCommonParams = (model: string, data: any) => {
-  return params.filter((item) => {
-    return !(item.support && !item.support.includes(model));
-  });
-};
-
-export const models = [
-  {
-    name: "Stable Image Ultra",
-    value: "ultra",
-    params: (data: any) => sdCommonParams("ultra", data),
-  },
-  {
-    name: "Stable Image Core",
-    value: "core",
-    params: (data: any) => sdCommonParams("core", data),
-  },
-  {
-    name: "Stable Diffusion 3",
-    value: "sd3",
-    params: (data: any) => {
-      return sdCommonParams("sd3", data).filter((item) => {
-        return !(
-          data.model === "sd3-large-turbo" && item.value == "negative_prompt"
-        );
-      });
-    },
-  },
-];
-
-export function ControlParamItem(props: {
-  title: string;
-  subTitle?: string;
-  required?: boolean;
-  children?: JSX.Element | JSX.Element[];
-  className?: string;
-}) {
-  return (
-    <div className={styles["ctrl-param-item"] + ` ${props.className || ""}`}>
-      <div className={styles["ctrl-param-item-header"]}>
-        <div className={styles["ctrl-param-item-title"]}>
-          <div>
-            {props.title}
-            {props.required && <span style={{ color: "red" }}>*</span>}
-          </div>
-        </div>
-      </div>
-      {props.children}
-      {props.subTitle && (
-        <div className={styles["ctrl-param-item-sub-title"]}>
-          {props.subTitle}
-        </div>
-      )}
-    </div>
-  );
-}
-
-export function ControlParam(props: {
-  columns: any[];
-  data: any;
-  onChange: (field: string, val: any) => void;
-}) {
-  return (
-    <>
-      {props.columns?.map((item) => {
-        let element: null | JSX.Element;
-        switch (item.type) {
-          case "textarea":
-            element = (
-              <ControlParamItem
-                title={item.name}
-                subTitle={item.sub}
-                required={item.required}
-              >
-                <textarea
-                  rows={item.rows || 3}
-                  style={{ maxWidth: "100%", width: "100%", padding: "10px" }}
-                  placeholder={item.placeholder}
-                  onChange={(e) => {
-                    props.onChange(item.value, e.currentTarget.value);
-                  }}
-                  value={props.data[item.value]}
-                ></textarea>
-              </ControlParamItem>
-            );
-            break;
-          case "select":
-            element = (
-              <ControlParamItem
-                title={item.name}
-                subTitle={item.sub}
-                required={item.required}
-              >
-                <Select
-                  aria-label={item.name}
-                  value={props.data[item.value]}
-                  onChange={(e) => {
-                    props.onChange(item.value, e.currentTarget.value);
-                  }}
-                >
-                  {item.options.map((opt: any) => {
-                    return (
-                      <option value={opt.value} key={opt.value}>
-                        {opt.name}
-                      </option>
-                    );
-                  })}
-                </Select>
-              </ControlParamItem>
-            );
-            break;
-          case "number":
-            element = (
-              <ControlParamItem
-                title={item.name}
-                subTitle={item.sub}
-                required={item.required}
-              >
-                <input
-                  aria-label={item.name}
-                  type="number"
-                  min={item.min}
-                  max={item.max}
-                  value={props.data[item.value] || 0}
-                  onChange={(e) => {
-                    props.onChange(item.value, parseInt(e.currentTarget.value));
-                  }}
-                />
-              </ControlParamItem>
-            );
-            break;
-          default:
-            element = (
-              <ControlParamItem
-                title={item.name}
-                subTitle={item.sub}
-                required={item.required}
-              >
-                <input
-                  aria-label={item.name}
-                  type="text"
-                  value={props.data[item.value]}
-                  style={{ maxWidth: "100%", width: "100%" }}
-                  onChange={(e) => {
-                    props.onChange(item.value, e.currentTarget.value);
-                  }}
-                />
-              </ControlParamItem>
-            );
-        }
-        return <div key={item.value}>{element}</div>;
-      })}
-    </>
-  );
-}
-
-export const getModelParamBasicData = (
-  columns: any[],
-  data: any,
-  clearText?: boolean,
-) => {
-  const newParams: any = {};
-  columns.forEach((item: any) => {
-    if (clearText && ["text", "textarea", "number"].includes(item.type)) {
-      newParams[item.value] = item.default || "";
-    } else {
-      // @ts-ignore
-      newParams[item.value] = data[item.value] || item.default || "";
-    }
-  });
-  return newParams;
-};
-
-export const getParams = (model: any, params: any) => {
-  return models.find((m) => m.value === model.value)?.params(params) || [];
-};
-
-export function SdPanel() {
-  const sdStore = useSdStore();
-  const currentModel = sdStore.currentModel;
-  const setCurrentModel = sdStore.setCurrentModel;
-  const params = sdStore.currentParams;
-  const setParams = sdStore.setCurrentParams;
-
-  const handleValueChange = (field: string, val: any) => {
-    setParams({
-      ...params,
-      [field]: val,
-    });
-  };
-  const handleModelChange = (model: any) => {
-    setCurrentModel(model);
-    setParams(getModelParamBasicData(model.params({}), params));
-  };
-
-  return (
-    <>
-      <ControlParamItem title={Locale.SdPanel.AIModel}>
-        <div className={styles["ai-models"]}>
-          {models.map((item) => {
-            return (
-              <IconButton
-                text={item.name}
-                key={item.value}
-                type={currentModel.value == item.value ? "primary" : null}
-                shadow
-                onClick={() => handleModelChange(item)}
-              />
-            );
-          })}
-        </div>
-      </ControlParamItem>
-      <ControlParam
-        columns={getParams?.(currentModel, params) as any[]}
-        data={params}
-        onChange={handleValueChange}
-      ></ControlParam>
-    </>
-  );
-}

+ 0 - 140
app/components/sd/sd-sidebar.tsx

@@ -1,140 +0,0 @@
-import { IconButton } from "@/app/components/button";
-import GithubIcon from "@/app/icons/github.svg";
-import SDIcon from "@/app/icons/sd.svg";
-import ReturnIcon from "@/app/icons/return.svg";
-import HistoryIcon from "@/app/icons/history.svg";
-import Locale from "@/app/locales";
-
-import { Path, REPO_URL } from "@/app/constant";
-
-import { useNavigate } from "react-router-dom";
-import dynamic from "next/dynamic";
-import {
-  SideBarContainer,
-  SideBarBody,
-  SideBarHeader,
-  SideBarTail,
-  useDragSideBar,
-  useHotKey,
-} from "@/app/components/sidebar";
-
-import { getParams, getModelParamBasicData } from "./sd-panel";
-import { useSdStore } from "@/app/store/sd";
-import { showToast } from "@/app/components/ui-lib";
-import { useMobileScreen } from "@/app/utils";
-
-const SdPanel = dynamic(
-  async () => (await import("@/app/components/sd")).SdPanel,
-  {
-    loading: () => null,
-  },
-);
-
-export function SideBar(props: { className?: string }) {
-  useHotKey();
-  const isMobileScreen = useMobileScreen();
-  const { onDragStart, shouldNarrow } = useDragSideBar();
-  const navigate = useNavigate();
-  const sdStore = useSdStore();
-  const currentModel = sdStore.currentModel;
-  const params = sdStore.currentParams;
-  const setParams = sdStore.setCurrentParams;
-
-  const handleSubmit = () => {
-    const columns = getParams?.(currentModel, params);
-    const reqParams: any = {};
-    for (let i = 0; i < columns.length; i++) {
-      const item = columns[i];
-      reqParams[item.value] = params[item.value] ?? null;
-      if (item.required) {
-        if (!reqParams[item.value]) {
-          showToast(Locale.SdPanel.ParamIsRequired(item.name));
-          return;
-        }
-      }
-    }
-    let data: any = {
-      model: currentModel.value,
-      model_name: currentModel.name,
-      status: "wait",
-      params: reqParams,
-      created_at: new Date().toLocaleString(),
-      img_data: "",
-    };
-    sdStore.sendTask(data, () => {
-      setParams(getModelParamBasicData(columns, params, true));
-      navigate(Path.SdNew);
-    });
-  };
-
-  return (
-    <SideBarContainer
-      onDragStart={onDragStart}
-      shouldNarrow={shouldNarrow}
-      {...props}
-    >
-      {isMobileScreen ? (
-        <div
-          className="window-header"
-          data-tauri-drag-region
-          style={{
-            paddingLeft: 0,
-            paddingRight: 0,
-          }}
-        >
-          <div className="window-actions">
-            <div className="window-action-button">
-              <IconButton
-                icon={<ReturnIcon />}
-                bordered
-                title={Locale.Sd.Actions.ReturnHome}
-                onClick={() => navigate(Path.Home)}
-              />
-            </div>
-          </div>
-          <SDIcon width={50} height={50} />
-          <div className="window-actions">
-            <div className="window-action-button">
-              <IconButton
-                icon={<HistoryIcon />}
-                bordered
-                title={Locale.Sd.Actions.History}
-                onClick={() => navigate(Path.SdNew)}
-              />
-            </div>
-          </div>
-        </div>
-      ) : (
-        <SideBarHeader
-          title={
-            <IconButton
-              icon={<ReturnIcon />}
-              bordered
-              title={Locale.Sd.Actions.ReturnHome}
-              onClick={() => navigate(Path.Home)}
-            />
-          }
-          logo={<SDIcon width={38} height={"100%"} />}
-        ></SideBarHeader>
-      )}
-      <SideBarBody>
-        <SdPanel />
-      </SideBarBody>
-      <SideBarTail
-        primaryAction={
-          <a href={REPO_URL} target="_blank" rel="noopener noreferrer">
-            <IconButton icon={<GithubIcon />} shadow />
-          </a>
-        }
-        secondaryAction={
-          <IconButton
-            text={Locale.SdPanel.Submit}
-            type="primary"
-            shadow
-            onClick={handleSubmit}
-          ></IconButton>
-        }
-      />
-    </SideBarContainer>
-  );
-}

+ 0 - 53
app/components/sd/sd.module.scss

@@ -1,53 +0,0 @@
-.sd-img-list{
-  display: flex;
-  flex-wrap: wrap;
-  justify-content: space-between;
-  .sd-img-item{
-    width: 48%;
-    .sd-img-item-info{
-      flex:1;
-      width: 100%;
-      overflow: hidden;
-      user-select: text;
-      p{
-        margin: 6px;
-        font-size: 12px;
-      }
-      .line-1{
-        overflow: hidden;
-        white-space: nowrap;
-        text-overflow: ellipsis;
-      }
-    }
-    .pre-img{
-      display: flex;
-      width: 130px;
-      justify-content: center;
-      align-items: center;
-      background-color: var(--second);
-      border-radius: 10px;
-    }
-    .img{
-      width: 130px;
-      height: 130px;
-      border-radius: 10px;
-      overflow: hidden;
-      cursor: pointer;
-      transition: all .3s;
-      &:hover{
-        opacity: .7;
-      }
-    }
-    &:not(:last-child){
-      margin-bottom: 20px;
-    }
-  }
-}
-
-@media only screen and (max-width: 600px) {
-  .sd-img-list{
-    .sd-img-item{
-      width: 100%;
-    }
-  }
-}

+ 0 - 336
app/components/sd/sd.tsx

@@ -1,336 +0,0 @@
-import chatStyles from "@/app/components/chat.module.scss";
-import styles from "@/app/components/sd/sd.module.scss";
-import homeStyles from "@/app/components/home.module.scss";
-
-import { IconButton } from "@/app/components/button";
-import ReturnIcon from "@/app/icons/return.svg";
-import Locale from "@/app/locales";
-import { Path } from "@/app/constant";
-import React, { useEffect, useMemo, useRef, useState } from "react";
-import {
-  copyToClipboard,
-  getMessageTextContent,
-  useMobileScreen,
-} from "@/app/utils";
-import { useNavigate, useLocation } from "react-router-dom";
-import { useAppConfig } from "@/app/store";
-import MinIcon from "@/app/icons/min.svg";
-import MaxIcon from "@/app/icons/max.svg";
-import { getClientConfig } from "@/app/config/client";
-import { ChatAction } from "@/app/components/chat";
-import DeleteIcon from "@/app/icons/clear.svg";
-import CopyIcon from "@/app/icons/copy.svg";
-import PromptIcon from "@/app/icons/prompt.svg";
-import ResetIcon from "@/app/icons/reload.svg";
-import { useSdStore } from "@/app/store/sd";
-import LoadingIcon from "@/app/icons/three-dots.svg";
-import ErrorIcon from "@/app/icons/delete.svg";
-import SDIcon from "@/app/icons/sd.svg";
-import { Property } from "csstype";
-import {
-  showConfirm,
-  showImageModal,
-  showModal,
-} from "@/app/components/ui-lib";
-import { removeImage } from "@/app/utils/chat";
-import { SideBar } from "./sd-sidebar";
-import { WindowContent } from "@/app/components/home";
-import { params } from "./sd-panel";
-
-function getSdTaskStatus(item: any) {
-  let s: string;
-  let color: Property.Color | undefined = undefined;
-  switch (item.status) {
-    case "success":
-      s = Locale.Sd.Status.Success;
-      color = "green";
-      break;
-    case "error":
-      s = Locale.Sd.Status.Error;
-      color = "red";
-      break;
-    case "wait":
-      s = Locale.Sd.Status.Wait;
-      color = "yellow";
-      break;
-    case "running":
-      s = Locale.Sd.Status.Running;
-      color = "blue";
-      break;
-    default:
-      s = item.status.toUpperCase();
-  }
-  return (
-    <p className={styles["line-1"]} title={item.error} style={{ color: color }}>
-      <span>
-        {Locale.Sd.Status.Name}: {s}
-      </span>
-      {item.status === "error" && (
-        <span
-          className="clickable"
-          onClick={() => {
-            showModal({
-              title: Locale.Sd.Detail,
-              children: (
-                <div style={{ color: color, userSelect: "text" }}>
-                  {item.error}
-                </div>
-              ),
-            });
-          }}
-        >
-          - {item.error}
-        </span>
-      )}
-    </p>
-  );
-}
-
-export function Sd() {
-  const isMobileScreen = useMobileScreen();
-  const navigate = useNavigate();
-  const location = useLocation();
-  const clientConfig = useMemo(() => getClientConfig(), []);
-  const showMaxIcon = !isMobileScreen && !clientConfig?.isApp;
-  const config = useAppConfig();
-  const scrollRef = useRef<HTMLDivElement>(null);
-  const sdStore = useSdStore();
-  const [sdImages, setSdImages] = useState(sdStore.draw);
-  const isSd = location.pathname === Path.Sd;
-
-  useEffect(() => {
-    setSdImages(sdStore.draw);
-  }, [sdStore.currentId]);
-
-  return (
-    <>
-      <SideBar className={isSd ? homeStyles["sidebar-show"] : ""} />
-      <WindowContent>
-        <div className={chatStyles.chat} key={"1"}>
-          <div className="window-header" data-tauri-drag-region>
-            {isMobileScreen && (
-              <div className="window-actions">
-                <div className={"window-action-button"}>
-                  <IconButton
-                    icon={<ReturnIcon />}
-                    bordered
-                    title={Locale.Chat.Actions.ChatList}
-                    onClick={() => navigate(Path.Sd)}
-                  />
-                </div>
-              </div>
-            )}
-            <div
-              className={`window-header-title ${chatStyles["chat-body-title"]}`}
-            >
-              <div className={`window-header-main-title`}>Stability AI</div>
-              <div className="window-header-sub-title">
-                {Locale.Sd.SubTitle(sdImages.length || 0)}
-              </div>
-            </div>
-
-            <div className="window-actions">
-              {showMaxIcon && (
-                <div className="window-action-button">
-                  <IconButton
-                    aria={Locale.Chat.Actions.FullScreen}
-                    icon={config.tightBorder ? <MinIcon /> : <MaxIcon />}
-                    bordered
-                    onClick={() => {
-                      config.update(
-                        (config) => (config.tightBorder = !config.tightBorder),
-                      );
-                    }}
-                  />
-                </div>
-              )}
-              {isMobileScreen && <SDIcon width={50} height={50} />}
-            </div>
-          </div>
-          <div className={chatStyles["chat-body"]} ref={scrollRef}>
-            <div className={styles["sd-img-list"]}>
-              {sdImages.length > 0 ? (
-                sdImages.map((item: any) => {
-                  return (
-                    <div
-                      key={item.id}
-                      style={{ display: "flex" }}
-                      className={styles["sd-img-item"]}
-                    >
-                      {item.status === "success" ? (
-                        <img
-                          className={styles["img"]}
-                          src={item.img_data}
-                          alt={item.id}
-                          onClick={(e) =>
-                            showImageModal(
-                              item.img_data,
-                              true,
-                              isMobileScreen
-                                ? { width: "100%", height: "fit-content" }
-                                : { maxWidth: "100%", maxHeight: "100%" },
-                              isMobileScreen
-                                ? { width: "100%", height: "fit-content" }
-                                : { width: "100%", height: "100%" },
-                            )
-                          }
-                        />
-                      ) : item.status === "error" ? (
-                        <div className={styles["pre-img"]}>
-                          <ErrorIcon />
-                        </div>
-                      ) : (
-                        <div className={styles["pre-img"]}>
-                          <LoadingIcon />
-                        </div>
-                      )}
-                      <div
-                        style={{ marginLeft: "10px" }}
-                        className={styles["sd-img-item-info"]}
-                      >
-                        <p className={styles["line-1"]}>
-                          {Locale.SdPanel.Prompt}:{" "}
-                          <span
-                            className="clickable"
-                            title={item.params.prompt}
-                            onClick={() => {
-                              showModal({
-                                title: Locale.Sd.Detail,
-                                children: (
-                                  <div style={{ userSelect: "text" }}>
-                                    {item.params.prompt}
-                                  </div>
-                                ),
-                              });
-                            }}
-                          >
-                            {item.params.prompt}
-                          </span>
-                        </p>
-                        <p>
-                          {Locale.SdPanel.AIModel}: {item.model_name}
-                        </p>
-                        {getSdTaskStatus(item)}
-                        <p>{item.created_at}</p>
-                        <div className={chatStyles["chat-message-actions"]}>
-                          <div className={chatStyles["chat-input-actions"]}>
-                            <ChatAction
-                              text={Locale.Sd.Actions.Params}
-                              icon={<PromptIcon />}
-                              onClick={() => {
-                                showModal({
-                                  title: Locale.Sd.GenerateParams,
-                                  children: (
-                                    <div style={{ userSelect: "text" }}>
-                                      {Object.keys(item.params).map((key) => {
-                                        let label = key;
-                                        let value = item.params[key];
-                                        switch (label) {
-                                          case "prompt":
-                                            label = Locale.SdPanel.Prompt;
-                                            break;
-                                          case "negative_prompt":
-                                            label =
-                                              Locale.SdPanel.NegativePrompt;
-                                            break;
-                                          case "aspect_ratio":
-                                            label = Locale.SdPanel.AspectRatio;
-                                            break;
-                                          case "seed":
-                                            label = "Seed";
-                                            value = value || 0;
-                                            break;
-                                          case "output_format":
-                                            label = Locale.SdPanel.OutFormat;
-                                            value = value?.toUpperCase();
-                                            break;
-                                          case "style":
-                                            label = Locale.SdPanel.ImageStyle;
-                                            value = params
-                                              .find(
-                                                (item) =>
-                                                  item.value === "style",
-                                              )
-                                              ?.options?.find(
-                                                (item) => item.value === value,
-                                              )?.name;
-                                            break;
-                                          default:
-                                            break;
-                                        }
-
-                                        return (
-                                          <div
-                                            key={key}
-                                            style={{ margin: "10px" }}
-                                          >
-                                            <strong>{label}: </strong>
-                                            {value}
-                                          </div>
-                                        );
-                                      })}
-                                    </div>
-                                  ),
-                                });
-                              }}
-                            />
-                            <ChatAction
-                              text={Locale.Sd.Actions.Copy}
-                              icon={<CopyIcon />}
-                              onClick={() =>
-                                copyToClipboard(
-                                  getMessageTextContent({
-                                    role: "user",
-                                    content: item.params.prompt,
-                                  }),
-                                )
-                              }
-                            />
-                            <ChatAction
-                              text={Locale.Sd.Actions.Retry}
-                              icon={<ResetIcon />}
-                              onClick={() => {
-                                const reqData = {
-                                  model: item.model,
-                                  model_name: item.model_name,
-                                  status: "wait",
-                                  params: { ...item.params },
-                                  created_at: new Date().toLocaleString(),
-                                  img_data: "",
-                                };
-                                sdStore.sendTask(reqData);
-                              }}
-                            />
-                            <ChatAction
-                              text={Locale.Sd.Actions.Delete}
-                              icon={<DeleteIcon />}
-                              onClick={async () => {
-                                if (
-                                  await showConfirm(Locale.Sd.Danger.Delete)
-                                ) {
-                                  // remove img_data + remove item in list
-                                  removeImage(item.img_data).finally(() => {
-                                    sdStore.draw = sdImages.filter(
-                                      (i: any) => i.id !== item.id,
-                                    );
-                                    sdStore.getNextId();
-                                  });
-                                }
-                              }}
-                            />
-                          </div>
-                        </div>
-                      </div>
-                    </div>
-                  );
-                })
-              ) : (
-                <div>{Locale.Sd.EmptyRecord}</div>
-              )}
-            </div>
-          </div>
-        </div>
-      </WindowContent>
-    </>
-  );
-}

+ 0 - 4
app/constant.ts

@@ -38,8 +38,6 @@ export enum Path {
   NewChat = "/new-chat",
   Masks = "/masks",
   Auth = "/auth",
-  Sd = "/sd",
-  SdNew = "/sd-new",
   Artifacts = "/artifacts",
 }
 
@@ -86,7 +84,6 @@ export enum StoreKey {
   Prompt = "prompt-store",
   Update = "chat-update",
   Sync = "sync",
-  SdList = "sd-list",
 }
 
 export const DEFAULT_SIDEBAR_WIDTH = 300;
@@ -482,4 +479,3 @@ export const internalAllowedWebDavEndpoints = [
   "https://app.koofr.net/dav/Koofr",
 ];
 
-export const PLUGINS = [{ name: "Stable Diffusion", path: Path.Sd }];

+ 0 - 163
app/store/sd.ts

@@ -1,163 +0,0 @@
-import {
-  Stability,
-  StoreKey,
-  ACCESS_CODE_PREFIX,
-  ApiPath,
-} from "@/app/constant";
-import { getBearerToken } from "@/app/client/api";
-import { createPersistStore } from "@/app/utils/store";
-import { nanoid } from "nanoid";
-import { uploadImage, base64Image2Blob } from "@/app/utils/chat";
-import { models, getModelParamBasicData } from "@/app/components/sd/sd-panel";
-import { useAccessStore } from "./access";
-
-const defaultModel = {
-  name: models[0].name,
-  value: models[0].value,
-};
-
-const defaultParams = getModelParamBasicData(models[0].params({}), {});
-
-const DEFAULT_SD_STATE = {
-  currentId: 0,
-  draw: [],
-  currentModel: defaultModel,
-  currentParams: defaultParams,
-};
-
-export const useSdStore = createPersistStore<
-  {
-    currentId: number;
-    draw: any[];
-    currentModel: typeof defaultModel;
-    currentParams: any;
-  },
-  {
-    getNextId: () => number;
-    sendTask: (data: any, okCall?: Function) => void;
-    updateDraw: (draw: any) => void;
-    setCurrentModel: (model: any) => void;
-    setCurrentParams: (data: any) => void;
-  }
->(
-  DEFAULT_SD_STATE,
-  (set, _get) => {
-    function get() {
-      return {
-        ..._get(),
-        ...methods,
-      };
-    }
-
-    const methods = {
-      getNextId() {
-        const id = ++_get().currentId;
-        set({ currentId: id });
-        return id;
-      },
-      sendTask(data: any, okCall?: Function) {
-        data = { ...data, id: nanoid(), status: "running" };
-        set({ draw: [data, ..._get().draw] });
-        this.getNextId();
-        this.stabilityRequestCall(data);
-        okCall?.();
-      },
-      stabilityRequestCall(data: any) {
-        const accessStore = useAccessStore.getState();
-        let prefix: string = ApiPath.Stability as string;
-        let bearerToken = "";
-        if (accessStore.useCustomConfig) {
-          prefix = accessStore.stabilityUrl || (ApiPath.Stability as string);
-          bearerToken = getBearerToken(accessStore.stabilityApiKey);
-        }
-        if (!bearerToken && accessStore.enabledAccessControl()) {
-          bearerToken = getBearerToken(
-            ACCESS_CODE_PREFIX + accessStore.accessCode,
-          );
-        }
-        const headers = {
-          Accept: "application/json",
-          Authorization: bearerToken,
-        };
-        const path = `${prefix}/${Stability.GeneratePath}/${data.model}`;
-        const formData = new FormData();
-        for (let paramsKey in data.params) {
-          formData.append(paramsKey, data.params[paramsKey]);
-        }
-        fetch(path, {
-          method: "POST",
-          headers,
-          body: formData,
-        })
-          .then((response) => response.json())
-          .then((resData) => {
-            if (resData.errors && resData.errors.length > 0) {
-              this.updateDraw({
-                ...data,
-                status: "error",
-                error: resData.errors[0],
-              });
-              this.getNextId();
-              return;
-            }
-            const self = this;
-            if (resData.finish_reason === "SUCCESS") {
-              uploadImage(base64Image2Blob(resData.image, "image/png"))
-                .then((img_data) => {
-                  console.debug("uploadImage success", img_data, self);
-                  self.updateDraw({
-                    ...data,
-                    status: "success",
-                    img_data,
-                  });
-                })
-                .catch((e) => {
-                  console.error("uploadImage error", e);
-                  self.updateDraw({
-                    ...data,
-                    status: "error",
-                    error: JSON.stringify(e),
-                  });
-                });
-            } else {
-              self.updateDraw({
-                ...data,
-                status: "error",
-                error: JSON.stringify(resData),
-              });
-            }
-            this.getNextId();
-          })
-          .catch((error) => {
-            this.updateDraw({ ...data, status: "error", error: error.message });
-            console.error("Error:", error);
-            this.getNextId();
-          });
-      },
-      updateDraw(_draw: any) {
-        const draw = _get().draw || [];
-        draw.some((item, index) => {
-          if (item.id === _draw.id) {
-            draw[index] = _draw;
-            set(() => ({ draw }));
-            return true;
-          }
-        });
-      },
-      setCurrentModel(model: any) {
-        set({ currentModel: model });
-      },
-      setCurrentParams(data: any) {
-        set({
-          currentParams: data,
-        });
-      },
-    };
-
-    return methods;
-  },
-  {
-    name: StoreKey.SdList,
-    version: 1.0,
-  },
-);