Skip to content

Commit

Permalink
remove rocard things
Browse files Browse the repository at this point in the history
  • Loading branch information
steve02081504 committed Oct 8, 2024
1 parent 97946de commit b61535a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 77 deletions.
48 changes: 0 additions & 48 deletions src/page/char-download.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -275,45 +275,6 @@ function getHostFromUrl(url) {
}
}

// rocard.ai
async function downloadRocardCharacter(id) {
let result = await fetch('https://api.rochathub.com/rocard.tavern.v1.TavernService/DownloadTavern', {
method: 'POST',
body: JSON.stringify({
tavernId: id
}),
headers: {
'content-type': 'application/json'
}
})

let check = async _ => {
if (!result.ok) {
const text = await result.text()
console.log('Rocard returned error', result.statusText, text)
throw new Error('Failed to download character')
}
}
await check()

const json = await result.json()
result = await fetch(json.downloadUrl)
await check()

const buffer = await result.buffer()
const fileName = `${sanitize(id)}.png`
const fileType = result.headers.get('content-type') || 'image/png'

return { buffer, fileName, fileType }
}

function parseRocardUrl(url) {
// https://rocard.ai/t/114514
const pattern = /^https?:\/\/rocard\.ai\/t\/(\d+)\/?$/i
const match = url.match(pattern)
return match ? match[1] : null
}

async function downloadGithubCharacter(id) {
const result = await fetch(`https://api.github.com/repos/${id}/releases/latest`)

Expand Down Expand Up @@ -359,7 +320,6 @@ export async function downloadCharacter(url) {
const isPygmalionContent = host.includes('pygmalion.chat')
const isAICharacterCardsContent = host.includes('aicharactercards.com')
const isRisu = host.includes('realm.risuai.net')
const isRocard = host.includes('rocard.ai')
const isGitHub = host.includes('github.com')

if (isPygmalionContent) {
Expand Down Expand Up @@ -410,14 +370,6 @@ export async function downloadCharacter(url) {
type = 'character'
result = await downloadRisuCharacter(uuid)
}
else if (isRocard) {
const id = parseRocardUrl(url)
if (!id)
throw new Error('Not found')

type = 'character'
result = await downloadRocardCharacter(id)
}
else if (isGitHub) {
const id = parseGithubUrl(url)
if (!id)
Expand Down
30 changes: 1 addition & 29 deletions src/page/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -322,36 +322,8 @@ async function fetchAndProcessFile(fileUrl) {
return result
}

import aws from 'aws-sdk'
export async function shareCard(cardBuffer, /** @type {import('../charData.mjs').v1CharData} */ cardData) {
let result = await fetch('https://api.rochathub.com/rocard.tavern.v1.TavernService/SignUploadUrl', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
tavernDesc: cardData.description || 'some description',
tavernName: cardData.name || 'some name'
})
})
if (!result.ok) throw result.statusText
result = await result.json()
let request = new aws.S3()
request.config.update({
credentials: {
accessKeyId: result.accessKeyId,
secretAccessKey: result.secretAccessKey,
sessionToken: result.sessionToken
},
region: 'ap-northeast-1'
})
await request.upload({
Bucket: 'rocard',
Key: result.filePath,
Body: cardBuffer,
ContentType: 'image/png'
}).promise()
return `https://rocard.s3.ap-northeast-1.amazonaws.com/${result.filePath}`
throw new Error('Not implemented')
}

if (window.location.search) {
Expand Down

0 comments on commit b61535a

Please sign in to comment.