Make risurealm share and download to use new api

This commit is contained in:
kwaroran
2024-03-28 03:59:14 +09:00
parent ea6b1d20e5
commit 9f0d398d3b
2 changed files with 64 additions and 46 deletions

View File

@@ -61,7 +61,7 @@
if(!latin1.test(enNotes)){
alertError("English version of creator notes must contain only Latin-1 characters")
}
shareRisuHub(char, {
shareRisuHub2(char, {
anon: privateMode,
nsfw: nsfwMode,
tag: tags,
@@ -79,7 +79,7 @@
import { XIcon } from "lucide-svelte";
import { language } from "src/lang";
import { alertError } from "src/ts/alert";
import { shareRisuHub } from "src/ts/characterCards";
import { shareRisuHub2 } from "src/ts/characterCards";
import { DataBase, type character } from "src/ts/storage/database";
import TextInput from "../GUI/TextInput.svelte";
import Button from "../GUI/Button.svelte";

View File

@@ -730,51 +730,56 @@ export async function shareRisuHub2(char:character, arg:{
license: string
anon: boolean
}) {
char = cloneDeep(char)
char.license = arg.license
let tagList = arg.tag.split(',')
if(arg.nsfw){
tagList.push("nsfw")
}
await alertWait("Uploading...")
let tags = tagList.filter((v, i) => {
return (!!v) && (tagList.indexOf(v) === i)
})
char.tags = tags
const writer = new VirtualWriter()
await exportSpecV2(char, 'png', {writer: writer})
const fetchPromise = fetch(hubURL + '/hub/realm/upload', {
method: "POST",
body: writer.buf.buffer,
headers: {
"Content-Type": 'image/png',
"x-risu-api-version": "4",
"x-risu-token": get(DataBase)?.account?.token,
'x-risu-username': arg.anon ? '' : (get(DataBase)?.account?.id),
try {
char = cloneDeep(char)
char.license = arg.license
let tagList = arg.tag.split(',')
if(arg.nsfw){
tagList.push("nsfw")
}
})
const res = await fetchPromise
if(res.status !== 200){
alertError(await res.text())
}
else{
const resJSON = await res.json()
alertNormal(resJSON.message)
const currentChar = get(CurrentCharacter)
if(currentChar.type === 'group'){
return
await alertWait("Uploading...")
let tags = tagList.filter((v, i) => {
return (!!v) && (tagList.indexOf(v) === i)
})
char.tags = tags
const writer = new VirtualWriter()
await exportSpecV2(char, 'png', {writer: writer})
const fetchPromise = fetch(hubURL + '/hub/realm/upload', {
method: "POST",
body: writer.buf.buffer,
headers: {
"Content-Type": 'image/png',
"x-risu-api-version": "4",
"x-risu-token": get(DataBase)?.account?.token,
'x-risu-username': arg.anon ? '' : (get(DataBase)?.account?.id),
'x-risu-debug': 'true'
}
})
const res = await fetchPromise
if(res.status !== 200){
alertError(await res.text())
}
currentChar.realmId = resJSON.id
else{
const resJSON = await res.json()
alertMd(resJSON.message)
const currentChar = get(CurrentCharacter)
if(currentChar.type === 'group'){
return
}
currentChar.realmId = resJSON.id
}
} catch (error) {
alertError(`${error}`)
}
}
@@ -904,11 +909,24 @@ export async function downloadRisuHub(id:string) {
type: "wait",
msg: "Downloading..."
})
const res = await fetch(hubURL + '/hub/get/' + id)
const res = await fetch(hubURL + '/hub/get/' + id, {
headers: {
"x-risu-api-version": "4"
}
})
if(res.status !== 200){
alertError(await res.text())
return
}
if(res.headers.get('content-type') === 'image/png'){
await importCharacterProcess({
name: 'realm.png',
data: res.body
})
checkCharOrder()
return
}
const result = await res.json()
const data:CharacterCardV2 = result.card