Skip to content

Commit 89aa946

Browse files
committed
feat: add download backup button
1 parent 53d0cde commit 89aa946

File tree

3 files changed

+50
-28
lines changed

3 files changed

+50
-28
lines changed

src/pages/tasks/index.vue

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,55 @@ function limitText(text: string, length: number) {
3939
}
4040
4141
function handleNext() {
42-
router.push({
43-
path: "/tasks",
44-
query: {
45-
page: page.value + 1,
46-
search: searchRef.value || undefined,
47-
},
48-
})
42+
if (page.value < totalPages.value) {
43+
router.push({
44+
path: "/tasks",
45+
query: {
46+
page: page.value + 1,
47+
search: searchRef.value || undefined,
48+
},
49+
})
50+
}
4951
}
5052
5153
function handlePrev() {
52-
router.push({
53-
path: "/tasks",
54-
query: {
55-
page: page.value - 1,
56-
search: searchRef.value || undefined,
57-
},
58-
})
54+
if (page.value > 1) {
55+
router.push({
56+
path: "/tasks",
57+
query: {
58+
page: page.value - 1,
59+
search: searchRef.value || undefined,
60+
},
61+
})
62+
}
5963
}
6064
</script>
6165

6266
<template>
6367
<div class="container-fluid py-4">
64-
<form method="get" action="">
65-
<div class="row mb-3">
66-
<div class="col">
67-
<div class="d-flex justify-content-end">
68-
<input
69-
type="search"
70-
name="search"
71-
class="form-control w-auto"
72-
placeholder="Search tasks..."
73-
v-model="searchRef"
74-
/>
75-
<button type="submit" class="btn btn-primary ml-2">Search</button>
68+
<div class="flex justify-between">
69+
<div>
70+
<button class="btn btn-outline-primary">
71+
<NuxtLink to="/api/tasks/backup" target="_blank"> Backup </NuxtLink>
72+
</button>
73+
</div>
74+
<form method="get" action="">
75+
<div class="row mb-3">
76+
<div class="col">
77+
<div class="d-flex justify-content-end">
78+
<input
79+
type="search"
80+
name="search"
81+
class="form-control w-auto"
82+
placeholder="Search tasks..."
83+
v-model="searchRef"
84+
/>
85+
<button type="submit" class="btn btn-primary ml-2">Search</button>
86+
</div>
7687
</div>
7788
</div>
78-
</div>
79-
</form>
89+
</form>
90+
</div>
8091

8192
<div class="table-responsive">
8293
<table class="table table-striped table-hover">

src/server/api/tasks/backup.get.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import fs from "fs"
2+
import { envVariables } from "~/server/env"
3+
4+
export default defineEventHandler(async (event) => {
5+
const stream = fs.createReadStream(envVariables.dbFilePath)
6+
setHeader(event, "Content-Type", "application/octet-stream")
7+
setHeader(event, "Content-Disposition", 'attachment; filename="database.db"')
8+
9+
return sendStream(event, stream)
10+
})

src/server/env.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const envVariables = {
2+
dbFilePath: process.env.DB_FILE_PATH!,
23
taskiqAdminApiToken: process.env.TASKIQ_ADMIN_API_TOKEN!,
34
}

0 commit comments

Comments
 (0)