[feat] add export as dataset

This commit is contained in:
kwaroran
2023-12-28 23:48:48 +09:00
parent 64d109508d
commit 8b2a2f9ce8
3 changed files with 51 additions and 20 deletions

View File

@@ -0,0 +1,29 @@
import { get } from "svelte/store";
import { DataBase } from "./database";
import { downloadFile } from "./globalApi";
import { alertNormal } from "../alert";
import { language } from "src/lang";
export async function exportAsDataset(){
const db = get(DataBase)
let dataset = []
for(const char of db.characters){
if(char.type === 'group'){
continue
}
for(const chat of char.chats){
dataset.push({
character: char.name,
description: char.desc,
chats: chat.message,
})
}
}
await downloadFile('dataset.json',Buffer.from(JSON.stringify(dataset, null,4), 'utf-8'))
alertNormal(language.successExport)
}