-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Add file download functionality and reports page
- Loading branch information
1 parent
2391c70
commit 46cb1ab
Showing
16 changed files
with
417 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Controllers; | ||
|
||
class FileController | ||
{ | ||
public function downloadFile() | ||
{ | ||
$type = request('type'); | ||
$endpoint = request('endpoint'); | ||
$data = (array) json_decode(request('data')); | ||
|
||
$random = str_random(16); | ||
$fileName = "/tmp/" . $random . "." . $data['format']; | ||
$file = fopen($fileName, "w+"); | ||
|
||
getResponse(function ($client) use ($type, $endpoint, $data, $file) { | ||
return $client->request(strtoupper($type), getUrl($endpoint), [ | ||
'sink' => $file, | ||
]); | ||
}); | ||
|
||
if (!file_exists($fileName)) { | ||
abort("File not found", 404); | ||
} else { | ||
header("Content-Type: " . mime_content_type($fileName)); | ||
header("Content-Disposition: attachment; filename=" . $random . "." . $data['format']); | ||
|
||
readfile($fileName); | ||
} | ||
} | ||
} |
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
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,12 @@ | ||
export interface IReport { | ||
id: string | ||
created_at: string | ||
updated_at: string | ||
deleted_at: string | ||
status: string | ||
job_type: string | ||
file_type: string | ||
report_type: string | ||
message: string | ||
path: string | ||
} |
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,39 @@ | ||
import type { IFilter } from "@/models/Filter" | ||
import type { IReport } from "@/models/Report" | ||
import type { IPaginator } from "@/models/Paginator" | ||
import http from "@/utils/http-common" | ||
import { i18n } from "@/utils/i18n" | ||
import { defineStore } from "pinia" | ||
|
||
export const useReportStore = defineStore({ | ||
id: "report", | ||
state: () => ({ | ||
filter: {} as IFilter, | ||
reports: {} as IPaginator<IReport>, | ||
}), | ||
getters: { | ||
get: (state) => state.reports, | ||
}, | ||
actions: { | ||
async fetch(payload: IFilter = {} as IFilter) { | ||
let q = payload | ||
if (Object.keys(payload).length < 1) { | ||
q = this.filter | ||
} else { | ||
this.filter = q | ||
} | ||
const query = new URLSearchParams(q as Record<string, string>).toString() | ||
return http.get(`jobs/?${query}`).then((res) => { | ||
if (res.status == 200) { | ||
this.reports = res.data | ||
} else { | ||
window.$notification.error({ | ||
title: i18n.t("common.error"), | ||
content: i18n.t("report.get.messages.error"), | ||
duration: 5000, | ||
}) | ||
} | ||
}) | ||
}, | ||
}, | ||
}) |
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,4 @@ | ||
[ | ||
{ "label": "CSV", "value": "csv" }, | ||
{ "label": "PDF", "value": "pdf" } | ||
] |
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
Oops, something went wrong.