feat: Remove unused import in CharConfig.svelte and update shareRisuHub function
This commit is contained in:
@@ -5,7 +5,7 @@ import { checkNullish, decryptBuffer, encryptBuffer, selectFileByDom, selectMult
|
||||
import { language } from "src/lang"
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { characterFormatUpdate } from "./characters"
|
||||
import { AppendableBuffer, checkCharOrder, downloadFile, loadAsset, LocalWriter, readImage, saveAsset, VirtualWriter } from "./storage/globalApi"
|
||||
import { AppendableBuffer, checkCharOrder, downloadFile, loadAsset, LocalWriter, openURL, readImage, saveAsset, VirtualWriter } from "./storage/globalApi"
|
||||
import { CurrentCharacter, selectedCharID } from "./stores"
|
||||
import { convertImage, hasher } from "./parser"
|
||||
import { CCardLib } from '@risuai/ccardlib'
|
||||
@@ -745,6 +745,12 @@ export async function exportSpecV2(char:character, type:'png'|'json'|'rcc' = 'pn
|
||||
}
|
||||
}
|
||||
|
||||
export async function shareRisuHub3() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
export async function shareRisuHub2(char:character, arg:{
|
||||
nsfw: boolean,
|
||||
tag:string
|
||||
@@ -772,6 +778,14 @@ export async function shareRisuHub2(char:character, arg:{
|
||||
|
||||
const writer = new VirtualWriter()
|
||||
await exportSpecV2(char, 'png', {writer: writer})
|
||||
const dat = Buffer.from(writer.buf.buffer).toString('base64') + '&' + 'rt.png'
|
||||
|
||||
openURL(`https://realm.risuai.net/hub/realm/upload#filedata=${encodeURIComponent(dat)}`)
|
||||
|
||||
let testMode = true
|
||||
if(testMode){
|
||||
return
|
||||
}
|
||||
|
||||
const fetchPromise = fetch(hubURL + '/hub/realm/upload', {
|
||||
method: "POST",
|
||||
@@ -808,85 +822,6 @@ export async function shareRisuHub2(char:character, arg:{
|
||||
|
||||
}
|
||||
|
||||
export async function shareRisuHub(char:character, arg:{
|
||||
nsfw: boolean,
|
||||
tag:string
|
||||
license: string
|
||||
anon: boolean
|
||||
}) {
|
||||
char = structuredClone(char)
|
||||
char.license = arg.license
|
||||
let tagList = arg.tag.split(',')
|
||||
|
||||
if(arg.nsfw){
|
||||
tagList.push("nsfw")
|
||||
}
|
||||
|
||||
|
||||
|
||||
let tags = tagList.filter((v, i) => {
|
||||
return (!!v) && (tagList.indexOf(v) === i)
|
||||
})
|
||||
char.tags = tags
|
||||
|
||||
|
||||
let img = await readImage(char.image)
|
||||
|
||||
try{
|
||||
const card = await createBaseV2(char)
|
||||
let resources:[string,string][] = []
|
||||
if(card.data.extensions.risuai.emotions && card.data.extensions.risuai.emotions.length > 0){
|
||||
for(let i=0;i<card.data.extensions.risuai.emotions.length;i++){
|
||||
alertStore.set({
|
||||
type: 'wait',
|
||||
msg: `Loading... (Adding Emotions ${i} / ${card.data.extensions.risuai.emotions.length})`
|
||||
})
|
||||
const data = card.data.extensions.risuai.emotions[i][1]
|
||||
const rData = await readImage(data)
|
||||
resources.push([data, Buffer.from(await convertImage(rData)).toString('base64')])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(card.data.extensions.risuai.additionalAssets && card.data.extensions.risuai.additionalAssets.length > 0){
|
||||
for(let i=0;i<card.data.extensions.risuai.additionalAssets.length;i++){
|
||||
alertStore.set({
|
||||
type: 'wait',
|
||||
msg: `Loading... (Adding Additional Assets ${i} / ${card.data.extensions.risuai.additionalAssets.length})`
|
||||
})
|
||||
const data = card.data.extensions.risuai.additionalAssets[i][1]
|
||||
const rData = await readImage(data)
|
||||
resources.push([data, Buffer.from(await convertImage(rData)).toString('base64')])
|
||||
}
|
||||
}
|
||||
|
||||
const da = await fetch(hubURL + '/hub/upload', {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
card: card,
|
||||
img: Buffer.from(img).toString('base64'),
|
||||
resources: resources,
|
||||
token: get(DataBase)?.account?.token,
|
||||
username: arg.anon ? '' : (get(DataBase)?.account?.id),
|
||||
apiver: 3
|
||||
})
|
||||
})
|
||||
|
||||
if(da.status !== 200){
|
||||
alertError(await da.text())
|
||||
}
|
||||
else{
|
||||
alertMd(await da.text())
|
||||
}
|
||||
}
|
||||
catch(e){
|
||||
alertError(`${e}`)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export type hubType = {
|
||||
name:string
|
||||
desc: string
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { get } from "svelte/store";
|
||||
import { exportSpecV2 } from "./characterCards";
|
||||
import { VirtualWriter } from "./storage/globalApi";
|
||||
import { VirtualWriter, isTauri, openURL } from "./storage/globalApi";
|
||||
import { sleep } from "./util";
|
||||
import { CurrentCharacter } from "./stores";
|
||||
import { DataBase, type character } from "./storage/database";
|
||||
@@ -26,21 +26,8 @@ export async function shareRealmCard() {
|
||||
export async function openRealm(name:string,data:ArrayBuffer) {
|
||||
const tk = get(DataBase)?.account?.token;
|
||||
const id = get(DataBase)?.account?.id
|
||||
const win = window.open(`https://realm.risuai.net/upload?token=${tk}&token_id=${id}`, "_blank");
|
||||
pong = false;
|
||||
while(true){
|
||||
if(pong){
|
||||
break;
|
||||
}
|
||||
win.postMessage("ping", "https://realm.risuai.net")
|
||||
await sleep(500);
|
||||
}
|
||||
alertStore.set({
|
||||
type: 'none',
|
||||
msg: ''
|
||||
})
|
||||
|
||||
const nameBuf = new TextEncoder().encode(name);
|
||||
|
||||
win.postMessage("filedata", "https://realm.risuai.net", [nameBuf,data]);
|
||||
const trimedName = name.replace(/[^a-zA-Z0-9]/g, '') || 'character';
|
||||
const filedata = encodeURIComponent(Buffer.from(data).toString('base64')) + `&${trimedName}.png`;
|
||||
const url = `https://realm.risuai.net/upload?token=${tk}&token_id=${id}#filedata=${filedata}`
|
||||
window.open(url, '_blank')
|
||||
}
|
||||
Reference in New Issue
Block a user