we can send now?
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simple_Not 2023-07-20 01:24:15 +10:00
parent 8d98c04fa3
commit 5938f4e063
4 changed files with 136 additions and 37 deletions

31
app.py
View File

@ -5,8 +5,10 @@ from todo import todos
from threads import threads_lists from threads import threads_lists
from threads_with_posts import open_threads from threads_with_posts import open_threads
from arango import ArangoClient from arango import ArangoClient
from minio import minioClient
import socket, os
import socket
app = Flask(__name__) app = Flask(__name__)
@ -176,6 +178,33 @@ def post_to_post(post_key):
# def post_a_file(): # def post_a_file():
# pass # pass
@app.route("/send_dudes", methods=["POST"])
def upload_file():
if request.method == "POST":
uploaded_file = request.files["file"]
if uploaded_file:
bucket_name = "thread-pics"
size = os.fstat(uploaded_file.fileno()).st_size
minioClient.put_object(
bucket_name, uploaded_file.filename, uploaded_file, size
)
return """
<h1>stored</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
"""
return """
<h1>Upload IPS File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
"""

View File

@ -1,3 +1,4 @@
flask flask
flask-assets flask-assets
python-arango python-arango
minio

View File

@ -44,6 +44,7 @@ return (function () {
defineExtension : defineExtension, defineExtension : defineExtension,
removeExtension : removeExtension, removeExtension : removeExtension,
logAll : logAll, logAll : logAll,
logNone : logNone,
logger : null, logger : null,
config : { config : {
historyEnabled:true, historyEnabled:true,
@ -71,6 +72,7 @@ return (function () {
defaultFocusScroll: false, defaultFocusScroll: false,
getCacheBusterParam: false, getCacheBusterParam: false,
globalViewTransitions: false, globalViewTransitions: false,
methodsThatUseUrlParams: ["get"],
}, },
parseInterval:parseInterval, parseInterval:parseInterval,
_:internalEval, _:internalEval,
@ -82,7 +84,7 @@ return (function () {
sock.binaryType = htmx.config.wsBinaryType; sock.binaryType = htmx.config.wsBinaryType;
return sock; return sock;
}, },
version: "1.9.2" version: "1.9.3"
}; };
/** @type {import("./htmx").HtmxInternalApi} */ /** @type {import("./htmx").HtmxInternalApi} */
@ -90,9 +92,11 @@ return (function () {
addTriggerHandler: addTriggerHandler, addTriggerHandler: addTriggerHandler,
bodyContains: bodyContains, bodyContains: bodyContains,
canAccessLocalStorage: canAccessLocalStorage, canAccessLocalStorage: canAccessLocalStorage,
findThisElement: findThisElement,
filterValues: filterValues, filterValues: filterValues,
hasAttribute: hasAttribute, hasAttribute: hasAttribute,
getAttributeValue: getAttributeValue, getAttributeValue: getAttributeValue,
getClosestAttributeValue: getClosestAttributeValue,
getClosestMatch: getClosestMatch, getClosestMatch: getClosestMatch,
getExpressionVars: getExpressionVars, getExpressionVars: getExpressionVars,
getHeaders: getHeaders, getHeaders: getHeaders,
@ -105,6 +109,7 @@ return (function () {
mergeObjects: mergeObjects, mergeObjects: mergeObjects,
makeSettleInfo: makeSettleInfo, makeSettleInfo: makeSettleInfo,
oobSwap: oobSwap, oobSwap: oobSwap,
querySelectorExt: querySelectorExt,
selectAndSwap: selectAndSwap, selectAndSwap: selectAndSwap,
settleImmediately: settleImmediately, settleImmediately: settleImmediately,
shouldCancel: shouldCancel, shouldCancel: shouldCancel,
@ -475,6 +480,10 @@ return (function () {
} }
} }
function logNone() {
htmx.logger = null
}
function find(eltOrSelector, selector) { function find(eltOrSelector, selector) {
if (selector) { if (selector) {
return eltOrSelector.querySelector(selector); return eltOrSelector.querySelector(selector);
@ -902,6 +911,17 @@ return (function () {
return hash; return hash;
} }
function deInitOnHandlers(elt) {
var internalData = getInternalData(elt);
if (internalData.onHandlers) {
for (let i = 0; i < internalData.onHandlers.length; i++) {
const handlerInfo = internalData.onHandlers[i];
elt.removeEventListener(handlerInfo.name, handlerInfo.handler);
}
delete internalData.onHandlers
}
}
function deInitNode(element) { function deInitNode(element) {
var internalData = getInternalData(element); var internalData = getInternalData(element);
if (internalData.timeout) { if (internalData.timeout) {
@ -920,12 +940,7 @@ return (function () {
} }
}); });
} }
if (internalData.onHandlers) { deInitOnHandlers(element);
for (let i = 0; i < internalData.onHandlers.length; i++) {
const handlerInfo = internalData.onHandlers[i];
element.removeEventListener(handlerInfo.name, handlerInfo.handler);
}
}
} }
function cleanUpElement(element) { function cleanUpElement(element) {
@ -950,7 +965,7 @@ return (function () {
newElt = eltBeforeNewContent.nextSibling; newElt = eltBeforeNewContent.nextSibling;
} }
getInternalData(target).replacedWith = newElt; // tuck away so we can fire events on it later getInternalData(target).replacedWith = newElt; // tuck away so we can fire events on it later
settleInfo.elts = [] // clear existing elements settleInfo.elts = settleInfo.elts.filter(e => e != target);
while(newElt && newElt !== target) { while(newElt && newElt !== target) {
if (newElt.nodeType === Node.ELEMENT_NODE) { if (newElt.nodeType === Node.ELEMENT_NODE) {
settleInfo.elts.push(newElt); settleInfo.elts.push(newElt);
@ -995,8 +1010,8 @@ return (function () {
} }
} }
function maybeSelectFromResponse(elt, fragment) { function maybeSelectFromResponse(elt, fragment, selectOverride) {
var selector = getClosestAttributeValue(elt, "hx-select"); var selector = selectOverride || getClosestAttributeValue(elt, "hx-select");
if (selector) { if (selector) {
var newFragment = getDocument().createDocumentFragment(); var newFragment = getDocument().createDocumentFragment();
forEach(fragment.querySelectorAll(selector), function (node) { forEach(fragment.querySelectorAll(selector), function (node) {
@ -1070,12 +1085,12 @@ return (function () {
} }
} }
function selectAndSwap(swapStyle, target, elt, responseText, settleInfo) { function selectAndSwap(swapStyle, target, elt, responseText, settleInfo, selectOverride) {
settleInfo.title = findTitle(responseText); settleInfo.title = findTitle(responseText);
var fragment = makeFragment(responseText); var fragment = makeFragment(responseText);
if (fragment) { if (fragment) {
handleOutOfBandSwaps(elt, fragment, settleInfo); handleOutOfBandSwaps(elt, fragment, settleInfo);
fragment = maybeSelectFromResponse(elt, fragment); fragment = maybeSelectFromResponse(elt, fragment, selectOverride);
handlePreservedElements(fragment); handlePreservedElements(fragment);
return swap(swapStyle, elt, target, fragment, settleInfo); return swap(swapStyle, elt, target, fragment, settleInfo);
} }
@ -1299,7 +1314,10 @@ return (function () {
var nodeData = getInternalData(elt); var nodeData = getInternalData(elt);
nodeData.timeout = setTimeout(function () { nodeData.timeout = setTimeout(function () {
if (bodyContains(elt) && nodeData.cancelled !== true) { if (bodyContains(elt) && nodeData.cancelled !== true) {
if (!maybeFilterEvent(spec, makeEvent('hx:poll:trigger', {triggerSpec:spec, target:elt}))) { if (!maybeFilterEvent(spec, elt, makeEvent('hx:poll:trigger', {
triggerSpec: spec,
target: elt
}))) {
handler(elt); handler(elt);
} }
processPolling(elt, handler, spec); processPolling(elt, handler, spec);
@ -1361,11 +1379,11 @@ return (function () {
return getInternalData(elt).boosted && elt.tagName === "A" && evt.type === "click" && (evt.ctrlKey || evt.metaKey); return getInternalData(elt).boosted && elt.tagName === "A" && evt.type === "click" && (evt.ctrlKey || evt.metaKey);
} }
function maybeFilterEvent(triggerSpec, evt) { function maybeFilterEvent(triggerSpec, elt, evt) {
var eventFilter = triggerSpec.eventFilter; var eventFilter = triggerSpec.eventFilter;
if(eventFilter){ if(eventFilter){
try { try {
return eventFilter(evt) !== true; return eventFilter.call(elt, evt) !== true;
} catch(e) { } catch(e) {
triggerErrorEvent(getDocument().body, "htmx:eventFilter:error", {error: e, source:eventFilter.source}); triggerErrorEvent(getDocument().body, "htmx:eventFilter:error", {error: e, source:eventFilter.source});
return true; return true;
@ -1398,7 +1416,7 @@ return (function () {
if (explicitCancel || shouldCancel(evt, elt)) { if (explicitCancel || shouldCancel(evt, elt)) {
evt.preventDefault(); evt.preventDefault();
} }
if (maybeFilterEvent(triggerSpec, evt)) { if (maybeFilterEvent(triggerSpec, elt, evt)) {
return; return;
} }
var eventData = getInternalData(evt); var eventData = getInternalData(evt);
@ -1650,6 +1668,9 @@ return (function () {
var sseEventSource = getInternalData(sseSourceElt).sseEventSource; var sseEventSource = getInternalData(sseSourceElt).sseEventSource;
var sseListener = function (event) { var sseListener = function (event) {
if (maybeCloseSSESource(sseSourceElt)) { if (maybeCloseSSESource(sseSourceElt)) {
return;
}
if (!bodyContains(elt)) {
sseEventSource.removeEventListener(sseEventName, sseListener); sseEventSource.removeEventListener(sseEventName, sseListener);
return; return;
} }
@ -1666,7 +1687,7 @@ return (function () {
var target = getTarget(elt) var target = getTarget(elt)
var settleInfo = makeSettleInfo(elt); var settleInfo = makeSettleInfo(elt);
selectAndSwap(swapSpec.swapStyle, elt, target, response, settleInfo) selectAndSwap(swapSpec.swapStyle, target, elt, response, settleInfo)
settleImmediately(settleInfo.tasks) settleImmediately(settleInfo.tasks)
triggerEvent(elt, "htmx:sseMessage", event) triggerEvent(elt, "htmx:sseMessage", event)
}; };
@ -1770,7 +1791,7 @@ return (function () {
observer.observe(elt); observer.observe(elt);
addEventListener(elt, handler, nodeData, triggerSpec); addEventListener(elt, handler, nodeData, triggerSpec);
} else if (triggerSpec.trigger === "load") { } else if (triggerSpec.trigger === "load") {
if (!maybeFilterEvent(triggerSpec, makeEvent("load", {elt:elt}))) { if (!maybeFilterEvent(triggerSpec, elt, makeEvent("load", {elt: elt}))) {
loadImmediately(elt, handler, nodeData, triggerSpec.delay); loadImmediately(elt, handler, nodeData, triggerSpec.delay);
} }
} else if (triggerSpec.pollInterval) { } else if (triggerSpec.pollInterval) {
@ -1820,6 +1841,16 @@ return (function () {
return document.querySelector("[hx-boost], [data-hx-boost]"); return document.querySelector("[hx-boost], [data-hx-boost]");
} }
function findHxOnWildcardElements(elt) {
if (!document.evaluate) return []
let node = null
const elements = []
const iter = document.evaluate('//*[@*[ starts-with(name(), "hx-on:") or starts-with(name(), "data-hx-on:") ]]', elt)
while (node = iter.iterateNext()) elements.push(node)
return elements
}
function findElementsToProcess(elt) { function findElementsToProcess(elt) {
if (elt.querySelectorAll) { if (elt.querySelectorAll) {
var boostedElts = hasChanceOfBeingBoosted() ? ", a, form" : ""; var boostedElts = hasChanceOfBeingBoosted() ? ", a, form" : "";
@ -1879,7 +1910,7 @@ return (function () {
function processHxOn(elt) { function processHxOn(elt) {
var hxOnValue = getAttributeValue(elt, 'hx-on'); var hxOnValue = getAttributeValue(elt, 'hx-on');
if (hxOnValue) { if (hxOnValue && htmx.config.allowEval) {
var handlers = {} var handlers = {}
var lines = hxOnValue.split("\n"); var lines = hxOnValue.split("\n");
var currentEvent = null; var currentEvent = null;
@ -1903,6 +1934,22 @@ return (function () {
} }
} }
function processHxOnWildcard(elt) {
// wipe any previous on handlers so that this function takes precedence
deInitOnHandlers(elt)
for (const attr of elt.attributes) {
const { name, value } = attr
if (name.startsWith("hx-on:") || name.startsWith("data-hx-on:")) {
let eventName = name.slice(name.indexOf(":") + 1)
// if the eventName starts with a colon, prepend "htmx" for shorthand support
if (eventName.startsWith(":")) eventName = "htmx" + eventName
addHxOnEventHandler(elt, eventName, value)
}
}
}
function initNode(elt) { function initNode(elt) {
if (elt.closest && elt.closest(htmx.config.disableSelector)) { if (elt.closest && elt.closest(htmx.config.disableSelector)) {
return; return;
@ -1959,6 +2006,9 @@ return (function () {
elt = resolveTarget(elt); elt = resolveTarget(elt);
initNode(elt); initNode(elt);
forEach(findElementsToProcess(elt), function(child) { initNode(child) }); forEach(findElementsToProcess(elt), function(child) { initNode(child) });
// Because it happens second, the new way of adding onHandlers superseeds the old one
// i.e. if there are any hx-on:eventName attributes, the hx-on attribute will be ignored
forEach(findHxOnWildcardElements(elt), processHxOnWildcard);
} }
//==================================================================== //====================================================================
@ -2196,7 +2246,9 @@ return (function () {
swapInnerHTML(historyElement, fragment, settleInfo) swapInnerHTML(historyElement, fragment, settleInfo)
settleImmediately(settleInfo.tasks); settleImmediately(settleInfo.tasks);
document.title = cached.title; document.title = cached.title;
setTimeout(function () {
window.scrollTo(0, cached.scroll); window.scrollTo(0, cached.scroll);
}, 0); // next 'tick', so browser has time to render layout
currentPathForHistory = path; currentPathForHistory = path;
triggerEvent(getDocument().body, "htmx:historyRestore", {path:path, item:cached}); triggerEvent(getDocument().body, "htmx:historyRestore", {path:path, item:cached});
} else { } else {
@ -2925,8 +2977,12 @@ return (function () {
var requestAttrValues = getValuesForElement(elt, 'hx-request'); var requestAttrValues = getValuesForElement(elt, 'hx-request');
var eltIsBoosted = getInternalData(elt).boosted; var eltIsBoosted = getInternalData(elt).boosted;
var useUrlParams = htmx.config.methodsThatUseUrlParams.indexOf(verb) >= 0
var requestConfig = { var requestConfig = {
boosted: eltIsBoosted, boosted: eltIsBoosted,
useUrlParams: useUrlParams,
parameters: filteredParameters, parameters: filteredParameters,
unfilteredParameters: allParameters, unfilteredParameters: allParameters,
headers:headers, headers:headers,
@ -2951,6 +3007,7 @@ return (function () {
headers = requestConfig.headers; headers = requestConfig.headers;
filteredParameters = requestConfig.parameters; filteredParameters = requestConfig.parameters;
errors = requestConfig.errors; errors = requestConfig.errors;
useUrlParams = requestConfig.useUrlParams;
if(errors && errors.length > 0){ if(errors && errors.length > 0){
triggerEvent(elt, 'htmx:validation:halted', requestConfig) triggerEvent(elt, 'htmx:validation:halted', requestConfig)
@ -2962,26 +3019,25 @@ return (function () {
var splitPath = path.split("#"); var splitPath = path.split("#");
var pathNoAnchor = splitPath[0]; var pathNoAnchor = splitPath[0];
var anchor = splitPath[1]; var anchor = splitPath[1];
var finalPathForGet = null;
if (verb === 'get') { var finalPath = path
finalPathForGet = pathNoAnchor; if (useUrlParams) {
finalPath = pathNoAnchor;
var values = Object.keys(filteredParameters).length !== 0; var values = Object.keys(filteredParameters).length !== 0;
if (values) { if (values) {
if (finalPathForGet.indexOf("?") < 0) { if (finalPath.indexOf("?") < 0) {
finalPathForGet += "?"; finalPath += "?";
} else { } else {
finalPathForGet += "&"; finalPath += "&";
} }
finalPathForGet += urlEncode(filteredParameters); finalPath += urlEncode(filteredParameters);
if (anchor) { if (anchor) {
finalPathForGet += "#" + anchor; finalPath += "#" + anchor;
} }
} }
xhr.open('GET', finalPathForGet, true);
} else {
xhr.open(verb.toUpperCase(), path, true);
} }
xhr.open(verb.toUpperCase(), finalPath, true);
xhr.overrideMimeType("text/html"); xhr.overrideMimeType("text/html");
xhr.withCredentials = requestConfig.withCredentials; xhr.withCredentials = requestConfig.withCredentials;
xhr.timeout = requestConfig.timeout; xhr.timeout = requestConfig.timeout;
@ -3002,7 +3058,7 @@ return (function () {
xhr: xhr, target: target, requestConfig: requestConfig, etc: etc, boosted: eltIsBoosted, xhr: xhr, target: target, requestConfig: requestConfig, etc: etc, boosted: eltIsBoosted,
pathInfo: { pathInfo: {
requestPath: path, requestPath: path,
finalRequestPath: finalPathForGet || path, finalRequestPath: finalPath,
anchor: anchor anchor: anchor
} }
}; };
@ -3077,7 +3133,8 @@ return (function () {
}); });
}); });
triggerEvent(elt, 'htmx:beforeSend', responseInfo); triggerEvent(elt, 'htmx:beforeSend', responseInfo);
xhr.send(verb === 'get' ? null : encodeParamsForBody(xhr, elt, filteredParameters)); var params = useUrlParams ? null : encodeParamsForBody(xhr, elt, filteredParameters)
xhr.send(params);
return promise; return promise;
} }
@ -3268,8 +3325,13 @@ return (function () {
// safari issue - see https://github.com/microsoft/playwright/issues/5894 // safari issue - see https://github.com/microsoft/playwright/issues/5894
} }
var selectOverride;
if (hasHeader(xhr, /HX-Reselect:/i)) {
selectOverride = xhr.getResponseHeader("HX-Reselect");
}
var settleInfo = makeSettleInfo(target); var settleInfo = makeSettleInfo(target);
selectAndSwap(swapSpec.swapStyle, target, elt, serverResponse, settleInfo); selectAndSwap(swapSpec.swapStyle, target, elt, serverResponse, settleInfo, selectOverride);
if (selectionInfo.elt && if (selectionInfo.elt &&
!bodyContains(selectionInfo.elt) && !bodyContains(selectionInfo.elt) &&

View File

@ -16,6 +16,13 @@
<div class="col s7 m6" id="answer-post"> <div class="col s7 m6" id="answer-post">
{% include 'answer-post.html' %} {% include 'answer-post.html' %}
</div> </div>
<div class="col s7 m6" id="minio"-post">
<h1>Upload IPS File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
</div>
</div> </div>
{% endblock content %} {% endblock content %}