refactor: ♻️ refacto container requests
This commit is contained in:
parent
4943f81dea
commit
dedcfa2708
@ -96,72 +96,34 @@ export default {
|
|||||||
await this.refresh()
|
await this.refresh()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async pull() {
|
async request(method: 'get' | 'post' | 'delete', path: string) {
|
||||||
try {
|
try {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
const response = await axios.post<Container>(
|
const response = await axios[method]<Container>(path)
|
||||||
`/api/container/${this.container_name}/pull`,
|
|
||||||
)
|
|
||||||
this.container = response.data
|
this.container = response.data
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
this.error =
|
this.error =
|
||||||
error instanceof AxiosError
|
error instanceof AxiosError
|
||||||
? error.message
|
? error.message
|
||||||
: 'Error pulling container'
|
: 'Error performing operation'
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async pull() {
|
||||||
|
await this.request('post', `/api/container/${this.container_name}/pull`)
|
||||||
|
},
|
||||||
async refresh() {
|
async refresh() {
|
||||||
try {
|
await this.request('get', `/api/container/${this.container_name}`)
|
||||||
this.loading = true
|
|
||||||
const response = await axios.get<Container>(
|
|
||||||
`/api/container/${this.container_name}`,
|
|
||||||
)
|
|
||||||
this.container = response.data
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
this.error =
|
|
||||||
error instanceof AxiosError
|
|
||||||
? error.message
|
|
||||||
: 'Error loading container'
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async remove() {
|
async remove() {
|
||||||
if (!confirm('Are you sure you want to remove this container?')) return
|
if (!confirm('Are you sure you want to remove this container?')) return
|
||||||
try {
|
await this.request('delete', `/api/container/${this.container_name}`)
|
||||||
this.loading = true
|
|
||||||
await axios.delete(`/api/container/${this.container_name}`)
|
|
||||||
this.$router.push('/')
|
this.$router.push('/')
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
this.error =
|
|
||||||
error instanceof AxiosError
|
|
||||||
? error.message
|
|
||||||
: 'Error deleting container'
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
async restart() {
|
async restart() {
|
||||||
try {
|
this.request('post', `/api/container/${this.container_name}/restart`)
|
||||||
this.loading = true
|
|
||||||
const response = await axios.post<Container>(
|
|
||||||
`/api/container/${this.container_name}/restart`,
|
|
||||||
)
|
|
||||||
this.container = response.data
|
|
||||||
} catch (error) {
|
|
||||||
console.error(error)
|
|
||||||
this.error =
|
|
||||||
error instanceof AxiosError
|
|
||||||
? error.message
|
|
||||||
: 'Error restarting container'
|
|
||||||
} finally {
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user