Skip to content
Snippets Groups Projects
Verified Commit 6fabe75e authored by BARBIER Marc's avatar BARBIER Marc
Browse files

safe fetches

parent 243f082b
Branches
No related tags found
No related merge requests found
import secureFetch from '@/secureFetch'
import { defineComponent } from 'vue'
import HeaderComponent from '../components/HeaderComponent/HeaderComponent.vue'
......@@ -23,7 +24,7 @@ export default defineComponent({
},
methods: {
loadProjects() {
fetch('http://localhost:8080/rest/projects').then(async (response) => {
secureFetch(this, 'http://localhost:8080/rest/projects').then(async (response) => {
if(response.status != 200) console.log(response)
else {
this.projects = await response.json()
......@@ -44,7 +45,7 @@ export default defineComponent({
if(this.newProjectName) {
const data = new FormData()
data.append('name', this.newProjectName)
fetch("http://localhost:8080/rest/project/create", {
secureFetch(this, "http://localhost:8080/rest/project/create", {
method: 'POST',
body: data
})
......@@ -65,7 +66,7 @@ export default defineComponent({
return
}
const id = await (await fetch('http://localhost:8080/rest/upload', {
const id = await (await secureFetch(this, 'http://localhost:8080/rest/upload', {
method: 'POST',
body: data
})).text()
......@@ -74,7 +75,7 @@ export default defineComponent({
if(file.name.endsWith('.csv')) {
const form = new FormData()
form.append('id', id)
await fetch('http://localhost:8080/rest/transform/convert-to-arff', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/transform/convert-to-arff', { method: 'POST', body: form })
}
this.loadProjects()
......@@ -82,7 +83,7 @@ export default defineComponent({
async deleteDataset(id: string) {
const url = 'http://localhost:8080/rest/item/remove?item='+encodeURIComponent(id)
await fetch(url, { method: 'POST' })
await secureFetch(this, url, { method: 'POST' })
this.loadProjects()
},
......
......@@ -3,6 +3,7 @@ import HeaderComponent from '../components/HeaderComponent/HeaderComponent.vue'
import TableComponent from '@/components/TableComponent/TableComponent.vue'
import Multiselect from '@vueform/multiselect'
import switchToNewestProject from '@/switchToNewestProject'
import secureFetch from '@/secureFetch'
//TODO: add optionals for other algorithms
......@@ -70,7 +71,7 @@ export default defineComponent({
}
//load
const data: { [key: string]: string }[] | { timestamp: number, status: number, error: string, path: string } = await (await fetch(`http://localhost:8080/rest/metadata/attributes?id=${localStorage.getItem('datasetId')}`)).json()
const data: { [key: string]: string }[] | { timestamp: number, status: number, error: string, path: string } = await (await secureFetch(this, `http://localhost:8080/rest/metadata/attributes?id=${localStorage.getItem('datasetId')}`)).json()
if(!data || 'status' in data) {
localStorage.removeItem('datasetId')
this.$router.push('/')
......@@ -78,8 +79,8 @@ export default defineComponent({
}
this.columns = data.flatMap(val => Object.keys(val))
this.fileItem = await (await fetch(`http://localhost:8080/rest/metadata/fileitem?id=${localStorage.getItem('datasetId')}`)).json()
this.dictionary = await(await fetch(`http://localhost:8080/rest/mining/dictionary?id=${localStorage.getItem('datasetId')}`)).json()
this.fileItem = await (await secureFetch(this, `http://localhost:8080/rest/metadata/fileitem?id=${localStorage.getItem('datasetId')}`)).json()
this.dictionary = await(await secureFetch(this, `http://localhost:8080/rest/mining/dictionary?id=${localStorage.getItem('datasetId')}`)).json()
},
methods: {
async runSetMining(e: Event) {
......@@ -89,7 +90,7 @@ export default defineComponent({
const form = new FormData(e.target)
form.append('columns', this.selectedPatternColumns.join(','))
form.append('id', '' + localStorage.getItem('datasetId'))
const response = await fetch('http://localhost:8080/rest/mining/mine', { method: 'POST', body: form })
const response = await secureFetch(this, 'http://localhost:8080/rest/mining/mine', { method: 'POST', body: form })
if(response.status === 200) {
this.$toast.info(await response.text())
switchToNewestProject(this)
......@@ -110,7 +111,7 @@ export default defineComponent({
const form = new FormData(e.target)
form.append('columns', this.selectedSequenceColumns.join(','))
form.append('id', '' + localStorage.getItem('datasetId'))
const response = await fetch('http://localhost:8080/rest/mining/mine', { method: 'POST', body: form })
const response = await secureFetch(this, 'http://localhost:8080/rest/mining/mine', { method: 'POST', body: form })
if(response.status === 200) {
this.$toast.info(await response.text())
switchToNewestProject(this)
......@@ -128,7 +129,7 @@ export default defineComponent({
this.arePatternsLoading = true
this.patternData = null
this.currentPattern = null
this.patternData = await (await fetch(`http://localhost:8080/rest/load-patterns-metadata?filename=${encodeURIComponent(filename)}&id=${localStorage.getItem('datasetId')}`)).json()
this.patternData = await (await secureFetch(this, `http://localhost:8080/rest/load-patterns-metadata?filename=${encodeURIComponent(filename)}&id=${localStorage.getItem('datasetId')}`)).json()
this.currentPattern = filename
this.arePatternsLoading = false
},
......@@ -139,7 +140,7 @@ export default defineComponent({
form.append('filename', filename)
form.append('id', '' + localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/mining/remove-patternset', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/mining/remove-patternset', { method: 'POST', body: form })
this.$router.go(0)
},
......@@ -151,7 +152,7 @@ export default defineComponent({
const form = new FormData(e.target)
form.append('filename', currentPattern)
form.append('id', '' + localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/mining/filter-length', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/mining/filter-length', { method: 'POST', body: form })
this.$router.go(0)
} else {
this.$toast.warning('Please select a pattern')
......@@ -175,7 +176,7 @@ export default defineComponent({
form.append('filename', currentPattern)
form.append('id', '' + localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/mining/filter-support', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/mining/filter-support', { method: 'POST', body: form })
this.$router.go(0)
} else {
this.$toast.warning('Please select a pattern')
......@@ -200,7 +201,7 @@ export default defineComponent({
form.append('filename', currentPattern)
form.append('id', '' + localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/mining/filter-jaccard', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/mining/filter-jaccard', { method: 'POST', body: form })
this.$router.go(0)
} else {
this.$toast.warning('Please select a pattern')
......@@ -224,7 +225,7 @@ export default defineComponent({
form.append('filename', currentPattern)
form.append('id', '' + localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/mining/filter-time-constraint', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/mining/filter-time-constraint', { method: 'POST', body: form })
this.$router.go(0)
} else {
this.$toast.warning('Please select a pattern')
......@@ -237,7 +238,7 @@ export default defineComponent({
form.append('id', '' + localStorage.getItem('datasetId'))
form.append('patternFilenames', this.selectedPatternFPOF.map(label => this.fileItem?.patterns.find(pattern => pattern.label === label)?.filename).join(','))
const response = await fetch('http://localhost:8080/rest/mining/anomaly-detection-fpof', { method: 'POST', body: form })
const response = await secureFetch(this, 'http://localhost:8080/rest/mining/anomaly-detection-fpof', { method: 'POST', body: form })
if(response.status === 200) {
this.$toast.info(await response.text())
......@@ -258,7 +259,7 @@ export default defineComponent({
form.append('id', '' + localStorage.getItem('datasetId'))
form.append('patternFilenames', this.selectedPatternPBAD.map(label => this.fileItem?.patterns.find(pattern => pattern.label === label)?.filename).join(','))
const response = await fetch('http://localhost:8080/rest/mining/anomaly-detection-pbad', { method: 'POST', body: form })
const response = await secureFetch(this, 'http://localhost:8080/rest/mining/anomaly-detection-pbad', { method: 'POST', body: form })
if(response.status === 200) {
this.$toast.info(await response.text())
......@@ -286,10 +287,10 @@ export default defineComponent({
const form = new FormData(e.target)
form.append('id', '' + localStorage.getItem('datasetId'))
form.append('patternFilename', currentPattern)
const response = await fetch('http://localhost:8080/rest/mining/min-max-filter-support', { method: 'POST', body: form })
const response = await secureFetch(this, 'http://localhost:8080/rest/mining/min-max-filter-support', { method: 'POST', body: form })
if(response.status === 200) {
//this.$router.go(0)
this.$router.go(0)
} else {
this.$toast.error(await response.text())
}
......
......@@ -5,6 +5,7 @@ import Multiselect from '@vueform/multiselect'
import ChartComponent, { type BackgroundElement, type ChartElement } from '@/components/ChartComponent/ChartComponent.vue'
import Slider from '@vueform/slider'
import makeTheSliderDragOnLock from './makeTheSliderDragOnLock'
import secureFetch from '@/secureFetch'
export default defineComponent({
name: 'PlotView',
......@@ -95,7 +96,7 @@ export default defineComponent({
this.$router.push('/')
}
this.fileItem = await (await fetch(`http://localhost:8080/rest/metadata/fileitem?id=${localStorage.getItem('datasetId')}`)).json()
this.fileItem = await (await secureFetch(this, `http://localhost:8080/rest/metadata/fileitem?id=${localStorage.getItem('datasetId')}`)).json()
await this.loadDataSet()
this.sliderMax = this.dataset?.totalSize || 1000
......@@ -110,7 +111,7 @@ export default defineComponent({
async loadDataSet(xmin?: number, xmax?: number) {
const id = localStorage.getItem('datasetId')
if(id) {
const response = await fetch(`http://localhost:8080/rest/load-data?id=${id}&windowed=false&pagination=${xmin || 0}-${xmax || 1000}`)
const response = await secureFetch(this, `http://localhost:8080/rest/load-data?id=${id}&windowed=false&pagination=${xmin || 0}-${xmax || 1000}`)
this.dataset = await response.json()
this.columns = this.dataset?.rows[0] || []
}
......@@ -131,7 +132,7 @@ export default defineComponent({
const item = {} as Record<string, Table>
for(const score of scores) {
item[score.label] = await (await fetch(`http://localhost:8080/rest/load-anomaly-score?filename=${score.filename}&id=${localStorage.getItem('datasetId')}`)).json()
item[score.label] = await (await secureFetch(this, `http://localhost:8080/rest/load-anomaly-score?filename=${score.filename}&id=${localStorage.getItem('datasetId')}`)).json()
}
this.scores = item
......@@ -298,8 +299,8 @@ export default defineComponent({
filename = patternList[patternId].filename
}
this.patterns = await (await fetch(`http://localhost:8080/rest/load-patterns?filename=${encodeURIComponent(filename)}&id=${localStorage.getItem('datasetId')}`)).json()
this.patternsOcc = await (await fetch(`http://localhost:8080/rest/load-pattern-occ?filename=${encodeURIComponent(filename)}&id=${localStorage.getItem('datasetId')}`)).json()
this.patterns = await (await secureFetch(this, `http://localhost:8080/rest/load-patterns?filename=${encodeURIComponent(filename)}&id=${localStorage.getItem('datasetId')}`)).json()
this.patternsOcc = await (await secureFetch(this, `http://localhost:8080/rest/load-pattern-occ?filename=${encodeURIComponent(filename)}&id=${localStorage.getItem('datasetId')}`)).json()
this.selectedPatterns = []
},
selectAll() {
......
import { defineComponent } from 'vue'
import HeaderComponent from '../components/HeaderComponent/HeaderComponent.vue'
import TableComponent from '@/components/TableComponent/TableComponent.vue'
import secureFetch from '@/secureFetch'
export default defineComponent({
name: 'TableView',
......@@ -42,7 +43,7 @@ export default defineComponent({
}
//on ne veut que le nombre de page
this.dataset = await this.fetchDataset(0,0)
const stats: Stats[] = await (await (await fetch(`http://localhost:8080/rest/metadata/attribute-and-statistics?id=${localStorage.getItem('datasetId')}` )).json())
const stats: Stats[] = await (await secureFetch(this, `http://localhost:8080/rest/metadata/attribute-and-statistics?id=${localStorage.getItem('datasetId')}` )).json()
if(this.hasWindows) {
const windowsAttributes = stats.find(stat => stat.attribute === 'Window')
......@@ -59,9 +60,9 @@ export default defineComponent({
const id = localStorage.getItem('datasetId')
if(id) {
if(this.windows)
return ( await fetch(`http://localhost:8080/rest/load-data?id=${id}&windowed=${this.windows}&pagination=${from * this.windowWidth}-${to * this.windowWidth}`)).json()
return ( await secureFetch(this, `http://localhost:8080/rest/load-data?id=${id}&windowed=${this.windows}&pagination=${from * this.windowWidth}-${to * this.windowWidth}`)).json()
else
return ( await fetch(`http://localhost:8080/rest/load-data?id=${id}&windowed=${this.windows}&pagination=${from}-${to}`)).json()
return ( await secureFetch(this, `http://localhost:8080/rest/load-data?id=${id}&windowed=${this.windows}&pagination=${from}-${to}`)).json()
} else {
this.$router.push('/')
//this error is thrown but will never have any impact
......
import { Chart as ChartJS, Tooltip, BarElement, CategoryScale, LinearScale } from 'chart.js'
import { defineComponent } from 'vue'
import HeaderComponent from '../components/HeaderComponent/HeaderComponent.vue'
import { Bar } from 'vue-chartjs'
import Multiselect from '@vueform/multiselect'
import HeaderComponent from '../components/HeaderComponent/HeaderComponent.vue'
import { Bar } from 'vue-chartjs'
import { Chart as ChartJS, Tooltip, BarElement, CategoryScale, LinearScale } from 'chart.js'
import secureFetch from '@/secureFetch'
import switchToNewestProject from '@/switchToNewestProject'
ChartJS.register(Tooltip, BarElement, CategoryScale, LinearScale)
......@@ -24,6 +26,7 @@ export default defineComponent({
selectedDropColumns: [] as string[],
selectedDateColumns: [] as string[],
selectedTypeColumns: [] as string[],
columnToRename: "",
bins: null as number | null,
useDensity: false,
columns: [] as string[],
......@@ -47,12 +50,7 @@ export default defineComponent({
this.$router.push('/')
}
const response = await fetch(`http://localhost:8080/rest/metadata/attribute-and-statistics?id=${localStorage.getItem('datasetId')}`)
const stats: Stats[] = await response.json()
this.columns = stats.map(e => e.attribute)
this.stats = stats.map(e => ({ ...e,
'histogram-labels': e['histogram-labels']?.split(',')?.slice(0, -1)?.join(',')
}))
await this.loadStats()
},
methods: {
async paa(e: Event) {
......@@ -63,7 +61,7 @@ export default defineComponent({
form.append('columns', this.PAAValues?.join(','))
form.append('window', this.PAAwindow.toString())
form.append('id', ''+localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/transform/paa', { body: form, method: 'POST' })
await secureFetch(this, 'http://localhost:8080/rest/transform/paa', { body: form, method: 'POST' })
await switchToNewestProject(this)
},
......@@ -76,7 +74,7 @@ export default defineComponent({
form.append('density', this.useDensity.toString())
form.append('bins', this.bins.toString())
form.append('id', ''+localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/transform/discretize', { body: form, method: 'POST' })
await secureFetch(this, 'http://localhost:8080/rest/transform/discretize', { body: form, method: 'POST' })
await switchToNewestProject(this)
},
......@@ -85,7 +83,7 @@ export default defineComponent({
// @ts-expect-error the target is a form
const form = new FormData(e.target)
form.append('id', ''+localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/transform/replace-outlier', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/transform/replace-outlier', { method: 'POST', body: form })
await switchToNewestProject(this)
},
......@@ -95,7 +93,7 @@ export default defineComponent({
// @ts-expect-error the target is a form
const form = new FormData(e.target)
form.append('id', ''+localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/transform/make-windows', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/transform/make-windows', { method: 'POST', body: form })
await switchToNewestProject(this)
localStorage.setItem('hasWindows', 'true')
},
......@@ -105,7 +103,7 @@ export default defineComponent({
//@ts-expect-error the target is a form
const form = new FormData(e.target)
form.append('id', '' + localStorage.getItem('datasetId'))
await fetch('http://localhost:8080/rest/transform/run-sql-query', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/transform/run-sql-query', { method: 'POST', body: form })
await switchToNewestProject(this)
},
......@@ -134,8 +132,27 @@ export default defineComponent({
form.append('id', '' + localStorage.getItem('datasetId'))
form.append('columns', columns.join(','))
form.append('transforms', name)
await fetch('http://localhost:8080/rest/transform/transform-columns/', { method: 'POST', body: form })
await secureFetch(this, 'http://localhost:8080/rest/transform/transform-columns/', { method: 'POST', body: form })
await switchToNewestProject(this)
}
},
async rename(e: Event) {
e.preventDefault()
//@ts-expect-error we know it's a form
const form = new FormData(e.target)
form.append('old_name', this.columnToRename)
form.append('id', '' + localStorage.getItem('datasetId'))
await secureFetch(this, 'http://localhost:8080/rest/transform/rename/', { method: 'POST', body: form })
await switchToNewestProject(this)
},
async loadStats() {
const response = await secureFetch(this, `http://localhost:8080/rest/metadata/attribute-and-statistics?id=${localStorage.getItem('datasetId')}`)
const stats: Stats[] = await response.json()
this.columns = stats.map(e => e.attribute)
this.stats = stats.map(e => ({ ...e,
'histogram-labels': e['histogram-labels']?.split(',')?.slice(0, -1)?.join(',')
}))
},
},
})
......@@ -238,6 +238,20 @@
<br>
<input type="submit" class="btn btn-primary" value="Run">
</form>
<hr>
<form @submit="rename">
<label>Rename column</label>
<Multiselect
v-model="columnToRename"
:options="columns"
/>
<br>
<input type="text" class="form-control" name="new_name" placeholder="new name" id="newname" required>
<br>
<input type="submit" class="btn btn-primary" value="Run">
</form>
</div>
</div>
</div>
......
import type { ComponentPublicInstance } from "vue"
async function secureFetch(self: ComponentPublicInstance, url: string, options?: RequestInit) {
const promise = fetch(url, options)
try {
//await so we can capture exceptions
return await promise
} catch(e) {
self.$toast.clear()
self.$toast.show('Could not contact the server make sure it is running on port 8080', { maxToasts: 1, type: 'error', duration: 3600 * 1000 })
let serverAvailable = false
while(!serverAvailable) {
await new Promise((res) => {
setTimeout(() => {
fetch('http://localhost:8080/', { method: 'HEAD' }).then(() => {
self.$toast.clear()
self.$toast.success('The connection to the server is back up :)')
serverAvailable = true
res(null)
}).catch(() => { /* juste ignore exceptions */ res(null) })
}, 1000)
})
}
return fetch(url, options)
}
}
export default secureFetch
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment