From ababe830d59bae5e36455dfa3ef2424c0c49a3df Mon Sep 17 00:00:00 2001 From: Sig <62321214+sigprogramming@users.noreply.github.com> Date: Thu, 26 Dec 2024 23:17:56 +0900 Subject: [PATCH] =?UTF-8?q?audio.ts=E3=81=A7generateTextFileData=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/audio.ts | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/store/audio.ts b/src/store/audio.ts index f93c7d2f91..85a793da09 100644 --- a/src/store/audio.ts +++ b/src/store/audio.ts @@ -1,4 +1,3 @@ -import Encoding from "encoding-japanese"; import { createUILockAction, withProgress } from "./ui"; import { AudioItem, @@ -64,6 +63,7 @@ import { cloneWithUnwrapProxy } from "@/helpers/cloneWithUnwrapProxy"; import { UnreachableError } from "@/type/utility"; import { errorToMessage } from "@/helpers/errorHelper"; import path from "@/helpers/path"; +import { generateTextFileData } from "@/helpers/fileDataGenerator"; function generateAudioKey() { return AudioKey(uuid4()); @@ -147,29 +147,13 @@ export async function writeTextFile(obj: { text: string; encoding?: EncodingType; }) { - obj.encoding ??= "UTF-8"; - - const textBlob = { - "UTF-8": (text: string) => { - const bom = new Uint8Array([0xef, 0xbb, 0xbf]); - return new Blob([bom, text], { - type: "text/plain;charset=UTF-8", - }); - }, - Shift_JIS: (text: string) => { - const sjisArray = Encoding.convert(Encoding.stringToCode(text), { - to: "SJIS", - type: "arraybuffer", - }); - return new Blob([new Uint8Array(sjisArray)], { - type: "text/plain;charset=Shift_JIS", - }); - }, - }[obj.encoding](obj.text); - + const textFileData = await generateTextFileData({ + text: obj.text, + encoding: obj.encoding, + }); return window.backend.writeFile({ filePath: obj.filePath, - buffer: await textBlob.arrayBuffer(), + buffer: textFileData, }); }