Fixed progress showing as int instead of human-readable in index and backend view. Added Download entire logfile button.

This commit is contained in:
abdulmohsen
2024-05-13 13:06:19 +03:00
parent d3999541c6
commit 686d6bb82f
5 changed files with 55 additions and 3 deletions

View File

@@ -22,6 +22,7 @@
"ext-curl": "*",
"ext-sodium": "*",
"ext-simplexml": "*",
"ext-fileinfo": "*",
"monolog/monolog": "^3.4",
"symfony/console": "^6.1.4",
"symfony/cache": "^6.1.3",

View File

@@ -69,7 +69,7 @@
<span class="has-text-success" v-if="history.watched">Played</span>
<span class="has-text-danger" v-else>Unplayed</span>
</div>
<div class="card-footer-item">{{ history.progress }}</div>
<div class="card-footer-item">{{ formatDuration(history.progress) }}</div>
</div>
</div>
</div>
@@ -99,7 +99,7 @@
<script setup>
import moment from 'moment'
import Message from '~/components/Message.vue'
import {notification} from "~/utils/index.js";
import {formatDuration, notification} from "~/utils/index.js";
const backend = useRoute().params.backend
const historyUrl = `/history/?via=${backend}`

View File

@@ -52,7 +52,7 @@
<span class="has-text-success" v-if="history.watched">Played</span>
<span class="has-text-danger" v-else>Unplayed</span>
</div>
<div class="card-footer-item">{{ history.progress }}</div>
<div class="card-footer-item">{{ formatDuration(history.progress) }}</div>
</div>
</div>
</div>
@@ -93,6 +93,7 @@
import request from '~/utils/request.js'
import moment from 'moment'
import Message from '~/components/Message.vue'
import {formatDuration} from "../utils/index.js";
useHead({title: 'Index'})

View File

@@ -9,6 +9,14 @@
<div class="is-pulled-right" v-if="!error">
<div class="field is-grouped">
<p class="control">
<button class="button is-danger is-light" v-tooltip="'Download the entire logfile.'" @click="downloadFile"
:class="{'is-loading':isDownloading}">
<span class="icon">
<i class="fas fa-download"></i>
</span>
</button>
</p>
<p class="control" v-if="filename.includes(moment().format('YYYYMMDD'))">
<button class="button" v-tooltip="'Watch log'" @click="watchLog"
:class="{'is-primary':!stream,'is-danger':stream}">
@@ -31,6 +39,7 @@
<span class="icon"><i class="fas fa-sync"></i></span>
</button>
</p>
</div>
</div>
</div>
@@ -76,6 +85,8 @@ const data = ref([])
const error = ref('')
const wrapLines = ref(true)
const isDownloading = ref(false)
const api_path = useStorage('api_path', '/v1/api')
const api_url = useStorage('api_url', '')
const api_token = useStorage('api_token', '')
@@ -127,6 +138,27 @@ const closeStream = () => {
}
}
const downloadFile = () => {
isDownloading.value = true;
const response = request(`/log/${filename}?download=1`)
if ('showSaveFilePicker' in window) {
response.then(async res => res.body.pipeTo(await (await showSaveFilePicker({
suggestedName: `${filename}`
})).createWritable()))
} else {
response.then(res => res.blob()).then(blob => {
isDownloading.value = false;
const fileURL = URL.createObjectURL(blob)
const fileLink = document.createElement('a')
fileLink.href = fileURL
fileLink.download = `${filename}`
fileLink.click()
});
}
}
const updateScroll = () => logContainer.value.scrollTop = logContainer.value.scrollHeight;
onUpdated(() => updateScroll());

View File

@@ -10,6 +10,7 @@ use App\Libs\DataUtil;
use App\Libs\HTTP_STATUS;
use App\Libs\Stream;
use App\Libs\StreamClosure;
use finfo;
use LimitIterator;
use Nyholm\Psr7\Response;
use Psr\Http\Message\ResponseInterface as iResponse;
@@ -129,6 +130,9 @@ final class Index
$file = new SplFileObject($filePath, 'r');
if (true === (bool)$params->get('download')) {
return $this->download($filePath);
}
if ($params->get('stream')) {
return $this->stream($filePath);
}
@@ -167,6 +171,20 @@ final class Index
);
}
private function download(string $filePath): iResponse
{
$mime = (new finfo(FILEINFO_MIME_TYPE))->file($filePath);
return new Response(
status: HTTP_STATUS::HTTP_OK->value,
headers: [
'Content-Type' => false === $mime ? 'application/octet-stream' : $mime,
'Content-Length' => filesize($filePath),
],
body: stream::make($filePath, 'r')
);
}
private function stream(string $filePath): iResponse
{
ini_set('max_execution_time', '3601');