saltcorn-samba 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +82 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/filemanager-view.js +249 -0
- package/index.js +622 -0
- package/package.json +56 -0
- package/pdf-view.js +163 -0
- package/public/samba-filemanager.js +736 -0
- package/public/samba-tree.js +292 -0
- package/public/samba.css +69 -0
- package/smb-client.js +279 -0
- package/tree-view.js +212 -0
package/pdf-view.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fieldview: `samba_pdf` – for String fields that store a path (relative to
|
|
3
|
+
* the plugin base_path) to a file on the Samba share. Renders one of:
|
|
4
|
+
*
|
|
5
|
+
* - inline PDF viewer (<iframe>) for .pdf
|
|
6
|
+
* - inline <img> for images
|
|
7
|
+
* - a download / "open in external app" pair of buttons for everything else
|
|
8
|
+
*
|
|
9
|
+
* The rendered HTML is self-contained; no external JavaScript needed for the
|
|
10
|
+
* fieldview itself.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
div,
|
|
15
|
+
a,
|
|
16
|
+
iframe,
|
|
17
|
+
img,
|
|
18
|
+
i,
|
|
19
|
+
span,
|
|
20
|
+
button,
|
|
21
|
+
} = require("@saltcorn/markup/tags");
|
|
22
|
+
const { text } = require("@saltcorn/markup");
|
|
23
|
+
|
|
24
|
+
/** Extract the file extension in lowercase, without the dot. */
|
|
25
|
+
function extOf(name) {
|
|
26
|
+
const s = String(name || "");
|
|
27
|
+
const dot = s.lastIndexOf(".");
|
|
28
|
+
return dot >= 0 ? s.slice(dot + 1).toLowerCase() : "";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isPdf(name) {
|
|
32
|
+
return extOf(name) === "pdf";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function isImage(name) {
|
|
36
|
+
return ["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp"].includes(extOf(name));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Build a download URL served by the plugin route (defined in index.js).
|
|
41
|
+
* `disposition` is "inline" or "attachment".
|
|
42
|
+
*/
|
|
43
|
+
function fileUrl(value, disposition = "inline") {
|
|
44
|
+
const q = new URLSearchParams({
|
|
45
|
+
path: value || "",
|
|
46
|
+
disposition,
|
|
47
|
+
}).toString();
|
|
48
|
+
return `/sambafile?${q}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** smb:// link for external file managers (Nemo, Nautilus, Explorer). */
|
|
52
|
+
function smbUrl(value) {
|
|
53
|
+
return `/sambalink?path=${encodeURIComponent(value || "")}`;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Fieldview definition
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
const samba_pdf = {
|
|
61
|
+
isEdit: false,
|
|
62
|
+
description:
|
|
63
|
+
"Show a file stored on the Samba share. PDFs are embedded inline; other files get open/download buttons.",
|
|
64
|
+
configFields: () => [
|
|
65
|
+
{
|
|
66
|
+
name: "height",
|
|
67
|
+
label: "Viewer height (px)",
|
|
68
|
+
type: "Integer",
|
|
69
|
+
default: 700,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: "show_download",
|
|
73
|
+
label: "Show download button",
|
|
74
|
+
type: "Bool",
|
|
75
|
+
default: true,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "show_external",
|
|
79
|
+
label: "Show 'Open in file manager' button (smb://)",
|
|
80
|
+
type: "Bool",
|
|
81
|
+
default: true,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "force_download_only",
|
|
85
|
+
label: "Never embed – always show buttons",
|
|
86
|
+
type: "Bool",
|
|
87
|
+
default: false,
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
run: (value, req, options = {}) => {
|
|
91
|
+
if (!value) return span({ class: "text-muted" }, "—");
|
|
92
|
+
const safeVal = text(String(value));
|
|
93
|
+
const height = Number(options.height) > 0 ? Number(options.height) : 700;
|
|
94
|
+
|
|
95
|
+
const buttons = [];
|
|
96
|
+
if (options.show_download !== false) {
|
|
97
|
+
buttons.push(
|
|
98
|
+
a(
|
|
99
|
+
{
|
|
100
|
+
href: fileUrl(safeVal, "attachment"),
|
|
101
|
+
class: "btn btn-sm btn-outline-secondary me-2",
|
|
102
|
+
},
|
|
103
|
+
i({ class: "fas fa-download me-1" }),
|
|
104
|
+
"Download"
|
|
105
|
+
)
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (options.show_external !== false) {
|
|
109
|
+
buttons.push(
|
|
110
|
+
a(
|
|
111
|
+
{
|
|
112
|
+
href: smbUrl(safeVal),
|
|
113
|
+
class: "btn btn-sm btn-outline-primary me-2",
|
|
114
|
+
title: "Open in Nemo/Nautilus/Explorer",
|
|
115
|
+
},
|
|
116
|
+
i({ class: "fas fa-external-link-alt me-1" }),
|
|
117
|
+
"Open in file manager"
|
|
118
|
+
)
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
buttons.push(
|
|
122
|
+
a(
|
|
123
|
+
{
|
|
124
|
+
href: fileUrl(safeVal, "inline"),
|
|
125
|
+
target: "_blank",
|
|
126
|
+
class: "btn btn-sm btn-outline-secondary",
|
|
127
|
+
},
|
|
128
|
+
i({ class: "fas fa-eye me-1" }),
|
|
129
|
+
"Open in new tab"
|
|
130
|
+
)
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
let body;
|
|
134
|
+
if (options.force_download_only) {
|
|
135
|
+
body = "";
|
|
136
|
+
} else if (isPdf(safeVal)) {
|
|
137
|
+
body = iframe({
|
|
138
|
+
src: fileUrl(safeVal, "inline"),
|
|
139
|
+
style: `width:100%;height:${height}px;border:1px solid #dee2e6;border-radius:4px;`,
|
|
140
|
+
});
|
|
141
|
+
} else if (isImage(safeVal)) {
|
|
142
|
+
body = img({
|
|
143
|
+
src: fileUrl(safeVal, "inline"),
|
|
144
|
+
style: `max-width:100%;max-height:${height}px;border:1px solid #dee2e6;border-radius:4px;`,
|
|
145
|
+
alt: safeVal,
|
|
146
|
+
});
|
|
147
|
+
} else {
|
|
148
|
+
body = div(
|
|
149
|
+
{ class: "text-muted small mb-2" },
|
|
150
|
+
i({ class: "fas fa-file me-1" }),
|
|
151
|
+
safeVal
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return div(
|
|
156
|
+
{ class: "samba-pdf-fieldview" },
|
|
157
|
+
div({ class: "samba-pdf-buttons mb-2" }, ...buttons),
|
|
158
|
+
body
|
|
159
|
+
);
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
module.exports = { samba_pdf };
|