Skip to content
/ web Public

Commit 03fd3e5

Browse files
committed
feature: download logs
1 parent dec6f8c commit 03fd3e5

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

components/ServiceLogs.vue

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,57 @@ import {
1010
TooltipProvider,
1111
TooltipTrigger,
1212
} from "~/components/ui/tooltip";
13+
import {
14+
DropdownMenu,
15+
DropdownMenuContent,
16+
DropdownMenuItem,
17+
DropdownMenuTrigger,
18+
} from "~/components/ui/dropdown-menu";
1319
1420
import { DownloadIcon, FullscreenIcon, ExpandIcon } from "lucide-vue-next";
1521
import Convert from "ansi-to-html";
22+
23+
const config = useRuntimeConfig();
24+
25+
async function downloadFullLogs(service: string) {
26+
try {
27+
const response = await fetch(
28+
`https://${config.public.apiDomain}/system/logs/download?service=${service}`,
29+
{
30+
method: "POST",
31+
headers: {
32+
"Content-Type": "application/json",
33+
},
34+
credentials: "include",
35+
body: JSON.stringify({ service }),
36+
},
37+
);
38+
39+
if (!response.ok) {
40+
throw new Error("Failed to download logs");
41+
}
42+
43+
const blob = await response.blob();
44+
const url = URL.createObjectURL(blob);
45+
46+
const contentDisposition = response.headers.get("Content-Disposition");
47+
let filename = `${service}-logs.zip`;
48+
if (contentDisposition) {
49+
const filenameMatch = contentDisposition.match(/filename="?([^"]+)"?/);
50+
if (filenameMatch) {
51+
filename = filenameMatch[1];
52+
}
53+
}
54+
55+
const a = document.createElement("a");
56+
a.href = url;
57+
a.download = filename;
58+
a.click();
59+
URL.revokeObjectURL(url);
60+
} catch (error) {
61+
console.error("Error downloading full logs", error);
62+
}
63+
}
1664
</script>
1765

1866
<template>
@@ -75,17 +123,26 @@ import Convert from "ansi-to-html";
75123
{{ $t("ui.logs.timestamps") }}
76124
</div>
77125

78-
<TooltipProvider>
79-
<Tooltip>
80-
<TooltipTrigger>
81-
<DownloadIcon
82-
@click="downloadLogs"
83-
class="h-5 w-5 cursor-pointer text-muted-foreground hover:text-foreground"
84-
/>
85-
</TooltipTrigger>
86-
<TooltipContent>{{ $t("ui.tooltips.download") }}</TooltipContent>
87-
</Tooltip>
88-
</TooltipProvider>
126+
<DropdownMenu>
127+
<DropdownMenuTrigger as-child>
128+
<button
129+
class="h-5 w-5 cursor-pointer text-muted-foreground hover:text-foreground flex items-center justify-center"
130+
>
131+
<DownloadIcon class="h-5 w-5" />
132+
</button>
133+
</DropdownMenuTrigger>
134+
<DropdownMenuContent align="end">
135+
<DropdownMenuItem @click="downloadLogs" class="cursor-pointer">
136+
Download visible logs
137+
</DropdownMenuItem>
138+
<DropdownMenuItem
139+
@click="downloadFullLogs(service)"
140+
class="cursor-pointer"
141+
>
142+
Download full logs
143+
</DropdownMenuItem>
144+
</DropdownMenuContent>
145+
</DropdownMenu>
89146
</div>
90147
</div>
91148

0 commit comments

Comments
 (0)