mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Merge branch 'dev' of github.com:bunkerity/bunkerweb into dev
This commit is contained in:
commit
d20afaeb2a
5 changed files with 63 additions and 32 deletions
|
|
@ -52,6 +52,7 @@ from src.User import AnonymousUser, User
|
|||
|
||||
from utils import check_settings, get_b64encoded_qr_image, path_to_dict, get_remain
|
||||
from Database import Database # type: ignore
|
||||
from logger import setup_logger # type: ignore
|
||||
from logging import getLogger
|
||||
|
||||
|
||||
|
|
@ -87,9 +88,14 @@ app.config["SECRET_KEY"] = getenv("FLASK_SECRET", urandom(32))
|
|||
|
||||
PROXY_NUMBERS = int(getenv("PROXY_NUMBERS", "1"))
|
||||
app.wsgi_app = ReverseProxied(app.wsgi_app, x_for=PROXY_NUMBERS, x_proto=PROXY_NUMBERS, x_host=PROXY_NUMBERS, x_prefix=PROXY_NUMBERS)
|
||||
app.logger = setup_logger("UI")
|
||||
|
||||
gunicorn_access_logger = getLogger("gunicorn.access")
|
||||
gunicorn_access_logger.setLevel(app.logger.level)
|
||||
gunicorn_logger = getLogger("gunicorn.error")
|
||||
app.logger = gunicorn_logger
|
||||
app.logger.setLevel(gunicorn_logger.level)
|
||||
gunicorn_logger.setLevel(app.logger.level)
|
||||
werkzeug_logger = getLogger("werkzeug")
|
||||
werkzeug_logger.setLevel(app.logger.level)
|
||||
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(app)
|
||||
|
|
@ -2052,34 +2058,20 @@ def jobs():
|
|||
@app.route("/jobs/download", methods=["GET"])
|
||||
@login_required
|
||||
def jobs_download():
|
||||
plugin_id = request.args.get("plugin_id", "")
|
||||
job_name = request.args.get("job_name", None)
|
||||
file_name = request.args.get("file_name", None)
|
||||
service_id = request.args.get("service_id", "")
|
||||
|
||||
if not job_name or not file_name:
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"status": "ko",
|
||||
"message": "job_name and file_name are required",
|
||||
}
|
||||
),
|
||||
422,
|
||||
)
|
||||
if not plugin_id or not job_name or not file_name:
|
||||
return jsonify({"status": "ko", "message": "plugin_id, job_name and file_name are required"}), 422
|
||||
|
||||
cache_file = db.get_job_cache_file(job_name, file_name)
|
||||
cache_file = db.get_job_cache_file(job_name, file_name, service_id=service_id, plugin_id=plugin_id)
|
||||
|
||||
if not cache_file:
|
||||
return (
|
||||
jsonify(
|
||||
{
|
||||
"status": "ko",
|
||||
"message": "file not found",
|
||||
}
|
||||
),
|
||||
404,
|
||||
)
|
||||
return jsonify({"status": "ko", "message": "file not found"}), 404
|
||||
|
||||
file = BytesIO(cache_file.data)
|
||||
file = BytesIO(cache_file)
|
||||
return send_file(file, as_attachment=True, download_name=file_name)
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -20,21 +20,59 @@ class Download {
|
|||
.closest("button")
|
||||
.hasAttribute(`data-${this.prefix}-download`)
|
||||
) {
|
||||
const dataValue = e.target
|
||||
.closest('div:has(span[data-cache-content=""])')
|
||||
.firstElementChild.getAttribute("data-value");
|
||||
const btnEl = e.target.closest("button");
|
||||
const jobName = btnEl.getAttribute("data-cache-download");
|
||||
const fileName = btnEl.getAttribute("data-cache-file");
|
||||
this.sendFileToDL(jobName, fileName);
|
||||
const jobName = btnEl.getAttribute(`data-${this.prefix}-job`);
|
||||
const fileName = btnEl.getAttribute(`data-${this.prefix}-download`);
|
||||
const pluginId = document
|
||||
.querySelector('[data-level="1"]')
|
||||
.getAttribute("data-name");
|
||||
var serviceId = null;
|
||||
if (
|
||||
document.querySelector(
|
||||
'[data-level="2"][data-cache-breadcrumb-item=""]:not(.hidden)',
|
||||
)
|
||||
) {
|
||||
serviceId = document
|
||||
.querySelector('[data-level="2"]')
|
||||
.getAttribute("data-name");
|
||||
}
|
||||
|
||||
if (dataValue !== "Download file to view content") {
|
||||
this.download(fileName, dataValue);
|
||||
} else {
|
||||
this.sendFileToDL(pluginId, jobName, fileName, serviceId);
|
||||
}
|
||||
}
|
||||
} catch (err) {}
|
||||
});
|
||||
}
|
||||
|
||||
async sendFileToDL(jobName, fileName) {
|
||||
download(filename, text) {
|
||||
var element = document.createElement("a");
|
||||
element.setAttribute(
|
||||
"href",
|
||||
"data:text/plain;charset=utf-8," + encodeURIComponent(text),
|
||||
);
|
||||
element.setAttribute("download", filename);
|
||||
|
||||
element.style.display = "none";
|
||||
document.body.appendChild(element);
|
||||
|
||||
element.click();
|
||||
|
||||
document.body.removeChild(element);
|
||||
}
|
||||
|
||||
async sendFileToDL(pluginId, jobName, fileName, serviceId) {
|
||||
window.open(
|
||||
`${location.href.replace(
|
||||
"cache",
|
||||
"jobs",
|
||||
)}/download?job_name=${jobName}&file_name=${fileName}`,
|
||||
)}/download?plugin_id=${pluginId}&job_name=${jobName}&file_name=${fileName}` +
|
||||
(serviceId ? `&service_id=${serviceId}` : ""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
6
src/ui/templates/file_manager.html
vendored
6
src/ui/templates/file_manager.html
vendored
|
|
@ -161,7 +161,7 @@
|
|||
<!-- download button -->
|
||||
{% if child['type'] == "file" and child['can_download'] == True %}
|
||||
{% if current_endpoint == "cache" %}
|
||||
<button role="tab" value="download" data-{{ current_endpoint }}-download="{{ child['name'].split("/")[0] }}" data-{{ current_endpoint }}-file="{{ child['name'].split("/")[1] }}" data-{{ current_endpoint }}-setting-select-dropdown-btn="{{ child['name'].split("/")[0] }}" class="duration-300 border-gray-300 hover:brightness-90 bg-white text-white my-0 relative px-6 py-2 text-center align-middle transition-all rounded-none cursor-pointer leading-normal text-sm ease-in tracking-tight-rem dark:border-slate-600 dark:bg-slate-700 dark:text-gray-300 w-full border-b border-l border-r hover:bg-gray-100">
|
||||
<button role="tab" value="download" data-{{ current_endpoint }}-download="{{ child['name'] }}" data-{{ current_endpoint }}-job="{{ child['job_name'] }}" class="duration-300 border-gray-300 hover:brightness-90 bg-white text-white my-0 relative px-6 py-2 text-center align-middle transition-all rounded-none cursor-pointer leading-normal text-sm ease-in tracking-tight-rem dark:border-slate-600 dark:bg-slate-700 dark:text-gray-300 w-full border-b border-l border-r hover:bg-gray-100">
|
||||
<span class="flex justify-start items-center">
|
||||
<svg class="h-5.5 w-5.5 stroke-sky-500"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
|
|
@ -242,7 +242,7 @@
|
|||
<!-- end main container -->
|
||||
<!-- modal -->
|
||||
<div data-{{ current_endpoint }}-modal class="hidden w-full h-screen fixed bg-gray-600/50 z-[1001] top-0 left-0 justify-center items-center">
|
||||
<div class="mx-1 px-4 py-3 w-full max-w-180 flex flex-col break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border">
|
||||
<div class="mx-1 px-4 py-3 w-full max-w-screen-lg flex flex-col break-words bg-white shadow-xl dark:bg-slate-850 dark:shadow-dark-xl rounded-2xl bg-clip-border">
|
||||
<div class="w-full flex justify-between">
|
||||
<p data-{{ current_endpoint }}-modal-title class="dark:text-white mb-0 font-sans font-semibold leading-normal uppercase text-sm">
|
||||
TITLE
|
||||
|
|
@ -269,7 +269,7 @@
|
|||
<input type="hidden" id="_type" value="file" name="type" />
|
||||
<textarea class="hidden" id="content" name="content"></textarea>
|
||||
<!-- editor-->
|
||||
<div data-{{ current_endpoint }}-modal-editor id="editor" class="text-base w-full h-48 overflow-hidden overflow-y-auto my-2 border border-gray-300 dark:border-slate-800">
|
||||
<div data-{{ current_endpoint }}-modal-editor id="editor" class="text-base w-full h-96 overflow-hidden overflow-y-auto my-2 border border-gray-300 dark:border-slate-800">
|
||||
</div>
|
||||
<!-- editor-->
|
||||
<div class="mt-4 w-full justify-end flex">
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ def path_to_dict(
|
|||
|
||||
file_info = {
|
||||
"name": conf["file_name"],
|
||||
"job_name": conf["job_name"],
|
||||
"type": "file",
|
||||
"path": join(
|
||||
path,
|
||||
|
|
|
|||
Loading…
Reference in a new issue