follow the rabbit to fix potential issues

This commit is contained in:
dakai 2024-10-14 02:33:28 +08:00
parent e64a4f209c
commit 39f5d263f9
4 changed files with 13 additions and 24 deletions

View File

@ -1122,12 +1122,11 @@ function _Chat() {
}; };
const updateMessageAudio = (msgId?: string, audio_url?: string) => { const updateMessageAudio = (msgId?: string, audio_url?: string) => {
chatStore.updateCurrentSession( chatStore.updateCurrentSession((session) => {
(session) => session.messages = session.messages.map((m) =>
(session.messages = session.messages.map((m) => m.id === msgId ? { ...m, audio_url } : m,
m.id === msgId ? { ...m, audio_url } : m, );
)), });
);
}; };
const onDelete = (msgId: string) => { const onDelete = (msgId: string) => {
@ -1903,7 +1902,6 @@ function _Chat() {
)} )}
{message.audio_url && ( {message.audio_url && (
<audio <audio
id="audio"
preload="auto" preload="auto"
controls controls
className={styles["chat-message-item-audio"]} className={styles["chat-message-item-audio"]}

View File

@ -403,8 +403,9 @@ pre {
audio { audio {
height: 35px; height: 35px;
} }
audio::-webkit-media-controls-play-button, audio::-webkit-media-controls-play-button,
audio::-webkit-media-controls-panel { audio::-webkit-media-controls-panel,
background-color: none; audio::-moz-media-controls-play-button,
} audio::-moz-media-controls-panel {
background: none;
}

View File

@ -251,19 +251,6 @@ export function getMessageImages(message: RequestMessage): string[] {
return urls; return urls;
} }
//export function getMessageAudio(message: RequestMessage): string[] {
// if (typeof message.content === "string") {
// return [];
// }
// const urls: string[] = [];
// for (const c of message.content) {
// if (c.type === "image_url") {
// urls.push(c.image_url?.url ?? "");
// }
// }
// return urls;
//}
export function isVisionModel(model: string) { export function isVisionModel(model: string) {
// Note: This is a better way using the TypeScript feature instead of `&&` or `||` (ts v5.5.0-dev.20240314 I've been using) // Note: This is a better way using the TypeScript feature instead of `&&` or `||` (ts v5.5.0-dev.20240314 I've been using)

View File

@ -90,6 +90,9 @@ export function arrayBufferToWav(buffer: ArrayBuffer): ArrayBuffer {
// Helper function to write a string to the DataView // Helper function to write a string to the DataView
function writeString(view: DataView, offset: number, string: string) { function writeString(view: DataView, offset: number, string: string) {
if (offset + string.length > view.byteLength) {
throw new Error("String is too long for the available space in DataView");
}
for (let i = 0; i < string.length; i++) { for (let i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i)); view.setUint8(offset + i, string.charCodeAt(i));
} }