import { reactive } from 'vue' import { lacuna, call } from '@tlecommunity/super-core' class CaptchaStore { data = reactive({ guid: '', url: '', solved: false, }) async fetch() { const captcha = await call(() => lacuna.captcha.fetch()) this.data.guid = captcha.guid this.data.url = captcha.url this.data.solved = false } async refresh() { const newCaptcha = await call(() => lacuna.captcha.fetch()) this.data.guid = newCaptcha.guid this.data.url = newCaptcha.url this.data.solved = false } async solve(answer) { const { error } = await lacuna.captcha.solve({ guid: this.data.guid, solution: answer }) if (error) { console.error(error.message) this.refresh() return false } this.data.solved = true return true } clear() { this.data.guid = '' this.data.url = '' this.data.solved = false } } export default new CaptchaStore()