Skip to content

Commit

Permalink
Merge pull request #988 from traPtitech/fix/cannot-export-log
Browse files Browse the repository at this point in the history
正しくログを出力できるように
  • Loading branch information
cp-20 authored Dec 24, 2024
2 parents bd84835 + 108944e commit 641cf37
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions dashboard/src/components/templates/app/ContainerLogExport.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { fromJsonString, toJsonString } from '@bufbuild/protobuf'
import { type Timestamp, TimestampSchema } from '@bufbuild/protobuf/wkt'
import { toJsonString } from '@bufbuild/protobuf'
import { type Timestamp, timestampFromDate, TimestampSchema } from '@bufbuild/protobuf/wkt'
import { type Component, Show, createSignal } from 'solid-js'
import toast from 'solid-toast'
import type { Application, ApplicationOutput } from '/@/api/neoshowcase/protobuf/gateway_pb'
import { Button } from '/@/components/UI/Button'
import { TextField } from '/@/components/UI/TextField'
Expand All @@ -26,13 +25,12 @@ const getLogsBefore = async (
setProgressMessage: (message: string) => void,
): Promise<ApplicationOutput[]> => {
let remainingLines = lines
const firstBefore: Timestamp = fromJsonString(TimestampSchema, before)
const firstBefore: Timestamp = timestampFromDate(new Date(before))
let nextBefore = firstBefore
let logLines: ApplicationOutput[] = []
while (remainingLines > 0 && firstBefore.seconds - nextBefore.seconds < days * secondsPerDay) {
const msg = `${toJsonString(TimestampSchema, nextBefore)} より前のログを取得中、残り ${remainingLines} 行 ...`
setProgressMessage(msg)
console.log(msg)

const res = await client.getOutput({
applicationId: appID,
Expand Down Expand Up @@ -96,34 +94,26 @@ const exportBefore = async (
setProgressMessage: (message: string) => void,
) => {
if (Number.isNaN(days)) {
toast.error('日数に整数を指定してください')
return
throw new Error('日数に整数を指定してください')
}
if (days <= 0) {
toast.error('1日以上を指定してください')
return
throw new Error('1日以上を指定してください')
}
if (days > maxExportDays) {
toast.error(`${maxExportDays} 日以下を指定してください`)
return
throw new Error(`${maxExportDays} 日以下を指定してください`)
}
if (Number.isNaN(lines)) {
toast.error('行に整数を指定してください')
return
throw new Error('行に整数を指定してください')
}
if (lines <= 0) {
toast.error('1行以上を指定してください')
return
throw new Error('1行以上を指定してください')
}
if (lines > maxExportLines) {
toast.error(`${maxExportLines} 行以下を指定してください`)
return
throw new Error(`${maxExportLines} 行以下を指定してください`)
}
try {
fromJsonString(TimestampSchema, beforeStr)
} catch (e) {
toast.error('日付フォーマットが正しくありません')
return
const date = new Date(beforeStr)
if (Number.isNaN(date)) {
throw new Error('日付フォーマットが正しくありません')
}

const logLines = await getLogsBefore(app.id, beforeStr, days, lines, setProgressMessage)
Expand Down Expand Up @@ -157,10 +147,12 @@ export const ContainerLogExport: Component<Props> = (props) => {
setExporting(true)
try {
await run()
setProgressMessage('エクスポート完了!')
} catch (e) {
handleAPIError(e, 'ログのエクスポートに失敗しました')
} finally {
setExporting(false)
}
setProgressMessage('エクスポート完了!')
setExporting(false)
}

Expand Down

0 comments on commit 641cf37

Please sign in to comment.