From d0d49b217d6741899f5be9ccf477d5284606a76a Mon Sep 17 00:00:00 2001 From: Max Richter Date: Sun, 5 Jan 2025 21:58:07 +0100 Subject: [PATCH] feat: store documents in sqlite --- components/layouts/main.tsx | 7 +- drizzle/0003_watery_purple_man.sql | 7 + drizzle/0004_fat_captain_marvel.sql | 13 ++ drizzle/0005_illegal_roland_deschain.sql | 1 + drizzle/0006_acoustic_the_initiative.sql | 1 + drizzle/0007_silly_synch.sql | 1 + drizzle/0008_loud_mephisto.sql | 1 + drizzle/meta/0003_snapshot.json | 226 ++++++++++++++++++++++ drizzle/meta/0004_snapshot.json | 226 ++++++++++++++++++++++ drizzle/meta/0005_snapshot.json | 228 ++++++++++++++++++++++ drizzle/meta/0006_snapshot.json | 233 +++++++++++++++++++++++ drizzle/meta/0007_snapshot.json | 233 +++++++++++++++++++++++ drizzle/meta/0008_snapshot.json | 233 +++++++++++++++++++++++ drizzle/meta/_journal.json | 42 ++++ fresh.gen.ts | 2 - lib/cache/documents.ts | 31 --- lib/documents.ts | 28 +-- lib/{cache => }/image.ts | 0 lib/resource/series.ts | 1 - lib/sqlite/schema.ts | 10 + routes/api/cache/index.ts | 9 - routes/api/images/index.ts | 4 +- routes/api/tmdb/[id].ts | 4 +- 23 files changed, 1476 insertions(+), 65 deletions(-) create mode 100644 drizzle/0003_watery_purple_man.sql create mode 100644 drizzle/0004_fat_captain_marvel.sql create mode 100644 drizzle/0005_illegal_roland_deschain.sql create mode 100644 drizzle/0006_acoustic_the_initiative.sql create mode 100644 drizzle/0007_silly_synch.sql create mode 100644 drizzle/0008_loud_mephisto.sql create mode 100644 drizzle/meta/0003_snapshot.json create mode 100644 drizzle/meta/0004_snapshot.json create mode 100644 drizzle/meta/0005_snapshot.json create mode 100644 drizzle/meta/0006_snapshot.json create mode 100644 drizzle/meta/0007_snapshot.json create mode 100644 drizzle/meta/0008_snapshot.json delete mode 100644 lib/cache/documents.ts rename lib/{cache => }/image.ts (100%) delete mode 100644 routes/api/cache/index.ts diff --git a/components/layouts/main.tsx b/components/layouts/main.tsx index fe017cb..a20741e 100644 --- a/components/layouts/main.tsx +++ b/components/layouts/main.tsx @@ -1,10 +1,5 @@ import { ComponentChildren } from "preact"; -import { resources } from "@lib/resources.ts"; -import { CSS, KATEX_CSS } from "gfm"; -import { Head } from "$fresh/runtime.ts"; -import Search, { RedirectSearchHandler } from "@islands/Search.tsx"; -import { KMenu } from "@islands/KMenu.tsx"; -import { Emoji } from "@components/Emoji.tsx"; +import Search from "@islands/Search.tsx"; import { SearchResult } from "@lib/types.ts"; export type Props = { diff --git a/drizzle/0003_watery_purple_man.sql b/drizzle/0003_watery_purple_man.sql new file mode 100644 index 0000000..097de92 --- /dev/null +++ b/drizzle/0003_watery_purple_man.sql @@ -0,0 +1,7 @@ +CREATE TABLE `document` ( + `name` text NOT NULL, + `last_modified` integer NOT NULL, + `contentType` text NOT NULL, + `size` integer NOT NULL, + `perm` text NOT NULL +); diff --git a/drizzle/0004_fat_captain_marvel.sql b/drizzle/0004_fat_captain_marvel.sql new file mode 100644 index 0000000..a36a684 --- /dev/null +++ b/drizzle/0004_fat_captain_marvel.sql @@ -0,0 +1,13 @@ +PRAGMA foreign_keys=OFF;--> statement-breakpoint +CREATE TABLE `__new_document` ( + `name` text PRIMARY KEY NOT NULL, + `last_modified` integer NOT NULL, + `contentType` text NOT NULL, + `size` integer NOT NULL, + `perm` text NOT NULL +); +--> statement-breakpoint +INSERT INTO `__new_document`("name", "last_modified", "contentType", "size", "perm") SELECT "name", "last_modified", "contentType", "size", "perm" FROM `document`;--> statement-breakpoint +DROP TABLE `document`;--> statement-breakpoint +ALTER TABLE `__new_document` RENAME TO `document`;--> statement-breakpoint +PRAGMA foreign_keys=ON; \ No newline at end of file diff --git a/drizzle/0005_illegal_roland_deschain.sql b/drizzle/0005_illegal_roland_deschain.sql new file mode 100644 index 0000000..a8ddf75 --- /dev/null +++ b/drizzle/0005_illegal_roland_deschain.sql @@ -0,0 +1 @@ +ALTER TABLE `document` RENAME COLUMN "contentType" TO "content_type"; \ No newline at end of file diff --git a/drizzle/0006_acoustic_the_initiative.sql b/drizzle/0006_acoustic_the_initiative.sql new file mode 100644 index 0000000..4391aeb --- /dev/null +++ b/drizzle/0006_acoustic_the_initiative.sql @@ -0,0 +1 @@ +ALTER TABLE `document` ADD `content` text; \ No newline at end of file diff --git a/drizzle/0007_silly_synch.sql b/drizzle/0007_silly_synch.sql new file mode 100644 index 0000000..af46e2d --- /dev/null +++ b/drizzle/0007_silly_synch.sql @@ -0,0 +1 @@ +ALTER TABLE `document` ALTER COLUMN "content" TO "content" text NOT NULL; \ No newline at end of file diff --git a/drizzle/0008_loud_mephisto.sql b/drizzle/0008_loud_mephisto.sql new file mode 100644 index 0000000..f8fee86 --- /dev/null +++ b/drizzle/0008_loud_mephisto.sql @@ -0,0 +1 @@ +ALTER TABLE `document` ALTER COLUMN "content" TO "content" text; \ No newline at end of file diff --git a/drizzle/meta/0003_snapshot.json b/drizzle/meta/0003_snapshot.json new file mode 100644 index 0000000..2ccf97c --- /dev/null +++ b/drizzle/meta/0003_snapshot.json @@ -0,0 +1,226 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "f00dd302-683e-4152-a1e4-bba8daa670dd", + "prevId": "6c228568-5674-4b9d-9088-9b947a016435", + "tables": { + "document": { + "name": "document", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "last_modified": { + "name": "last_modified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "contentType": { + "name": "contentType", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "perm": { + "name": "perm", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "image": { + "name": "image", + "columns": { + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "average": { + "name": "average", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "blurhash": { + "name": "blurhash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "performance": { + "name": "performance", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "search": { + "name": "search", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time": { + "name": "time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(STRFTIME('%s', 'now') * 1000)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/0004_snapshot.json b/drizzle/meta/0004_snapshot.json new file mode 100644 index 0000000..7863ee0 --- /dev/null +++ b/drizzle/meta/0004_snapshot.json @@ -0,0 +1,226 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "bdeaba62-8ee6-49df-9ae4-c869c22e91c9", + "prevId": "f00dd302-683e-4152-a1e4-bba8daa670dd", + "tables": { + "document": { + "name": "document", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "last_modified": { + "name": "last_modified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "contentType": { + "name": "contentType", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "perm": { + "name": "perm", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "image": { + "name": "image", + "columns": { + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "average": { + "name": "average", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "blurhash": { + "name": "blurhash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "performance": { + "name": "performance", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "search": { + "name": "search", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time": { + "name": "time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(STRFTIME('%s', 'now') * 1000)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/0005_snapshot.json b/drizzle/meta/0005_snapshot.json new file mode 100644 index 0000000..3a2ba8b --- /dev/null +++ b/drizzle/meta/0005_snapshot.json @@ -0,0 +1,228 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "9d65b82e-46c8-49b2-a6b4-629433f90a43", + "prevId": "bdeaba62-8ee6-49df-9ae4-c869c22e91c9", + "tables": { + "document": { + "name": "document", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "last_modified": { + "name": "last_modified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "perm": { + "name": "perm", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "image": { + "name": "image", + "columns": { + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "average": { + "name": "average", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "blurhash": { + "name": "blurhash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "performance": { + "name": "performance", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "search": { + "name": "search", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time": { + "name": "time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(STRFTIME('%s', 'now') * 1000)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": { + "\"document\".\"contentType\"": "\"document\".\"content_type\"" + } + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/0006_snapshot.json b/drizzle/meta/0006_snapshot.json new file mode 100644 index 0000000..205bc86 --- /dev/null +++ b/drizzle/meta/0006_snapshot.json @@ -0,0 +1,233 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "fe3d07f9-1182-4a42-b38d-d45147d46c66", + "prevId": "9d65b82e-46c8-49b2-a6b4-629433f90a43", + "tables": { + "document": { + "name": "document", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "last_modified": { + "name": "last_modified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "perm": { + "name": "perm", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "image": { + "name": "image", + "columns": { + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "average": { + "name": "average", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "blurhash": { + "name": "blurhash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "performance": { + "name": "performance", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "search": { + "name": "search", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time": { + "name": "time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(STRFTIME('%s', 'now') * 1000)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/0007_snapshot.json b/drizzle/meta/0007_snapshot.json new file mode 100644 index 0000000..59525eb --- /dev/null +++ b/drizzle/meta/0007_snapshot.json @@ -0,0 +1,233 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "083889d7-e93e-464a-911c-3fade1de4335", + "prevId": "fe3d07f9-1182-4a42-b38d-d45147d46c66", + "tables": { + "document": { + "name": "document", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "last_modified": { + "name": "last_modified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "perm": { + "name": "perm", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "image": { + "name": "image", + "columns": { + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "average": { + "name": "average", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "blurhash": { + "name": "blurhash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "performance": { + "name": "performance", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "search": { + "name": "search", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time": { + "name": "time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(STRFTIME('%s', 'now') * 1000)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/0008_snapshot.json b/drizzle/meta/0008_snapshot.json new file mode 100644 index 0000000..a49129f --- /dev/null +++ b/drizzle/meta/0008_snapshot.json @@ -0,0 +1,233 @@ +{ + "version": "6", + "dialect": "sqlite", + "id": "11e0dfc0-1020-46a9-9b26-061a2238a2d5", + "prevId": "083889d7-e93e-464a-911c-3fade1de4335", + "tables": { + "document": { + "name": "document", + "columns": { + "name": { + "name": "name", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "last_modified": { + "name": "last_modified", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "perm": { + "name": "perm", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "image": { + "name": "image", + "columns": { + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "average": { + "name": "average", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "blurhash": { + "name": "blurhash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "performance": { + "name": "performance", + "columns": { + "path": { + "name": "path", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "search": { + "name": "search", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "time": { + "name": "time", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(STRFTIME('%s', 'now') * 1000)" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(current_timestamp)" + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "checkConstraints": {} + } + }, + "views": {}, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "indexes": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 83f9f8a..35f9b35 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -22,6 +22,48 @@ "when": 1736100025647, "tag": "0002_chubby_vance_astro", "breakpoints": true + }, + { + "idx": 3, + "version": "6", + "when": 1736109017749, + "tag": "0003_watery_purple_man", + "breakpoints": true + }, + { + "idx": 4, + "version": "6", + "when": 1736109042640, + "tag": "0004_fat_captain_marvel", + "breakpoints": true + }, + { + "idx": 5, + "version": "6", + "when": 1736109067103, + "tag": "0005_illegal_roland_deschain", + "breakpoints": true + }, + { + "idx": 6, + "version": "6", + "when": 1736109456371, + "tag": "0006_acoustic_the_initiative", + "breakpoints": true + }, + { + "idx": 7, + "version": "6", + "when": 1736109586407, + "tag": "0007_silly_synch", + "breakpoints": true + }, + { + "idx": 8, + "version": "6", + "when": 1736109783318, + "tag": "0008_loud_mephisto", + "breakpoints": true } ] } \ No newline at end of file diff --git a/fresh.gen.ts b/fresh.gen.ts index b19ac10..a12c0b6 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -14,7 +14,6 @@ import * as $api_articles_index from "./routes/api/articles/index.ts"; import * as $api_auth_callback from "./routes/api/auth/callback.ts"; import * as $api_auth_login from "./routes/api/auth/login.ts"; import * as $api_auth_logout from "./routes/api/auth/logout.ts"; -import * as $api_cache_index from "./routes/api/cache/index.ts"; import * as $api_images_index from "./routes/api/images/index.ts"; import * as $api_index from "./routes/api/index.ts"; import * as $api_logs from "./routes/api/logs.ts"; @@ -74,7 +73,6 @@ const manifest = { "./routes/api/auth/callback.ts": $api_auth_callback, "./routes/api/auth/login.ts": $api_auth_login, "./routes/api/auth/logout.ts": $api_auth_logout, - "./routes/api/cache/index.ts": $api_cache_index, "./routes/api/images/index.ts": $api_images_index, "./routes/api/index.ts": $api_index, "./routes/api/logs.ts": $api_logs, diff --git a/lib/cache/documents.ts b/lib/cache/documents.ts deleted file mode 100644 index bdde90b..0000000 --- a/lib/cache/documents.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Document } from "@lib/documents.ts"; -import * as cache from "@lib/cache/cache.ts"; - -const CACHE_INTERVAL = 60; -const CACHE_KEY = "documents"; - -export async function getDocuments() { - const res = await cache.get(CACHE_KEY); - if (res) return JSON.parse(res); - return; -} - -export function setDocuments(documents: Document[]) { - return cache.set( - CACHE_KEY, - JSON.stringify(documents), - { expires: CACHE_INTERVAL }, - ); -} - -export function getDocument(id: string) { - return cache.get(CACHE_KEY + ":" + id.replaceAll("/", ":")); -} - -export async function setDocument(id: string, content: string) { - await cache.set( - CACHE_KEY + ":" + id.replaceAll("/", ":"), - content, - { expires: CACHE_INTERVAL }, - ); -} diff --git a/lib/documents.ts b/lib/documents.ts index cc63e4f..c308b15 100644 --- a/lib/documents.ts +++ b/lib/documents.ts @@ -8,16 +8,19 @@ import remarkStringify from "https://esm.sh/remark-stringify@10.0.3"; import remarkFrontmatter, { Root, } from "https://esm.sh/remark-frontmatter@4.0.1"; -import * as cache from "@lib/cache/documents.ts"; import { SILVERBULLET_SERVER } from "@lib/env.ts"; import { fixRenderedMarkdown } from "@lib/helpers.ts"; import { createLogger } from "@lib/log.ts"; import * as typesense from "@lib/typesense.ts"; +import { db } from "@lib/sqlite/sqlite.ts"; +import { documentTable } from "@lib/sqlite/schema.ts"; +import { eq } from "drizzle-orm/sql"; export type Document = { name: string; lastModified: number; contentType: string; + content: string | null; size: number; perm: string; }; @@ -25,8 +28,8 @@ export type Document = { const log = createLogger("documents"); export async function getDocuments(): Promise { - const cachedDocuments = await cache.getDocuments(); - if (cachedDocuments) return cachedDocuments; + let documents = await db.select().from(documentTable).all(); + if (documents.length) return documents; const headers = new Headers(); headers.append("Accept", "application/json"); @@ -36,10 +39,9 @@ export async function getDocuments(): Promise { headers: headers, }); - const documents = await response.json(); - cache.setDocuments(documents); - - typesense.synchronize(); + documents = await response.json(); + await db.delete(documentTable); + await db.insert(documentTable).values(documents); return documents; } @@ -67,8 +69,10 @@ export function createDocument( } export async function getDocument(name: string): Promise { - const cachedDocument = await cache.getDocument(name); - if (cachedDocument) return cachedDocument; + const documents = await db.select().from(documentTable).where( + eq(documentTable.name, name), + ).limit(1); + if (documents[0]?.content) return documents[0].content; log.debug("fetching document", { name }); const headers = new Headers(); @@ -76,9 +80,9 @@ export async function getDocument(name: string): Promise { const response = await fetch(SILVERBULLET_SERVER + "/" + name, { headers }); const text = await response.text(); - cache.setDocument(name, text); - - typesense.synchronize(); + await db.update(documentTable).set({ + content: text, + }).where(eq(documentTable.name, name)); return text; } diff --git a/lib/cache/image.ts b/lib/image.ts similarity index 100% rename from lib/cache/image.ts rename to lib/image.ts diff --git a/lib/resource/series.ts b/lib/resource/series.ts index 3b4bda2..ff8488b 100644 --- a/lib/resource/series.ts +++ b/lib/resource/series.ts @@ -3,7 +3,6 @@ import { parse, stringify } from "yaml"; import { createCrud } from "@lib/crud.ts"; import { extractHashTags, formatDate } from "@lib/string.ts"; import { fixRenderedMarkdown } from "@lib/helpers.ts"; -import { getThumbhash } from "@lib/cache/image.ts"; export type Series = { id: string; diff --git a/lib/sqlite/schema.ts b/lib/sqlite/schema.ts index b196467..95222a9 100644 --- a/lib/sqlite/schema.ts +++ b/lib/sqlite/schema.ts @@ -1,5 +1,6 @@ import { int, integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; import { sql } from "drizzle-orm/sql"; +import { contentType } from "https://deno.land/std@0.216.0/media_types/content_type.ts"; export const userTable = sqliteTable("user", { id: text() @@ -43,3 +44,12 @@ export const imageTable = sqliteTable("image", { blurhash: text().notNull(), mime: text().notNull(), }); + +export const documentTable = sqliteTable("document", { + name: text().notNull().primaryKey(), + lastModified: integer("last_modified").notNull(), + content: text(), + contentType: text("content_type").notNull(), + size: integer().notNull(), + perm: text().notNull(), +}); diff --git a/routes/api/cache/index.ts b/routes/api/cache/index.ts deleted file mode 100644 index b12f350..0000000 --- a/routes/api/cache/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Handlers } from "$fresh/server.ts"; -import * as cache from "@lib/cache/cache.ts"; - -export const handler: Handlers = { - async DELETE() { - await cache.clearAll(); - return new Response("OK"); - }, -}; diff --git a/routes/api/images/index.ts b/routes/api/images/index.ts index 9ce9eb3..8aba605 100644 --- a/routes/api/images/index.ts +++ b/routes/api/images/index.ts @@ -1,5 +1,5 @@ import { FreshContext, Handlers } from "$fresh/server.ts"; -import * as cache from "@lib/cache/image.ts"; +import { getImageContent } from "@lib/image.ts"; import { SILVERBULLET_SERVER } from "@lib/env.ts"; import { createLogger } from "@lib/log.ts"; import { isLocalImage } from "@lib/string.ts"; @@ -83,7 +83,7 @@ const GET = async ( log.debug("Processing image request:", { imageUrl, params }); - const image = await cache.getImageContent(imageUrl, params); + const image = await getImageContent(imageUrl, params); return new Response(image.content, { headers: { diff --git a/routes/api/tmdb/[id].ts b/routes/api/tmdb/[id].ts index b32a1ed..2e8c255 100644 --- a/routes/api/tmdb/[id].ts +++ b/routes/api/tmdb/[id].ts @@ -1,4 +1,4 @@ -import { HandlerContext, Handlers } from "$fresh/server.ts"; +import { FreshContext, Handlers } from "$fresh/server.ts"; import { getMovie } from "@lib/tmdb.ts"; import * as cache from "@lib/cache/cache.ts"; import { json } from "@lib/helpers.ts"; @@ -12,7 +12,7 @@ const CACHE_INTERVAL = 1000 * 60 * 24 * 30; const GET = async ( _req: Request, - _ctx: HandlerContext, + _ctx: FreshContext, ) => { const id = _ctx.params.id;