fml
This commit is contained in:
parent
3287e3721c
commit
f66fdc34f1
6 changed files with 18 additions and 15 deletions
|
@ -3,8 +3,8 @@ CREATE TABLE `entry` (
|
|||
`name` text NOT NULL,
|
||||
`href` text NOT NULL,
|
||||
`finished` integer DEFAULT false NOT NULL,
|
||||
`created_at` integer DEFAULT (unixepoch('subsec') NOT NULL,
|
||||
`updated_at` integer DEFAULT (unixepoch('subsec') NOT NULL
|
||||
`created_at` integer DEFAULT (unixepoch('subsec')) NOT NULL,
|
||||
`updated_at` integer DEFAULT (unixepoch('subsec')) NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX `entry_name_unique` ON `entry` (`name`);
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"version": "6",
|
||||
"dialect": "sqlite",
|
||||
"id": "5b7c56dc-4c5d-444a-9c66-9da5c7e06977",
|
||||
"id": "034dc823-0bad-47de-9b5e-4858f89517be",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"tables": {
|
||||
"entry": {
|
||||
|
@ -42,7 +42,7 @@
|
|||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch('subsec')"
|
||||
"default": "(unixepoch('subsec'))"
|
||||
},
|
||||
"updated_at": {
|
||||
"name": "updated_at",
|
||||
|
@ -50,7 +50,7 @@
|
|||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"autoincrement": false,
|
||||
"default": "(unixepoch('subsec')"
|
||||
"default": "(unixepoch('subsec'))"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
{
|
||||
"idx": 0,
|
||||
"version": "6",
|
||||
"when": 1743898098259,
|
||||
"tag": "0000_neat_marvel_boy",
|
||||
"when": 1743898653227,
|
||||
"tag": "0000_rapid_turbo",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Database } from 'bun:sqlite';
|
||||
import { env } from 'bun';
|
||||
import { drizzle } from 'drizzle-orm/bun-sqlite';
|
||||
import { migrate } from 'drizzle-orm/bun-sqlite/migrator';
|
||||
// import { migrate } from 'drizzle-orm/bun-sqlite/migrator';
|
||||
import { createWrappedTimer } from '../wrapped-timer';
|
||||
|
||||
function initDb() {
|
||||
|
@ -25,10 +25,10 @@ function vacuumDb() {
|
|||
}
|
||||
|
||||
if (global.db === undefined || global.drizzleDB === undefined) {
|
||||
global.db = new Database(`${env.SQLITE_DB_PATH}/${env.SQLITE_DB_NAME}`, { create: true });
|
||||
global.db = new Database(`${env.SQLITE_DB_PATH}/${env.SQLITE_DB_NAME}`, { create: true, strict: true });
|
||||
initDb();
|
||||
global.drizzleDB = drizzle(global.db);
|
||||
migrate(global.drizzleDB, { migrationsFolder: './drizzle' });
|
||||
// migrate(global.drizzleDB, { migrationsFolder: './drizzle' });
|
||||
}
|
||||
|
||||
const incrementalVacuumInterval = 1000 * 30; // 30 seconds
|
||||
|
|
|
@ -3,11 +3,11 @@ import { index, integer, primaryKey, sqliteTable, text } from 'drizzle-orm/sqlit
|
|||
|
||||
const createdAt = integer('created_at', { mode: 'timestamp_ms' })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch('subsec')`)
|
||||
.default(sql`(unixepoch('subsec'))`)
|
||||
.$defaultFn(() => new Date());
|
||||
const updatedAt = integer('updated_at', { mode: 'timestamp_ms' })
|
||||
.notNull()
|
||||
.default(sql`(unixepoch('subsec')`)
|
||||
.default(sql`(unixepoch('subsec'))`)
|
||||
.$onUpdateFn(() => new Date());
|
||||
|
||||
export const entry = sqliteTable(
|
||||
|
|
|
@ -6,6 +6,7 @@ import sitemapTxt from './static/sitemap.txt';
|
|||
import icon from './static/favicon.png' with { type: 'file' };
|
||||
import { entry } from "./db/schema";
|
||||
import { desc, eq } from "drizzle-orm";
|
||||
import { drizzleDB } from "./db";
|
||||
const favicon = await Bun.file(icon).bytes();
|
||||
|
||||
const development = env.NODE_ENV !== 'production';
|
||||
|
@ -138,9 +139,11 @@ async function getEntryFromReq(req: Request) {
|
|||
}
|
||||
|
||||
function isAuthenticated(req: Request) {
|
||||
const bearer = req.headers.get('bearer');
|
||||
if (!bearer) return false;
|
||||
|
||||
const auth = req.headers.get('authorization');
|
||||
if (!auth) return false;
|
||||
const [type, bearer] = auth.split(' ');
|
||||
if (type !== 'Bearer') return false;
|
||||
// Check if the token is valid
|
||||
return bearer === env.BEARER_TOKEN;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue