add download cache file on jobs

This commit is contained in:
Jordan Blasenhauer 2024-06-18 17:54:32 +02:00
parent 2b92aca4b9
commit 2dde36befa
5 changed files with 90 additions and 67 deletions

View file

@ -1,5 +1,6 @@
<script setup>
import { v4 as uuidv4 } from "uuid";
import { defineProps, reactive } from "vue";
/**
@name Icons/Trespass.vue
@description This component is a svg icon representing no trespassing.

View file

@ -198,5 +198,5 @@
"jobs_table_reload" : "Reload",
"jobs_table_success" : "Success",
"jobs_table_last_run_date" : "Last run date",
"jobs_table_cache" : "Cache"
"jobs_table_cache_downloadable" : "Cache (downloadable)"
}

View file

@ -1,7 +1,6 @@
<script setup>
import { reactive, onBeforeMount, onMounted } from "vue";
import { useGlobal } from "@utils/global.js";
import { useForm } from "@utils/form.js";
import DashboardLayout from "@components/Dashboard/Layout.vue";
import BuilderJobs from "@components/Builder/Jobs.vue";
@ -26,9 +25,42 @@ onBeforeMount(() => {
services.builder = data;
});
function getLastArrItem(startStr, endStr, array) {
return array[array.length - 1].startsWith(startStr) &&
array[array.length - 1].endsWith(endStr)
? array.pop().replace(startStr, "").replace(endStr, "").trim()
: null;
}
function downloadCacheEvent() {
window.addEventListener(
"click",
(e) => {
// Case not wanted element
if (!e.target.hasAttribute("data-select-item")) return;
if (!e.target.closest("[data-table-body]")) return;
const value = e.target.getAttribute("data-setting-value");
// Get needed values to download the cache file
const values = value.split(" ");
// In case the last element start with "[" and end with "]", this is the serviceId
const serviceId = getLastArrItem("[", "]", values);
// In case the last element start with "(" and end with ")", this is the pluginId
const pluginId = getLastArrItem("(", ")", values);
// Merge the rest of the values and trim, this is the file name
const fileName = values.join(" ").trim();
window.open(
`${location.href}/download?plugin_id=${pluginId}&job_name=${serviceId}&file_name=${fileName}`
);
},
true
);
}
onMounted(() => {
useGlobal();
useForm();
downloadCacheEvent();
});
// const builder = [
@ -78,7 +110,7 @@ const builder = [
"jobs_table_reload",
"jobs_table_success",
"jobs_table_last_run_date",
"jobs_table_cache",
"jobs_table_cache_downloadable",
],
positions: [2, 2, 1, 1, 1, 2, 3],
items: [
@ -605,7 +637,8 @@ const builder = [
},
},
{
cache: "none default-server-cert.pem default-server-cert.key",
cache:
"default-server-cert.pem (misc) default-server-cert.key (misc)",
type: "Fields",
data: {
setting: {
@ -614,16 +647,10 @@ const builder = [
hideLabel: true,
inpType: "select",
name: "default-server-cert_cache",
value: "none",
value: "download",
values: [
"none",
"default-server-cert.pem",
"default-server-cert.key",
"default-server-cert.key",
"default-server-cert.key",
"default-server-cert.key",
"default-server-cert.key",
"default-server-cert.key",
"default-server-cert.pem (misc)",
"default-server-cert.key (misc)",
],
columns: {
pc: 12,
@ -631,7 +658,7 @@ const builder = [
mobile: 12,
},
overflowAttrEl: "data-table-body",
containerClass: "table",
containerClass: "table download-cache-file",
maxBtnChars: 12,
popovers: [
{
@ -796,7 +823,7 @@ const builder = [
},
},
{
cache: "none folder:/var/tmp/bunkerweb/failover.tgz",
cache: "folder:/var/tmp/bunkerweb/failover.tgz (jobs)",
type: "Fields",
data: {
setting: {
@ -805,15 +832,15 @@ const builder = [
hideLabel: true,
inpType: "select",
name: "failover-backup_cache",
value: "none",
values: ["none", "folder:/var/tmp/bunkerweb/failover.tgz"],
value: "download",
values: ["folder:/var/tmp/bunkerweb/failover.tgz (jobs)"],
columns: {
pc: 12,
tablet: 12,
mobile: 12,
},
overflowAttrEl: "data-table-body",
containerClass: "table",
containerClass: "table download-cache-file",
maxBtnChars: 12,
popovers: [
{
@ -925,7 +952,7 @@ const builder = [
},
},
{
cache: "none asn.mmdb",
cache: "asn.mmdb (jobs)",
type: "Fields",
data: {
setting: {
@ -934,15 +961,15 @@ const builder = [
hideLabel: true,
inpType: "select",
name: "mmdb-asn_cache",
value: "none",
values: ["none", "asn.mmdb"],
value: "download",
values: ["asn.mmdb (jobs)"],
columns: {
pc: 12,
tablet: 12,
mobile: 12,
},
overflowAttrEl: "data-table-body",
containerClass: "table",
containerClass: "table download-cache-file",
maxBtnChars: 12,
popovers: [
{
@ -1001,7 +1028,7 @@ const builder = [
},
},
{
cache: "none country.mmdb",
cache: "country.mmdb (jobs)",
type: "Fields",
data: {
setting: {
@ -1010,15 +1037,15 @@ const builder = [
hideLabel: true,
inpType: "select",
name: "mmdb-country_cache",
value: "none",
values: ["none", "country.mmdb"],
value: "download",
values: ["country.mmdb (jobs)"],
columns: {
pc: 12,
tablet: 12,
mobile: 12,
},
overflowAttrEl: "data-table-body",
containerClass: "table",
containerClass: "table download-cache-file",
maxBtnChars: 12,
popovers: [
{
@ -1130,7 +1157,8 @@ const builder = [
},
},
{
cache: "none www.example.com/cert.pem www.example.com/key.pem",
cache:
"cert.pem (selfsigned) [www.example.com] key.pem (selfsigned) [www.example.com]",
type: "Fields",
data: {
setting: {
@ -1139,11 +1167,10 @@ const builder = [
hideLabel: true,
inpType: "select",
name: "self-signed_cache",
value: "none",
value: "download",
values: [
"none",
"www.example.com/cert.pem",
"www.example.com/key.pem",
"cert.pem (selfsigned) [www.example.com]",
"key.pem (selfsigned) [www.example.com]",
],
columns: {
pc: 12,
@ -1151,7 +1178,7 @@ const builder = [
mobile: 12,
},
overflowAttrEl: "data-table-body",
containerClass: "table",
containerClass: "table download-cache-file",
maxBtnChars: 12,
popovers: [
{

View file

@ -27,7 +27,7 @@
"jobs_table_reload",
"jobs_table_success",
"jobs_table_last_run_date",
"jobs_table_cache"
"jobs_table_cache_downloadable"
],
"positions": [
2,
@ -562,7 +562,7 @@
}
},
{
"cache": "none default-server-cert.pem default-server-cert.key",
"cache": "default-server-cert.pem (misc) default-server-cert.key (misc)",
"type": "Fields",
"data": {
"setting": {
@ -571,11 +571,10 @@
"hideLabel": true,
"inpType": "select",
"name": "default-server-cert_cache",
"value": "none",
"value": "download",
"values": [
"none",
"default-server-cert.pem",
"default-server-cert.key"
"default-server-cert.pem (misc)",
"default-server-cert.key (misc)"
],
"columns": {
"pc": 12,
@ -583,7 +582,7 @@
"mobile": 12
},
"overflowAttrEl": "data-table-body",
"containerClass": "table",
"containerClass": "table download-cache-file",
"maxBtnChars": 12,
"popovers": [
{
@ -748,7 +747,7 @@
}
},
{
"cache": "none folder:/var/tmp/bunkerweb/failover.tgz",
"cache": "folder:/var/tmp/bunkerweb/failover.tgz (jobs)",
"type": "Fields",
"data": {
"setting": {
@ -757,10 +756,9 @@
"hideLabel": true,
"inpType": "select",
"name": "failover-backup_cache",
"value": "none",
"value": "download",
"values": [
"none",
"folder:/var/tmp/bunkerweb/failover.tgz"
"folder:/var/tmp/bunkerweb/failover.tgz (jobs)"
],
"columns": {
"pc": 12,
@ -768,7 +766,7 @@
"mobile": 12
},
"overflowAttrEl": "data-table-body",
"containerClass": "table",
"containerClass": "table download-cache-file",
"maxBtnChars": 12,
"popovers": [
{
@ -880,7 +878,7 @@
}
},
{
"cache": "none asn.mmdb",
"cache": "asn.mmdb (jobs)",
"type": "Fields",
"data": {
"setting": {
@ -889,10 +887,9 @@
"hideLabel": true,
"inpType": "select",
"name": "mmdb-asn_cache",
"value": "none",
"value": "download",
"values": [
"none",
"asn.mmdb"
"asn.mmdb (jobs)"
],
"columns": {
"pc": 12,
@ -900,7 +897,7 @@
"mobile": 12
},
"overflowAttrEl": "data-table-body",
"containerClass": "table",
"containerClass": "table download-cache-file",
"maxBtnChars": 12,
"popovers": [
{
@ -959,7 +956,7 @@
}
},
{
"cache": "none country.mmdb",
"cache": "country.mmdb (jobs)",
"type": "Fields",
"data": {
"setting": {
@ -968,10 +965,9 @@
"hideLabel": true,
"inpType": "select",
"name": "mmdb-country_cache",
"value": "none",
"value": "download",
"values": [
"none",
"country.mmdb"
"country.mmdb (jobs)"
],
"columns": {
"pc": 12,
@ -979,7 +975,7 @@
"mobile": 12
},
"overflowAttrEl": "data-table-body",
"containerClass": "table",
"containerClass": "table download-cache-file",
"maxBtnChars": 12,
"popovers": [
{
@ -1091,7 +1087,7 @@
}
},
{
"cache": "none www.example.com/cert.pem www.example.com/key.pem",
"cache": "cert.pem (selfsigned) [www.example.com] key.pem (selfsigned) [www.example.com]",
"type": "Fields",
"data": {
"setting": {
@ -1100,11 +1096,10 @@
"hideLabel": true,
"inpType": "select",
"name": "self-signed_cache",
"value": "none",
"value": "download",
"values": [
"none",
"www.example.com/cert.pem",
"www.example.com/key.pem"
"cert.pem (selfsigned) [www.example.com]",
"key.pem (selfsigned) [www.example.com]"
],
"columns": {
"pc": 12,
@ -1112,7 +1107,7 @@
"mobile": 12
},
"overflowAttrEl": "data-table-body",
"containerClass": "table",
"containerClass": "table download-cache-file",
"maxBtnChars": 12,
"popovers": [
{

View file

@ -236,13 +236,13 @@ def get_jobs_list(jobs):
continue
if k in ("cache") and len(v) > 0:
files = ["none"]
files = []
# loop on each cache item
for cache in v:
file_name = (
f"{cache['service_id']}/{cache['file_name']}"
f"{cache['file_name']} ({value['plugin_id']}) [{cache['service_id']}]"
if cache["service_id"]
else cache["file_name"]
else f"{cache['file_name']} ({value['plugin_id']})"
)
files.append(file_name)
@ -257,7 +257,7 @@ def get_jobs_list(jobs):
"hideLabel": True,
"inpType": "select",
"name": f"{key}_cache",
"value": "none",
"value": "download file",
"values": files,
"columns": {
"pc": 12,
@ -265,7 +265,7 @@ def get_jobs_list(jobs):
"mobile": 12,
},
"overflowAttrEl": "data-table-body",
"containerClass": "table",
"containerClass": "table download-cache-file",
"maxBtnChars": 12,
"popovers": [
{
@ -320,7 +320,7 @@ def job_builder(jobs):
"jobs_table_reload",
"jobs_table_success",
"jobs_table_last_run_date",
"jobs_table_cache",
"jobs_table_cache_downloadable",
],
"positions": [2, 2, 1, 1, 1, 2, 3],
"items": jobs_list,