Update dependencies and fix image URL transformation

This commit is contained in:
小石头 2024-03-29 16:35:19 +08:00
parent 58b7fa428a
commit f650b960dc
8 changed files with 48 additions and 8 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
REACT_APP_IMAGE_BASE_URL=https://img2.baidu.com

View File

@ -124,7 +124,7 @@
"axios": "^1.3.6",
"clean-webpack-plugin": "^4.0.0",
"dayjs": "^1.11.10",
"dotenv": "^16.0.3",
"dotenv": "^16.4.5",
"i18next": "^23.7.11",
"js-yaml": "^4.1.0",
"lodash.clonedeep": "^4.5.0",

View File

@ -196,10 +196,16 @@ const MessageMarkdown = observer((props: MessageMarkdownProps) => {
}
return children;
}, [children, i18n.language]);
console.log("process.env.REACT_APP_IMAGE_BASE_URL", process.env.platform);
return (
<ReactMarkdown
{...props}
transformImageUri={(uri) =>
uri.startsWith("http")
? uri
: `${process.env.REACT_APP_IMAGE_BASE_URL}${uri}`
}
remarkPlugins={[
() => (tree) => {
let stepCount = 1;

View File

@ -153,7 +153,9 @@ const Config = function () {
value: writeConfig,
key: "",
});
MessageUtil.sendMessage({ command: "readConfig", key: "" });
setTimeout(() => {
MessageUtil.sendMessage({ command: "readConfig", key: "" });
}, 1000);
};
const changeModelDetail = (key: string, value: number | string) => {

View File

@ -2,6 +2,7 @@ import MessageUtil from "@/util/MessageUtil";
import { types, Instance } from "mobx-state-tree";
import modelsTemplate from "@/models";
import cloneDeep from "lodash.clonedeep";
import { set } from "mobx";
const defaultAPIBase = [
"https://api.devchat.ai/v1",
@ -65,6 +66,7 @@ export const ConfigStore = types
},
setConfig: function (data) {
self.settle = false;
let needUpdate = false;
const newConfig = { ...data };
if (!data.models) {
newConfig.models = {};
@ -112,6 +114,12 @@ export const ConfigStore = types
}
});
const modelList = this.getModelList();
if (!modelList.includes(newConfig.default_model)) {
newConfig.default_model = modelList[0];
needUpdate = true;
}
if (!defaultAPIBase.includes(newConfig.providers.devchat.api_base)) {
newConfig.providers.devchat.cumstom_api_base =
newConfig.providers.devchat.api_base;
@ -121,6 +129,9 @@ export const ConfigStore = types
self.config = newConfig;
self.settle = true;
self.defaultModel = newConfig.default_model;
if (needUpdate) {
this.writeConfig();
}
},
getModelList: () => {
const modelsArray = self.modelsTemplate.map((item) => {
@ -129,7 +140,6 @@ export const ConfigStore = types
return modelsArray;
},
writeConfig: function () {
console.log("writeConfig");
const writeConfig = cloneDeep(self.config);
if (
writeConfig.providers.devchat.api_base === "custom" &&
@ -145,6 +155,10 @@ export const ConfigStore = types
value: writeConfig,
key: "",
});
setTimeout(() => {
MessageUtil.sendMessage({ command: "readConfig", key: "" });
}, 1000);
},
setConfigValue: function (key: string, value: any) {
if (key === "default_model") {

View File

@ -4,6 +4,14 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const { DefinePlugin } = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const dotenv = require("dotenv");
const env = dotenv.config().parsed;
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
const webviewConfig = {
name: "webview",
@ -105,6 +113,7 @@ const webviewConfig = {
}),
new DefinePlugin({
"process.env.platform": JSON.stringify("vscode"),
...envKeys,
}),
// new CopyWebpackPlugin({
// patterns: [{ from: "dist", to: "../dist" }],

View File

@ -1,4 +1,3 @@
//@ts-check
"use strict";
const path = require("path");
@ -6,6 +5,14 @@ const HtmlWebpackPlugin = require("html-webpack-plugin");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const webpack = require("webpack");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const dotenv = require("dotenv");
const env = dotenv.config().parsed;
const envKeys = Object.keys(env).reduce((prev, next) => {
prev[`process.env.${next}`] = JSON.stringify(env[next]);
return prev;
}, {});
const webviewConfig = {
name: "webview",
@ -94,6 +101,7 @@ const webviewConfig = {
new webpack.ProgressPlugin(),
new webpack.DefinePlugin({
"process.env.platform": JSON.stringify("idea"),
...envKeys,
}),
],
};

View File

@ -3759,10 +3759,10 @@ dot-case@^3.0.4:
no-case "^3.0.4"
tslib "^2.0.3"
dotenv@^16.0.3:
version "16.3.1"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e"
integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==
dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==
duplexer2@~0.1.4:
version "0.1.4"