Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akurilov committed Mar 3, 2024
1 parent 9d6486a commit 9d5623e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
18 changes: 13 additions & 5 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,22 @@
</div>

<div id="events-menu"
style="display: none"
style="display: flex"
class="absolute inset-x-0 z-20 w-full bg-white px-1 py-1 shadow-md transition-all duration-300 ease-in-out dark:bg-gray-900 items-center justify-center flex flex-col space-y-1">

<div class="grid space-x-2">
<span class="col-span-2 text-center text-gray-600 dark:text-gray-400">
<p id="streaming-results">Results appear below for the next 15 minutes.</p>
<p class="flex space-x-2">
For full functionality use <a href="https://t.me/AwakariBot" target="_blank" class="text-blue-500">@AwakariBot</a>.
<p id="streaming-results">Results will appear below for the next 1 hour.</p>
<p>
Use
<a href="https://t.me/AwakariBot" target="_blank" class="text-blue-500">@AwakariBot</a>
as full-featured reader.</p>
<p>
Go to
<a href="https://awakari.com/sub.html" class="text-blue-500">Subscriptions</a>
to manage own queries.</p>
<div class="flex">
<div class="grow w-full"></div>
<svg xmlns="http://www.w3.org/2000/svg"
onclick="queryStop()"
class="h-6 w-6 place-self-end sm:place-self-center text-gray-800 dark:text-gray-200"
Expand All @@ -214,7 +222,7 @@
stroke-width="2">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</p>
</div>
</span>
</div>

Expand Down
29 changes: 15 additions & 14 deletions web/query.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const resultsStreamingTtimeout = 3_600_000;

function loadQuery() {
const q = new URLSearchParams(window.location.search).get("q");
if (q != null && q !== "") {
Expand All @@ -8,19 +10,20 @@ function loadQuery() {
break
default:
document.getElementById("query").value = q;
getQuerySubscription(q)
const expires = Date.now() + resultsStreamingTtimeout;
getQuerySubscription(q, expires)
.then(subId => {
if (subId !== "") {
startEventsLoading(subId);
startEventsLoading(subId, resultsStreamingTtimeout);
}
})
}
}
}

const subNameDefault = "_app_reserved";
const defaultSubName = "_reserved_app_search";

function getQuerySubscription(q) {
function getQuerySubscription(q, expires) {
const authToken = localStorage.getItem(keyAuthToken);
const userId = localStorage.getItem(keyUserId);
const headers = {
Expand All @@ -36,7 +39,7 @@ function getQuerySubscription(q) {
"X-Awakari-User-Id": userId,
},
}
return fetch(`/v1/sub?limit=1000&filter=${subNameDefault}`, optsReq)
return fetch(`/v1/sub?limit=1000&filter=${defaultSubName}`, optsReq)
.then(resp => {
if (resp.ok) {
return resp.json();
Expand All @@ -47,13 +50,13 @@ function getQuerySubscription(q) {
.then(data => {
if (data && data.subs) {
for (let sub of data.subs) {
if (sub.description === subNameDefault) {
if (sub.description === defaultSubName) {
return deleteSubscription(sub.id, headers)
.then(_ => createSubscription(q, headers));
.then(_ => createSubscription(q, headers, expires));
}
}
}
return createSubscription(q, headers);
return createSubscription(q, headers, expires);
})
.catch(err => {
alert(err);
Expand All @@ -78,10 +81,11 @@ function deleteSubscription(id, headers) {
})
}

function createSubscription(q, headers) {
function createSubscription(q, headers, expires) {
const payload = {
description: subNameDefault,
description: defaultSubName,
enabled: true,
expires: expires.toISOString(),
cond: {
not: false,
tc: {
Expand Down Expand Up @@ -129,10 +133,7 @@ function queryStop() {
}
}

const timeout = 900_000;

async function startEventsLoading(subId) {
const deadline = Date.now() + timeout;
async function startEventsLoading(subId, deadline) {
document.getElementById("events-menu").style.display = "flex";
queryRunning = true;
try {
Expand Down

0 comments on commit 9d5623e

Please sign in to comment.