-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add real log viewer page with pako integration
- Created logViewer.ts to handle log fetching and decompression using pako - Updated CodeBlock component to support log viewer variant - Added LogViewerCard with link to the new log viewer page - Implemented LogViewer page to display full logs - Updated routeTree.gen.ts to include the new log viewer route - Added new messages for log viewer in locales - Updated string utility to use URL object for truncation - Modified QuerySwitcher to display UnexpectedError component Closes #997
- Loading branch information
Showing
14 changed files
with
290 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pako from 'pako'; | ||
import type { UseQueryResult } from '@tanstack/react-query'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { minutesToMilliseconds } from 'date-fns'; | ||
|
||
import { RequestData } from './commonRequest'; | ||
|
||
// eslint-disable-next-line no-magic-numbers | ||
const STALE_DURATION_MS = minutesToMilliseconds(60); | ||
|
||
type FetchAndDecompressLogsResponse = { | ||
content: string; | ||
}; | ||
async function fetchAndDecompressLog( | ||
url: string, | ||
): Promise<FetchAndDecompressLogsResponse> { | ||
const proxyUrl = `/api/proxy/?url=${encodeURIComponent(url)}`; | ||
const urlPathname = new URL(url).pathname; | ||
const isGzipped = urlPathname.endsWith('.gz'); | ||
|
||
try { | ||
if (isGzipped) { | ||
const response = await RequestData.get<ArrayBuffer>(proxyUrl, { | ||
responseType: 'arraybuffer', | ||
}); | ||
|
||
const uint8ArrayResponse = new Uint8Array(response); | ||
const decompressedData = pako.inflate(uint8ArrayResponse); | ||
const textDecoder = new TextDecoder('utf-8'); | ||
const decompressedText = textDecoder.decode(decompressedData); | ||
|
||
return { content: decompressedText }; | ||
} else { | ||
// For non-gzipped files, request as text | ||
const response = await RequestData.get<string>(proxyUrl, { | ||
responseType: 'text', | ||
}); | ||
|
||
return { content: response }; | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
throw new Error( | ||
`Failed to fetch logs: ${error instanceof Error ? error.message : 'Unknown error'}`, | ||
); | ||
} | ||
} | ||
|
||
export const useLogViewer = ( | ||
url: string, | ||
): UseQueryResult<FetchAndDecompressLogsResponse> => { | ||
return useQuery({ | ||
queryKey: ['logs', url], | ||
queryFn: () => fetchAndDecompressLog(url), | ||
enabled: !!url, | ||
staleTime: STALE_DURATION_MS, | ||
refetchOnWindowFocus: false, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.