Skip to content

Dev #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Oct 7, 2024
Merged

Dev #46

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pypi-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: "setup python"
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.12"

- name: "install wheel"
run: "python -m pip install --user wheel"
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
## CHANGELOG

### [24.10.0] - In Development
- Rewrote how Drop and Paste is handled - we now support dropping or pasting images and they are converted to Markdown Data URIs - however, there is a performance issue with large images - this won't get fixed until I migrate to CodeMirror 6
- Updated `/logs` so it can scroll back through the history
- Increased the size of the `logring` from 128 to 1024
- Updated Dockerfile so it sets `VIRTUAL_ENV` and `PATH` correctly
- Updated Dockerfile to use Python 3.13
- Updated DataTemplate Export so it wraps long lines
- Updated Pandoc to 3.5 in Dockerfile

### [24.9.0] - Sep 2, 2024
- Removed 'Fira Code' font from `/logs` as it adds no value over 'Consolas'
- Updated `codemirror` JavaScript library to 5.65.17
Expand Down Expand Up @@ -329,6 +338,7 @@
### 21.11.0 - Nov 29, 2021
- Initial release

[24.10.0]: https://github.com/cmason3/jinjafx_server/compare/24.9.0...24.10.0
[24.9.0]: https://github.com/cmason3/jinjafx_server/compare/24.6.4...24.9.0
[24.6.4]: https://github.com/cmason3/jinjafx_server/compare/24.6.3...24.6.4
[24.6.3]: https://github.com/cmason3/jinjafx_server/compare/24.6.2...24.6.3
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ JinjaFx Server supports the ability to use "output" tags to create different out
</output>
```

You can also paste in an image and it will convert it to a Base64 encoded Data URI that is formatted as Markdown.

### Ansible Vault

JinjaFx Server supports the ability to perform Ansible Vault encryption of strings from within the browser using client side JavaScript. By clicking on the padlock it will prompt you for your string and the password to use which you can then use within `vars.yml`. JinjaFx doesn't support the ability to use different passwords for different strings within the same DataTemplate so it is important that all vaulted strings are using the same password within the same DataTemplate.
Expand Down
35 changes: 0 additions & 35 deletions contrib/bootstrap.scss

This file was deleted.

6 changes: 3 additions & 3 deletions jinjafx_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import re, argparse, hashlib, traceback, glob, hmac, uuid, struct, binascii, gzip, requests, ctypes, subprocess
import cmarkgfm, emoji

__version__ = '24.9.0'
__version__ = '24.10.0'

llock = threading.RLock()
rlock = threading.RLock()
Expand Down Expand Up @@ -601,7 +601,7 @@ def html_escape(text):
try:
if not self.ratelimit(remote_addr, 4, False):
html = self.d(json.loads(postdata.decode('utf-8')))
p = subprocess.run([pandoc, '-f', 'html', '-t', 'docx', '--sandbox', '--reference-doc=' + base + '/pandoc/reference.docx'], input=html, stdout=subprocess.PIPE, check=True)
p = subprocess.run([pandoc, '-f', 'html', '-t', 'docx', '--sandbox', '--standalone', '--embed-resources', '--reference-doc=' + base + '/pandoc/reference.docx'], input=html, stdout=subprocess.PIPE, check=True)
self.send_response(200)
self.send_header('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
self.send_header('Content-Length', str(len(p.stdout)))
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def log(t, ae=''):
print('[' + timestamp + '] ' + t + ae)

logring.append('[' + timestamp + '] ' + t + ae)
logring = logring[-128:]
logring = logring[-1024:]

if logfile is not None:
try:
Expand Down
15 changes: 9 additions & 6 deletions kubernetes/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
FROM docker.io/library/python:3.12-slim AS BUILD
FROM docker.io/library/python:3.13-slim AS BUILD

ARG BRANCH="main"
ARG BRANCH main

RUN set -eux; \

apt-get update; \
apt-get install -y --no-install-recommends wget git build-essential; \

wget -P /tmp https://github.com/jgm/pandoc/releases/download/3.3/pandoc-3.3-1-amd64.deb; \
dpkg -i /tmp/pandoc-3.3-1-amd64.deb; \
wget -P /tmp https://github.com/jgm/pandoc/releases/download/3.5/pandoc-3.5-1-amd64.deb; \
dpkg -i /tmp/pandoc-3.5-1-amd64.deb; \

python3 -m venv /opt/jinjafx; \
/opt/jinjafx/bin/python3 -m pip install --upgrade git+https://github.com/cmason3/jinjafx_server.git@${BRANCH} lxml; \
/opt/jinjafx/bin/python3 -m pip uninstall -y pip


FROM docker.io/library/python:3.12-slim
FROM docker.io/library/python:3.13-slim

COPY --from=BUILD /opt/jinjafx /opt/jinjafx
COPY --from=BUILD /usr/bin/pandoc /usr/bin/pandoc

ENTRYPOINT [ "/opt/jinjafx/bin/python3", "-u", "-m", "jinjafx_server", "-s", "-l", "0.0.0.0", "-p", "8080" ]
ENV VIRTUAL_ENV /opt/jinjafx
ENV PATH /opt/jinjafx/bin:${PATH}

ENTRYPOINT [ "python3", "-u", "-m", "jinjafx_server", "-s", "-l", "0.0.0.0", "-p", "8080" ]
3 changes: 2 additions & 1 deletion www/dt.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
<link rel="shortcut icon" href="/874f2915/jinjafx.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css" integrity="sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg==" crossorigin="anonymous" referrerpolicy="no-referrer">
<link rel="stylesheet" href="/f8555653/jinjafx.css">
<link rel="stylesheet" href="/6bf86b6e/jinjafx_dt.css">
<script src="/00abd23c/jinjafx_dt.js"></script>
</head>
<body>
<div id="wrap" class="p-2 bg-transparent">
<div id="wrap" class="p-3 bg-transparent">
<button id="saveas" class="btn btn-secondary text-white float-end me-3 mt-3 d-none" type="button" title="Save DataTemplate As">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" />
Expand Down
2 changes: 1 addition & 1 deletion www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js" integrity="sha512-CSBhVREyzHAjAFfBlIBakjoRUKp5h7VSweP0InR/pAJyptH7peuhCsqAI/snV+TwZmXZqoUklpXp6R6wMnYf5Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/dayjs.min.js" integrity="sha512-FwNWaxyfy2XlEINoSnZh1JQ5TRRtGow0D6XcmAWmYCRgvqOUTnzCxPc9uF35u5ZEpirk1uhlPVA19tflhvnW1g==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/plugin/relativeTime.min.js" integrity="sha512-MVzDPmm7QZ8PhEiqJXKz/zw2HJuv61waxb8XXuZMMs9b+an3LoqOqhOEt5Nq3LY1e4Ipbbd/e+AWgERdHlVgaA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="/35550d85/jinjafx_m.js"></script>
<script src="/1d7a4cee/jinjafx_m.js"></script>
</head>
<body>
<div id="overlay"></div>
Expand Down
6 changes: 6 additions & 0 deletions www/jinjafx_dt.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pre {
height: 100%;
white-space: pre-wrap;
word-break: break-all;
display: inline;
}
10 changes: 7 additions & 3 deletions www/logs.css → www/jinjafx_logs.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ body {
}
pre {
height: 100%;
font-family: Consolas, monaco, monospace;
font-size: 14px;
font-variant-ligatures: none;
white-space: pre-wrap;
word-break: break-all;
overflow-y: hidden;
overflow-y: scroll;
scrollbar-width: none;
-ms-overflow-style: none;
}
pre::-webkit-scrollbar {
width: 0;
height: 0;
}
File renamed without changes.
65 changes: 54 additions & 11 deletions www/jinjafx_m.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ function getStatusText(code) {
document.getElementById('get2').onclick = function() { jinjafx('get_link'); };
document.getElementById('update').onclick = function() { jinjafx('update_link'); };
document.getElementById('protect').onclick = function() { jinjafx('protect'); };

if (window.crypto.subtle) {
document.getElementById('encrypt').classList.remove('d-none');
}
Expand Down Expand Up @@ -1108,11 +1108,16 @@ function getStatusText(code) {
csv_on = false;
};

window.cmData.on("beforeChange", onPaste);
window.cmTemplate.on("beforeChange", onPaste);
window.cmVars.on("beforeChange", onPaste);
window.cmgVars.on("beforeChange", onPaste);

window.cmData.on("paste", onPaste);
window.cmVars.on("paste", onPaste);
window.cmgVars.on("paste", onPaste);
window.cmTemplate.on("paste", onPaste);

window.cmData.on("drop", onDrop);
window.cmVars.on("drop", onDrop);
window.cmgVars.on("drop", onDrop);
window.cmTemplate.on("drop", onDrop);

window.cmData.on("change", onChange);
window.cmVars.on("change", onChange);
window.cmgVars.on("change", onChange);
Expand Down Expand Up @@ -1703,14 +1708,11 @@ function getStatusText(code) {
document.getElementById('protect').innerHTML = 'Protect Link';
}

function onPaste(cm, change) {
if (change.origin === "paste") {
var t = change.text.join('\n');

function onPasteOrDrop(e, obj, target) {
var process_text = function(t) {
if (t.replace(/\r/g, '').indexOf('---\ndt:\n') > -1) {
var obj = jsyaml.load(t, jsyaml_schema);
if (obj != null) {
change.cancel();
pending_dt = obj['dt'];

if (dirty) {
Expand All @@ -1723,7 +1725,48 @@ function getStatusText(code) {
}
}
}
else {
target.getDoc().replaceSelection(t);
}
};

e.preventDefault();

var t = obj.getData("text");
if (t.length) {
process_text(t);
}
else {
for (var i in obj.items) {
if ((typeof obj.items[i].type !== 'undefined') && (obj.items[i].type.indexOf("image") === 0)) {
var b = obj.items[i].getAsFile();
var r = new FileReader();
r.onload = function(e) {
var x = '![](' + e.target.result + ')';
target.getDoc().replaceSelection(x);
};
r.readAsDataURL(b);
return;
}
}

var b = obj.items[0].getAsFile();
var r = new FileReader();
r.onload = function(e) {
process_text(e.target.result);
};
r.readAsText(b);
}
}

function onDrop(cm, e) {
var dataTransfer = (e.originalEvent || e).dataTransfer;
onPasteOrDrop(e, dataTransfer, cm);
}

function onPaste(cm, e) {
var clipboardData = (e.originalEvent || e).clipboardData;
onPasteOrDrop(e, clipboardData, cm);
}

function onBeforeUnload(e) {
Expand Down
4 changes: 2 additions & 2 deletions www/logs.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<link rel="shortcut icon" href="/874f2915/jinjafx.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css" integrity="sha512-jnSuA4Ss2PkkikSOLtYs8BlYIeeIK1h99ty4YfvRPAlzr377vr3CXDb7sb7eEEBYjDtcYj+AjBH3FLv5uSJuXg==" crossorigin="anonymous" referrerpolicy="no-referrer">
<link rel="stylesheet" href="/f8555653/jinjafx.css">
<link rel="stylesheet" href="/13677283/logs.css">
<script src="/4f5b7922/logs.js"></script>
<link rel="stylesheet" href="/28fdf760/jinjafx_logs.css">
<script src="/4f5b7922/jinjafx_logs.js"></script>
</head>
<body>
<pre id="container" class="p-3"></pre>
Expand Down