Skip to content
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

fix for deno 2 #180

Merged
merged 2 commits into from
Dec 12, 2024
Merged
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
9 changes: 4 additions & 5 deletions .github/workflows/build-frontend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ on:
branches:
- "*"
schedule:
- cron: "39 12 * * 6"
- cron: "39 12 * * 6"

jobs:
run-linter:
run-frontend-linter:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- uses: actions/setup-node@v3
with:
node-version: 'latest'
node-version: "16"

- name: Install dependencies
run: npm install
working-directory: ./app/frontend
Expand All @@ -29,4 +29,3 @@ jobs:
# - name: Build
# run: npm run lint
# working-directory: ./app/frontend

4 changes: 2 additions & 2 deletions .github/workflows/lint-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:
branches:
- "*"
schedule:
- cron: "39 12 * * 6"
- cron: "39 12 * * 6"

jobs:
run-linter:
run-backend-linter:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
16 changes: 8 additions & 8 deletions app/backend/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ const values = Deno.env.toObject();
const port = values.PORT || 80;
const vapidKey = values.VAPID_KEY || 'eyJrdHkiOiJFQyIsImNydiI6IlAtMjU2IiwiYWxnIjoiRVMyNTYiLCJ4IjoiUV92WlVXUExOUlFMRnU5QWRNaGRDQlFpY1FKamxYajVHZ2lwY19BS1E5USIsInkiOiJILXlDUF9hZ3FzRmpGMmgtZ2dNTTdVT1UxdktJN1JTcU1XSVhfZjBJekhnIiwiZCI6IjVXdzg1TnFxN09lY0pyaDN5MDl6a1JLWWR3TEhUVTVObjlNZUNqMkh6Y2MiLCJrZXlfb3BzIjpbInNpZ24iXSwiZXh0Ijp0cnVlfQ==';
const sub = values.SUB || 'mailto:[email protected]';
const cors = values.CORS || false;
const cors = Boolean(values.CORS) || false;
const frontend = values.FRONTEND ?? 'static-site';
const sendkey = values.SENDKEY || undefined;
const loginkey = values.LOGINKEY || undefined;


await serve({
port: Number(port),
sub: sub,
vapidKey: vapidKey,
cors: cors,
frontend: frontend,
sendkey: sendkey,
loginkey: loginkey,
port: Number(port),
sub: sub,
vapidKey: vapidKey,
cors: cors,
frontend: frontend,
sendkey: sendkey,
loginkey: loginkey,
})
96 changes: 48 additions & 48 deletions app/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,66 @@ import { validateEmail, validatePort } from "./util/commandvalidator.ts";
import { notify } from "./client/mod.ts";

async function generateVapidKey() {
const key = await window.crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
const serverKey = await window.crypto.subtle.exportKey("jwk", key.privateKey);
const serverKeyString = JSON.stringify(serverKey, null, 0);
const vapidKey = btoa(serverKeyString);
return vapidKey;
const key = await crypto.subtle.generateKey({ name: "ECDSA", namedCurve: "P-256" }, true, ["sign", "verify"]);
const serverKey = await crypto.subtle.exportKey("jwk", key.privateKey);
const serverKeyString = JSON.stringify(serverKey, null, 0);
const vapidKey = btoa(serverKeyString);
return vapidKey;
}

export const program = new Denomander({
app_name: "Notify",
app_description: ``,
app_version: "1.0.0"
app_name: "Notify",
app_description: ``,
app_version: "1.0.0"
});


program
.command('run', 'Run the server')
.requiredOption("--vapidkey", `vapid key, you can use notify generate to generate a new one - warning a new key means that clients need to subscribe to it again!`)
.requiredOption("--sub", `Set the vapid subscription information (email of the owner of the site)`, validateEmail)
// .option("-s --store", `Store messages, so clients can request past messages that might be lost when device is not online for a long time.`, Boolean)
.option("-c --cors", `Enable CORS`, Boolean)
.option("-f --frontend", `if set the frontend will be served (this needs to point to the build directory of the frontend)`, undefined, './frontend/build')
.option("--sendkey", `Set the api key (for sending a new request)`, String)
.option("--loginkey", `Set the api key (for login into the ui)`, String)
.option("-p --port", `Set the api url (for this request)`, validatePort, 8787)
.action(async (ctx: Denomander) =>
await serve({
port: Number(ctx.port),
sub: ctx.sub,
vapidKey: ctx.vapidkey,
cors: ctx.cors,
frontend: ctx.frontend,
sendkey: ctx.sendkey,
loginkey: ctx.loginkey,
}));
.command('run', 'Run the server')
.requiredOption("--vapidkey", `vapid key, you can use notify generate to generate a new one - warning a new key means that clients need to subscribe to it again!`)
.requiredOption("--sub", `Set the vapid subscription information (email of the owner of the site)`, validateEmail)
// .option("-s --store", `Store messages, so clients can request past messages that might be lost when device is not online for a long time.`, Boolean)
.option("-c --cors", `Enable CORS`, Boolean)
.option("-f --frontend", `if set the frontend will be served (this needs to point to the build directory of the frontend)`, undefined, './frontend/build')
.option("--sendkey", `Set the api key (for sending a new request)`, String)
.option("--loginkey", `Set the api key (for login into the ui)`, String)
.option("-p --port", `Set the api url (for this request)`, validatePort, 8787)
.action(async (ctx: Denomander) =>
await serve({
port: Number(ctx.port),
sub: ctx.sub,
vapidKey: ctx.vapidkey,
cors: ctx.cors,
frontend: ctx.frontend,
sendkey: ctx.sendkey,
loginkey: ctx.loginkey,
}));


program.
command('generate', 'Generate a new vapid key')
.action(async () => {
const vapidKey = await generateVapidKey();
console.log(vapidKey);
});
command('generate', 'Generate a new vapid key')
.action(async () => {
const vapidKey = await generateVapidKey();
console.log(vapidKey);
});

program.
command('notify', 'Send a test notification to all clients')
.requiredOption("-t --title", `Set the title of the notification`, String)
.requiredOption("-m --message", `Set the body of the notification`, String)
.option("-i --icon", `Set the icon of the notification`, String)
.option("-t --tags", `Comma separated list of all tags`, String)
.option("-r --remote", `Set the remote url of the notification`, String, 'http://localhost:8787')
.option("-k --key", `Set the api key (for this request)`, String)
.action(async (ctx: Denomander) => {
await notify(ctx.remote, {
title: ctx.title,
message: ctx.message,
iconUrl: ctx.icon,
tags: ctx.tags ? ctx.tags.split(',') : [],
}, ctx.key);
console.log('Notification sent');
});
command('notify', 'Send a test notification to all clients')
.requiredOption("-t --title", `Set the title of the notification`, String)
.requiredOption("-m --message", `Set the body of the notification`, String)
.option("-i --icon", `Set the icon of the notification`, String)
.option("-t --tags", `Comma separated list of all tags`, String)
.option("-r --remote", `Set the remote url of the notification`, String, 'http://localhost:8787')
.option("-k --key", `Set the api key (for this request)`, String)
.action(async (ctx: Denomander) => {
await notify(ctx.remote, {
title: ctx.title,
message: ctx.message,
iconUrl: ctx.icon,
tags: ctx.tags ? ctx.tags.split(',') : [],
}, ctx.key);
console.log('Notification sent');
});


await program.parse(Deno.args);
Loading