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