Compare commits

..

No commits in common. "main" and "v0.0.1" have entirely different histories.
main ... v0.0.1

5 changed files with 5 additions and 54 deletions

View File

@ -6,18 +6,15 @@ on:
branches: main
jobs:
validate:
name: Validate
runs-on: ubuntu-latest
permissions:
contents: read # Needed to clone the repository
steps:
- name: Clone repository
uses: actions/checkout@v3
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Check
run: "deno task check"

View File

@ -7,31 +7,19 @@ jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
contents: read # Needed to clone the repository
steps:
- name: Clone
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '>=1.20.1'
- name: Compile
run: "deno task compile"
- name: Release
id: use-go-action
uses: "https://gitea.com/actions/release-action@main"
uses: ncipollo/release-action@v1
with:
files: "bunker"
api_key: '${{secrets.GITEA_TOKEN}}'
artifacts: "bunker"

View File

@ -1,13 +0,0 @@
[Unit]
Description=Bunker webservice
[Service]
Type=simple
User=simone
ExecStart=/home/simone/bunker/bunker
WorkingDirectory=/home/simone/bunker/
Restart=on-failure
Environment="PORT=8200"
[Install]
WantedBy=default.target

View File

@ -6,7 +6,7 @@
"tasks": {
"check": "deno check main.ts",
"dev": "deno run -A --unstable-ffi --env main.ts",
"compile": "deno compile --allow-net --allow-read --allow-env --allow-write --allow-ffi --allow-run --unstable-ffi --output bunker --include 'https://deno.land/x/bcrypt@v0.4.1/src/worker.ts' main.ts",
"compile": "deno compile --allow-net --allow-read --allow-env --allow-write --allow-ffi --allow-run --unstable-ffi --env main.ts",
"reset-db": "rm -rf bunker.db && sqlite3 bunker.db '.read database.sql'"
}
}

23
main.ts
View File

@ -1,6 +1,7 @@
import * as sqlite from "jsr:@db/sqlite@0.11";
import * as oak from "jsr:@oak/oak@14";
import * as bcrypt from "https://deno.land/x/bcrypt@v0.4.1/mod.ts";
import * as _bcrypt_worker from "https://deno.land/x/bcrypt@v0.4.1/src/worker.ts";
type User = {
id: number;
@ -21,28 +22,6 @@ interface Db {
createSession(init: Omit<Session, "id">): Promise<Session>;
}
try {
await Deno.lstat("bunker.db");
} catch (error) {
if (!(error instanceof Deno.errors.NotFound)) {
throw error;
}
console.log("'bunker.db' not found, creating...");
const cmd = new Deno.Command("sqlite3", {
args: ["bunker.db", ".read database.sql"],
stdout: "piped",
stderr: "piped",
});
const cmdChild = cmd.spawn();
cmdChild.stdout.pipeTo(Deno.stdout.writable);
cmdChild.stderr.pipeTo(Deno.stderr.writable);
const status = await cmdChild.status;
if (!status.success) {
console.log("failed creating 'bunker.db', exiting...");
Deno.exit(1);
}
}
class SqliteDb implements Db {
private db = new sqlite.Database("bunker.db", { create: false });