Skip to content

Commit 2f19e49

Browse files
committed
直した!!!
1 parent b33af7d commit 2f19e49

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/app/charites/TridentFileSystem.tsx

+16-4
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,24 @@ export const TridentFileSystem: React.FC = () => {
206206
prompt: inputText,
207207
});
208208
console.log(resJson.content);
209-
const resContent = resJson.content;
210-
const newFilePath = resContent.split("\n")[0].replace("# path: ", "");
209+
const resContent = resJson.content as string;
210+
const regex = /```(?:yaml)?\n([\s\S]+)\n```/;
211+
const resMatched = resContent.match(regex);
212+
const resBody = resMatched ? resMatched[1] : null;
213+
if (!resBody) {
214+
throw new Error("AIによるファイルの編集に失敗しました");
215+
}
216+
const newFilePath = resBody.split("\n")[0].replace("# path: ", "");
217+
console.log(newFilePath);
211218
const newDirPath = newFilePath.split("/").slice(0, -1).join("/");
219+
console.log(newDirPath);
212220
const newFileName = newFilePath.split("/").pop();
213-
const newContent = resContent.split("\n").slice(1).join("\n");
221+
console.log(newFileName);
222+
if (!newFileName || !newDirPath) {
223+
throw new Error("AIによるファイルの編集に失敗しました");
224+
}
214225
const newDirHandle = await rootDirHandle.getDirectoryHandle(newDirPath);
226+
const newContent = resBody.split("\n").slice(1).join("\n");
215227

216228
const newFileHandle = await newDirHandle.getFileHandle(newFileName, {
217229
create: true,
@@ -366,7 +378,7 @@ export const TridentFileSystem: React.FC = () => {
366378
zoom: 4,
367379
}}
368380
style={{ width: "100vw", height: "80vh" }}
369-
mapStyle={styleJsonOutput}
381+
mapStyle={styleJsonOutput ? styleJsonOutput : {}}
370382
>
371383
<GeolocateControl />
372384
</Map>

0 commit comments

Comments
 (0)