feat(fc3b): platforms + credentials Pinia stores + vitests
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { useApi } from '../composables/useApi.js'
|
||||
|
||||
export const useCredentialsStore = defineStore('credentials', () => {
|
||||
const api = useApi()
|
||||
|
||||
const byPlatform = ref(new Map())
|
||||
const extensionKey = ref(null)
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
async function loadAll() {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const arr = await api.get('/api/credentials')
|
||||
const m = new Map()
|
||||
for (const c of arr) m.set(c.platform, c)
|
||||
byPlatform.value = m
|
||||
} catch (e) {
|
||||
error.value = e
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function upload(platform, credential_type, data) {
|
||||
const rec = await api.post('/api/credentials', {
|
||||
body: { platform, credential_type, data },
|
||||
})
|
||||
byPlatform.value.delete(platform)
|
||||
return rec
|
||||
}
|
||||
|
||||
async function remove(platform) {
|
||||
await api.delete(`/api/credentials/${platform}`)
|
||||
byPlatform.value.delete(platform)
|
||||
}
|
||||
|
||||
async function loadKey() {
|
||||
const body = await api.get('/api/settings/extension_api_key')
|
||||
extensionKey.value = body.key
|
||||
}
|
||||
|
||||
async function rotateKey() {
|
||||
const body = await api.post('/api/settings/extension_api_key/rotate')
|
||||
extensionKey.value = body.key
|
||||
}
|
||||
|
||||
return {
|
||||
byPlatform, extensionKey, loading, error,
|
||||
loadAll, upload, remove, loadKey, rotateKey,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
import { useApi } from '../composables/useApi.js'
|
||||
|
||||
export const usePlatformsStore = defineStore('platforms', () => {
|
||||
const api = useApi()
|
||||
|
||||
const byKey = ref(new Map())
|
||||
const loaded = ref(false)
|
||||
|
||||
const list = computed(() => Array.from(byKey.value.values()))
|
||||
|
||||
async function loadAll() {
|
||||
if (loaded.value) return
|
||||
const body = await api.get('/api/platforms')
|
||||
const m = new Map()
|
||||
for (const [k, v] of Object.entries(body.platforms || {})) {
|
||||
m.set(k, v)
|
||||
}
|
||||
byKey.value = m
|
||||
loaded.value = true
|
||||
}
|
||||
|
||||
return { byKey, loaded, list, loadAll }
|
||||
})
|
||||
Reference in New Issue
Block a user