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 branches: main
jobs: jobs:
validate: validate:
name: Validate
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read # Needed to clone the repository contents: read # Needed to clone the repository
steps: steps:
- name: Clone repository - name: Clone repository
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Install Deno - name: Install Deno
uses: denoland/setup-deno@v1 uses: denoland/setup-deno@v1
with: with:
deno-version: v1.x deno-version: v1.x
- name: Check - name: Check
run: "deno task check" run: "deno task check"

View File

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

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": { "tasks": {
"check": "deno check main.ts", "check": "deno check main.ts",
"dev": "deno run -A --unstable-ffi --env 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'" "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 sqlite from "jsr:@db/sqlite@0.11";
import * as oak from "jsr:@oak/oak@14"; 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 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 = { type User = {
id: number; id: number;
@ -21,28 +22,6 @@ interface Db {
createSession(init: Omit<Session, "id">): Promise<Session>; 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 { class SqliteDb implements Db {
private db = new sqlite.Database("bunker.db", { create: false }); private db = new sqlite.Database("bunker.db", { create: false });