add middlewareManifest type, ensure events to hook into are valid when calling use(middleware)

This commit is contained in:
wearrrrr 2024-06-17 02:09:12 -05:00
parent 4395c41041
commit 6f4f234c82
8 changed files with 330 additions and 249 deletions

View file

@ -1,5 +1,5 @@
import path from "path"; import path from "path";
import fs from "fs" import fs from "fs";
const failureFile = fs.readFileSync("Checkfailed.html", "utf8"); const failureFile = fs.readFileSync("Checkfailed.html", "utf8");

View file

@ -10,20 +10,22 @@ const ww = new WorkerWare({
debug: true, debug: true,
}); });
function logContext(ctx, event) { function logContext(event) {
console.log("Context:", ctx);
console.log("Event:", event); console.log("Event:", event);
return void 0; return undefined;
} }
ww.use(logContext) ww.use({
function: logContext,
events: ["fetch"],
});
const uv = new UVServiceWorker(); const uv = new UVServiceWorker();
self.addEventListener("fetch", async (event) => { self.addEventListener("fetch", async (event) => {
let middleware = await ww.run(self, event)(); let mwResponse = await ww.run(event)();
if (middleware.includes(null)) { if (mwResponse.includes(null)) {
console.log("Aborting Request!") console.log("Aborting Request!");
return; return;
} }
event.respondWith( event.respondWith(

View file

@ -0,0 +1,6 @@
class WWError extends Error {
constructor(message) {
super(message);
this.name = "[WorkerWare Exception]";
}
}

View file

@ -1,28 +1,97 @@
importScripts("/workerware/WWError.js");
const dbg = console.log.bind(console, "[WorkerWare]"); const dbg = console.log.bind(console, "[WorkerWare]");
const defaultOpt = { const defaultOpt = {
debug: false, debug: false,
} };
// type middlewareManifest = {
// function: Function,
// name?: string,
// events: string[], // Should be a union of validEvents.
// }
const validEvents = [
"abortpayment",
"activate",
"backgroundfetchabort",
"backgroundfetchclick",
"backgroundfetchfail",
"backgroundfetchsuccess",
"canmakepayment",
"contentdelete",
"cookiechange",
"fetch",
"install",
"message",
"messageerror",
"notificationclick",
"notificationclose",
"paymentrequest",
"periodicsync",
"push",
"pushsubscriptionchange",
"sync",
];
class WorkerWare { class WorkerWare {
constructor(opt) { constructor(opt) {
this._opt = opt; this._opt = opt;
this._middlewares = []; this._middlewares = [];
}
use(middleware) {
let validateMW = this.validateMiddleware(middleware);
if (validateMW.error) throw new WWError(validateMW.error);
// This means the middleware is an anonymous function, or the user is silly and named their function "function"
if (middleware.function.name == "function") middleware.name = crypto.randomUUID();
if (!middleware.name) middleware.name = middleware.function.name;
if (this._opt.debug) dbg("Adding middleware:", middleware.name);
this._middlewares.push(middleware);
}
run(event) {
const middlewares = this._middlewares;
const returnList = [];
let fn = async () => {
for (let i = 0; i < middlewares.length; i++) {
dbg(middlewares[i], event.type);
if (middlewares[i].events.includes(event.type)) {
returnList.push(await middlewares[i].function(event));
}
}
return returnList;
};
return fn;
}
runMW(id, event) {
const middlewares = this._middlewares;
if (this._opt.debug) dbg("Running middleware:", id);
if (middlewares.includes(id)) {
return middlewares[id](event);
} }
use(fn) { }
if (typeof fn !== 'function') throw new TypeError('[WorkerWare] Middleware must be a function!'); validateMiddleware(middleware) {
if (this._opt.debug) dbg("Added middleware", fn.name || "<anonymous>"); if (!middleware.function)
this._middlewares.push(fn); return {
} error: "middleware.function is required",
run(ctx, event) { };
const middlewares = this._middlewares; if (typeof middleware.function !== "function")
const returnList = []; return {
let fn = async () => { error: "middleware.function must be typeof function",
for (let i = 0; i < middlewares.length; i++) { };
returnList.push(await middlewares[i](ctx, event)); if (!middleware.events)
} return {
return returnList; error: "middleware.events is required",
}; };
return fn; if (!Array.isArray(middleware.events))
} return {
} error: "middleware.events must be an array",
};
if (middleware.events.some((ev) => !validEvents.includes(ev)))
return {
error: "Invalid event type! Must be one of the following: " + validEvents.join(", "),
};
return {
error: undefined,
};
}
}

View file

@ -48,9 +48,7 @@
} }
function getUVProxyURL(frame: HTMLIFrameElement) { function getUVProxyURL(frame: HTMLIFrameElement) {
return window.__uv$config.decodeUrl( return window.__uv$config.decodeUrl(frame.contentWindow!.location.href.split("/service/")[1]);
frame.contentWindow!.location.href.split("/service/")[1]
)
} }
async function loadContent() { async function loadContent() {
@ -209,9 +207,7 @@
input!.value.trim() input!.value.trim()
); );
} else { } else {
navigator.clipboard.writeText( navigator.clipboard.writeText(getUVProxyURL(proxyFrame));
getUVProxyURL(proxyFrame)
);
} }
new Notyf({ new Notyf({
duration: 2000, duration: 2000,

View file

@ -72,7 +72,7 @@ export async function registerSW() {
}); });
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
await navigator.serviceWorker.register("/sw.js").then((registration) => { await navigator.serviceWorker.register("/sw.js").then((registration) => {
console.log("Registered SW!") console.log("Registered SW!");
resolve(null); resolve(null);
}); });
}); });

View file

@ -57,10 +57,12 @@ const { title, optionalPreloads } = Astro.props;
<script src="https://www.googletagmanager.com/gtag/js?id=G-P1JX4G9KSF" is:inline></script> <script src="https://www.googletagmanager.com/gtag/js?id=G-P1JX4G9KSF" is:inline></script>
<script is:inline> <script is:inline>
window.dataLayer = window.dataLayer || []; window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);} function gtag() {
gtag('js', new Date()); dataLayer.push(arguments);
}
gtag('config', 'G-P1JX4G9KSF'); gtag("js", new Date());
gtag("config", "G-P1JX4G9KSF");
</script> </script>
<meta name="generator" content={Astro.generator} /> <meta name="generator" content={Astro.generator} />
<title>{title}</title> <title>{title}</title>

View file

@ -3,215 +3,221 @@ import Layout from "src/layouts/Layout.astro";
--- ---
<Layout title="Terms and Conditions | Alu"> <Layout title="Terms and Conditions | Alu">
<div id="main-content"> <div id="main-content">
<h2><strong>Terms and Conditions</strong></h2> <h2><strong>Terms and Conditions</strong></h2>
<p>Welcome to Alu!</p> <p>Welcome to Alu!</p>
<p> <p>
These terms and conditions outline the rules and regulations for the use of Alu Project's These terms and conditions outline the rules and regulations for the use of Alu Project's
Website, located at https://aluu.xyz. Website, located at https://aluu.xyz.
</p> </p>
<p> <p>
By accessing this website we assume you accept these terms and conditions. Do not continue to By accessing this website we assume you accept these terms and conditions. Do not continue to
use Alu if you do not agree to take all of the terms and conditions stated on this page. use Alu if you do not agree to take all of the terms and conditions stated on this page.
</p> </p>
<p> <p>
The following terminology applies to these Terms and Conditions, Privacy Statement and The following terminology applies to these Terms and Conditions, Privacy Statement and
Disclaimer Notice and all Agreements: "Client", "You" and "Your" refers to you, the person log Disclaimer Notice and all Agreements: "Client", "You" and "Your" refers to you, the person log
on this website and compliant to the Company's terms and conditions. "The Company", "Ourselves", on this website and compliant to the Company's terms and conditions. "The Company",
"We", "Our" and "Us", refers to our Company. "Party", "Parties", or "Us", refers to both the "Ourselves", "We", "Our" and "Us", refers to our Company. "Party", "Parties", or "Us", refers
Client and ourselves. All terms refer to the offer, acceptance and consideration of payment to both the Client and ourselves. All terms refer to the offer, acceptance and consideration
necessary to undertake the process of our assistance to the Client in the most appropriate of payment necessary to undertake the process of our assistance to the Client in the most
manner for the express purpose of meeting the Client's needs in respect of provision of the appropriate manner for the express purpose of meeting the Client's needs in respect of
Company's stated services, in accordance with and subject to, prevailing law of us. Any use of provision of the Company's stated services, in accordance with and subject to, prevailing law
the above terminology or other words in the singular, plural, capitalization and/or he/she or of us. Any use of the above terminology or other words in the singular, plural, capitalization
they, are taken as interchangeable and therefore as referring to same. and/or he/she or they, are taken as interchangeable and therefore as referring to same.
</p> </p>
<h3><strong>Cookies</strong></h3> <h3><strong>Cookies</strong></h3>
<p> <p>
We employ the use of cookies. By accessing Alu, you agreed to use cookies in agreement with the We employ the use of cookies. By accessing Alu, you agreed to use cookies in agreement with
Alu Project's Privacy Policy. the Alu Project's Privacy Policy.
</p> </p>
<p> <p>
Most interactive websites use cookies to let us retrieve the user's details for each visit. Most interactive websites use cookies to let us retrieve the user's details for each visit.
Cookies are used by our website to enable the functionality of certain areas to make it easier Cookies are used by our website to enable the functionality of certain areas to make it easier
for people visiting our website. Some of our affiliate/advertising partners may also use for people visiting our website. Some of our affiliate/advertising partners may also use
cookies. cookies.
</p> </p>
<h3><strong>License</strong></h3> <h3><strong>License</strong></h3>
<p> <p>
Unless otherwise stated, Alu Project and/or its licensors own the intellectual property rights Unless otherwise stated, Alu Project and/or its licensors own the intellectual property rights
for all material on Alu. All intellectual property rights are reserved. You may access this from for all material on Alu. All intellectual property rights are reserved. You may access this
Alu for your own personal use subjected to restrictions set in these terms and conditions. from Alu for your own personal use subjected to restrictions set in these terms and
</p> conditions.
</p>
<p>You must not:</p>
<ul> <p>You must not:</p>
<li>Republish material from Alu</li> <ul>
<li>Sell, rent or sub-license material from Alu</li> <li>Republish material from Alu</li>
<li>Reproduce, duplicate or copy material from Alu</li> <li>Sell, rent or sub-license material from Alu</li>
<li>Redistribute content from Alu</li> <li>Reproduce, duplicate or copy material from Alu</li>
</ul> <li>Redistribute content from Alu</li>
</ul>
<p>This Agreement shall begin on the date hereof.</p>
<p>This Agreement shall begin on the date hereof.</p>
<h3><strong>Hyperlinking to our Content</strong></h3>
<h3><strong>Hyperlinking to our Content</strong></h3>
<p>The following organizations may link to our Website without prior written approval:</p>
<p>The following organizations may link to our Website without prior written approval:</p>
<ul>
<li>Government agencies;</li> <ul>
<li>Search engines;</li> <li>Government agencies;</li>
<li>News organizations;</li> <li>Search engines;</li>
<li> <li>News organizations;</li>
Online directory distributors may link to our Website in the same manner as they hyperlink to <li>
the Websites of other listed businesses; and Online directory distributors may link to our Website in the same manner as they hyperlink
</li> to the Websites of other listed businesses; and
<li> </li>
System wide Accredited Businesses except soliciting non-profit organizations, charity shopping <li>
malls, and charity fundraising groups which may not hyperlink to our Web site. System wide Accredited Businesses except soliciting non-profit organizations, charity
</li> shopping malls, and charity fundraising groups which may not hyperlink to our Web site.
</ul> </li>
</ul>
<p>
These organizations may link to our home page, to publications or to other Website information <p>
so long as the link: (a) is not in any way deceptive; (b) does not falsely imply sponsorship, These organizations may link to our home page, to publications or to other Website information
endorsement or approval of the linking party and its products and/or services; and (c) fits so long as the link: (a) is not in any way deceptive; (b) does not falsely imply sponsorship,
within the context of the linking party's site. endorsement or approval of the linking party and its products and/or services; and (c) fits
</p> within the context of the linking party's site.
</p>
<p>We may consider and approve other link requests from the following types of organizations:</p>
<p>
<ul> We may consider and approve other link requests from the following types of organizations:
<li>commonly-known consumer and/or business information sources;</li> </p>
<li>dot.com community sites;</li>
<li>associations or other groups representing charities;</li> <ul>
<li>online directory distributors;</li> <li>commonly-known consumer and/or business information sources;</li>
<li>internet portals;</li> <li>dot.com community sites;</li>
<li>accounting, law and consulting firms; and</li> <li>associations or other groups representing charities;</li>
<li>educational institutions and trade associations.</li> <li>online directory distributors;</li>
</ul> <li>internet portals;</li>
<li>accounting, law and consulting firms; and</li>
<p> <li>educational institutions and trade associations.</li>
We will approve link requests from these organizations if we decide that: (a) the link would not </ul>
make us look unfavorably to ourselves or to our accredited businesses; (b) the organization does
not have any negative records with us; (c) the benefit to us from the visibility of the <p>
hyperlink compensates the absence of Alu Project; and (d) the link is in the context of general We will approve link requests from these organizations if we decide that: (a) the link would
resource information. not make us look unfavorably to ourselves or to our accredited businesses; (b) the
</p> organization does not have any negative records with us; (c) the benefit to us from the
visibility of the hyperlink compensates the absence of Alu Project; and (d) the link is in the
<p> context of general resource information.
These organizations may link to our home page so long as the link: (a) is not in any way </p>
deceptive; (b) does not falsely imply sponsorship, endorsement or approval of the linking party
and its products or services; and (c) fits within the context of the linking party's site. <p>
</p> These organizations may link to our home page so long as the link: (a) is not in any way
deceptive; (b) does not falsely imply sponsorship, endorsement or approval of the linking
<p> party and its products or services; and (c) fits within the context of the linking party's
If you are one of the organizations listed in paragraph 2 above and are interested in linking to site.
our website, you must inform us by sending an e-mail to Alu Project. Please include your name, </p>
your organization name, contact information as well as the URL of your site, a list of any URLs
from which you intend to link to our Website, and a list of the URLs on our site to which you <p>
would like to link. Wait 2-3 weeks for a response. If you are one of the organizations listed in paragraph 2 above and are interested in linking
</p> to our website, you must inform us by sending an e-mail to Alu Project. Please include your
name, your organization name, contact information as well as the URL of your site, a list of
<p>Approved organizations may hyperlink to our Website as follows:</p> any URLs from which you intend to link to our Website, and a list of the URLs on our site to
which you would like to link. Wait 2-3 weeks for a response.
<ul> </p>
<li>By use of our corporate name; or</li>
<li>By use of the uniform resource locator being linked to; or</li> <p>Approved organizations may hyperlink to our Website as follows:</p>
<li>
By use of any other description of our Website being linked to that makes sense within the <ul>
context and format of content on the linking party's site. <li>By use of our corporate name; or</li>
</li> <li>By use of the uniform resource locator being linked to; or</li>
</ul> <li>
By use of any other description of our Website being linked to that makes sense within the
<p> context and format of content on the linking party's site.
No use of Alu Project's logo or other artwork will be allowed for linking absent a trademark </li>
license agreement. </ul>
</p>
<p>
<h3><strong>iFrames</strong></h3> No use of Alu Project's logo or other artwork will be allowed for linking absent a trademark
license agreement.
<p> </p>
Without prior approval and written permission, you may not create frames around our Webpages
that alter in any way the visual presentation or appearance of our Website. <h3><strong>iFrames</strong></h3>
</p>
<p>
<h3><strong>Content Liability</strong></h3> Without prior approval and written permission, you may not create frames around our Webpages
that alter in any way the visual presentation or appearance of our Website.
<p> </p>
We shall not be hold responsible for any content that appears on your Website. You agree to
protect and defend us against all claims that is rising on your Website. No link(s) should <h3><strong>Content Liability</strong></h3>
appear on any Website that may be interpreted as libelous, obscene or criminal, or which
infringes, otherwise violates, or advocates the infringement or other violation of, any third <p>
party rights. We shall not be hold responsible for any content that appears on your Website. You agree to
</p> protect and defend us against all claims that is rising on your Website. No link(s) should
appear on any Website that may be interpreted as libelous, obscene or criminal, or which
<h3><strong>Reservation of Rights</strong></h3> infringes, otherwise violates, or advocates the infringement or other violation of, any third
party rights.
<p> </p>
We reserve the right to request that you remove all links or any particular link to our Website.
You approve to immediately remove all links to our Website upon request. We also reserve the <h3><strong>Reservation of Rights</strong></h3>
right to amen these terms and conditions and it's linking policy at any time. By continuously
linking to our Website, you agree to be bound to and follow these linking terms and conditions. <p>
</p> We reserve the right to request that you remove all links or any particular link to our
Website. You approve to immediately remove all links to our Website upon request. We also
<h3><strong>Removal of links from our website</strong></h3> reserve the right to amen these terms and conditions and it's linking policy at any time. By
continuously linking to our Website, you agree to be bound to and follow these linking terms
<p> and conditions.
If you find any link on our Website that is offensive for any reason, you are free to contact </p>
and inform us any moment. We will consider requests to remove links but we are not obligated to
or so or to respond to you directly. <h3><strong>Removal of links from our website</strong></h3>
</p>
<p>
<p> If you find any link on our Website that is offensive for any reason, you are free to contact
We do not ensure that the information on this website is correct, we do not warrant its and inform us any moment. We will consider requests to remove links but we are not obligated
completeness or accuracy; nor do we promise to ensure that the website remains available or that to or so or to respond to you directly.
the material on the website is kept up to date. </p>
</p>
<p>
<h3><strong>Disclaimer</strong></h3> We do not ensure that the information on this website is correct, we do not warrant its
completeness or accuracy; nor do we promise to ensure that the website remains available or
<p> that the material on the website is kept up to date.
To the maximum extent permitted by applicable law, we exclude all representations, warranties </p>
and conditions relating to our website and the use of this website. Nothing in this disclaimer
will: <h3><strong>Disclaimer</strong></h3>
</p>
<p>
<ul> To the maximum extent permitted by applicable law, we exclude all representations, warranties
<li>limit or exclude our or your liability for death or personal injury;</li> and conditions relating to our website and the use of this website. Nothing in this disclaimer
<li>limit or exclude our or your liability for fraud or fraudulent misrepresentation;</li> will:
<li> </p>
limit any of our or your liabilities in any way that is not permitted under applicable law; or
</li> <ul>
<li>exclude any of our or your liabilities that may not be excluded under applicable law.</li> <li>limit or exclude our or your liability for death or personal injury;</li>
</ul> <li>limit or exclude our or your liability for fraud or fraudulent misrepresentation;</li>
<li>
<p> limit any of our or your liabilities in any way that is not permitted under applicable law;
The limitations and prohibitions of liability set in this Section and elsewhere in this or
disclaimer: (a) are subject to the preceding paragraph; and (b) govern all liabilities arising </li>
under the disclaimer, including liabilities arising in contract, in tort and for breach of <li>exclude any of our or your liabilities that may not be excluded under applicable law.</li>
statutory duty. </ul>
</p>
<p>
<p> The limitations and prohibitions of liability set in this Section and elsewhere in this
As long as the website and the information and services on the website are provided free of disclaimer: (a) are subject to the preceding paragraph; and (b) govern all liabilities arising
charge, we will not be liable for any loss or damage of any nature. under the disclaimer, including liabilities arising in contract, in tort and for breach of
</p> statutory duty.
</div> </p>
<p>
As long as the website and the information and services on the website are provided free of
charge, we will not be liable for any loss or damage of any nature.
</p>
</div>
</Layout> </Layout>
<style> <style>
#main-content { #main-content {
width: 90%; width: 90%;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>