FIX: Disable ajv schema validation for now

Doing schema compilation in renderer requires unsafe-eval CSP, let's rather compile them at build time
This commit is contained in:
Robert Kossessa
2024-03-01 22:34:42 +01:00
parent 7e5bb6ea26
commit 746c339c16
2 changed files with 27 additions and 34 deletions

View File

@@ -1,7 +1,6 @@
import { createPinia, defineStore } from 'pinia' import { createPinia, defineStore } from 'pinia'
import Axios from 'axios' // import schema from '@renderer/data/profileSchema.json' // see below
import schema from '@renderer/data/profileSchema.json' // import Ajv from 'ajv' // see below
import Ajv from 'ajv'
import WIP from '@renderer/components/WIP.vue' import WIP from '@renderer/components/WIP.vue'
import KnobFeedbackConfig from '@renderer/components/config/knob/KnobFeedbackConfig.vue' import KnobFeedbackConfig from '@renderer/components/config/knob/KnobFeedbackConfig.vue'
import KnobLightConfig from '@renderer/components/config/knob/KnobLightConfig.vue' import KnobLightConfig from '@renderer/components/config/knob/KnobLightConfig.vue'
@@ -9,8 +8,9 @@ import KeyLightConfig from '@renderer/components/config/keys/KeyLightConfig.vue'
import KnobMappingConfig from '@renderer/components/config/knob/KnobMappingConfig.vue' import KnobMappingConfig from '@renderer/components/config/knob/KnobMappingConfig.vue'
import KeyMappingConfig from '@renderer/components/config/keys/KeyMappingConfig.vue' import KeyMappingConfig from '@renderer/components/config/keys/KeyMappingConfig.vue'
import { shallowRef } from 'vue' import { shallowRef } from 'vue'
import mockData from '@renderer/data/nanoConfig.json'
const ajv = new Ajv() // const ajv = new Ajv() // see below
export const useStore = defineStore('main', { export const useStore = defineStore('main', {
state: () => { state: () => {
@@ -131,37 +131,30 @@ export const useStore = defineStore('main', {
profile.name = newName profile.name = newName
}, },
fetchProfiles() { fetchProfiles() {
Axios.get('http://localhost:3001/categories') const categories = mockData.categories
.then((res) => { console.log(categories)
const categories = res.data const ids = new Set()
console.log(categories) // const validate = ajv.compile(schema) // see below
const ids = new Set() this.$patch({
const validate = ajv.compile(schema) profileCategories: categories.map((category) => ({
this.$patch({ name: category.name,
profileCategories: categories.map((category) => ({ profiles: category.profiles.filter((profile) => {
name: category.name, // Ajv validation requires unsafe-eval CSP, let's not do that
profiles: category.profiles.filter((profile) => { // TODO: Remove ajv validation completely or compile schema at build time
// TODO: Validation seems to be broken right now // if (!validate(profile)) {
if (!validate(profile)) { // console.error('Failed to validate profile: ' + profile.name, validate.errors)
console.error('Failed to validate profile: ' + profile.name, validate.errors) // return false
return false // }
} if (ids.has(profile.id)) {
if (ids.has(profile.id)) { console.error('Duplicate profile id: ' + profile.id + ' for profile: ' + profile.name)
console.error( return false
'Duplicate profile id: ' + profile.id + ' for profile: ' + profile.name }
) ids.add(profile.id)
return false return true
}
ids.add(profile.id)
return true
})
})),
selectedProfileId: categories[0]?.profiles[0]?.id || null
}) })
}) })),
.catch((err) => { selectedProfileId: categories[0]?.profiles[0]?.id || null
console.error(err) })
})
}, },
newProfileName(originalName = '') { newProfileName(originalName = '') {
let name = originalName let name = originalName