Skip to content

Commit

Permalink
Merge pull request #9 from Lendruk/develop
Browse files Browse the repository at this point in the history
Release v0.6.0
  • Loading branch information
Lendruk authored Sep 9, 2024
2 parents 69e798a + 8325177 commit 94b4049
Show file tree
Hide file tree
Showing 88 changed files with 2,921 additions and 1,727 deletions.
2 changes: 1 addition & 1 deletion backend/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", "tab"],
"indent": ["off", "tab"],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
CREATE TABLE `loras_to_mediaItems` (
CREATE TABLE IF NOT EXISTS `loras_to_mediaItems` (
`media_item_id` integer NOT NULL,
`lora_id` text NOT NULL,
PRIMARY KEY(`lora_id`, `media_item_id`),
FOREIGN KEY (`media_item_id`) REFERENCES `media_items`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`lora_id`) REFERENCES `sd_loras`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `media_items` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `media_items` (
`id` integer PRIMARY KEY NOT NULL,
`file_name` text NOT NULL,
`type` text NOT NULL,
Expand All @@ -19,8 +19,8 @@ CREATE TABLE `media_items` (
`sd_checkpoint` text,
FOREIGN KEY (`sd_checkpoint`) REFERENCES `sd_checkpoints`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `media_items_metadata` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `media_items_metadata` (
`id` text PRIMARY KEY NOT NULL,
`media_item` integer,
`width` integer NOT NULL,
Expand All @@ -39,26 +39,26 @@ CREATE TABLE `media_items_metadata` (
`denoising_strength` real,
FOREIGN KEY (`media_item`) REFERENCES `media_items`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `playlists` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `playlists` (
`id` integer PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`created_at` integer NOT NULL,
`randomize_order` integer DEFAULT 0 NOT NULL,
`time_per_item` integer DEFAULT 0,
`updated_at` integer
);
--> statement-breakpoint
CREATE TABLE `playlists_media_items` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `playlists_media_items` (
`playlist_id` integer NOT NULL,
`media_item_id` integer NOT NULL,
`item_index` integer NOT NULL,
PRIMARY KEY(`media_item_id`, `playlist_id`),
FOREIGN KEY (`playlist_id`) REFERENCES `playlists`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`media_item_id`) REFERENCES `media_items`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `sd_checkpoints` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `sd_checkpoints` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`path` text NOT NULL,
Expand All @@ -68,8 +68,8 @@ CREATE TABLE `sd_checkpoints` (
`sha256` text NOT NULL,
`preview_image` text
);
--> statement-breakpoint
CREATE TABLE `sd_loras` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `sd_loras` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`path` text NOT NULL,
Expand All @@ -80,8 +80,8 @@ CREATE TABLE `sd_loras` (
`preview_image` text,
`activation_words` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `sd_prompts` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `sd_prompts` (
`id` text PRIMARY KEY NOT NULL,
`name` text,
`preview_image` text,
Expand All @@ -100,37 +100,37 @@ CREATE TABLE `sd_prompts` (
`high_res_upscale_by` real,
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `sd_wildcards` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `sd_wildcards` (
`id` text PRIMARY KEY NOT NULL,
`list_name` text NOT NULL,
`text` text NOT NULL
);
--> statement-breakpoint
CREATE TABLE `tags` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `tags` (
`id` integer PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`color` text NOT NULL,
`parent_id` integer
);
--> statement-breakpoint
CREATE TABLE `tags_to_loras` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `tags_to_loras` (
`tag_id` integer NOT NULL,
`lora_id` text NOT NULL,
PRIMARY KEY(`lora_id`, `tag_id`),
FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`lora_id`) REFERENCES `sd_loras`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `tags_to_media_items` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `tags_to_media_items` (
`tag_id` integer NOT NULL,
`media_item_id` integer NOT NULL,
PRIMARY KEY(`media_item_id`, `tag_id`),
FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`media_item_id`) REFERENCES `media_items`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE TABLE `users` (
--- StatementBreak
CREATE TABLE IF NOT EXISTS `users` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`name` text NOT NULL
);
36 changes: 36 additions & 0 deletions backend/migrations/vault/0.6.0/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ALTER TABLE `media_items` ADD COLUMN original_file_name TEXT DEFAULT NULL;
--- StatementBreak
ALTER TABLE `media_items` ADD COLUMN source TEXT DEFAULT NULL;
--- StatementBreak
CREATE TABLE IF NOT EXISTS `active_watchers` (
`id` text PRIMARY KEY NOT NULL,
`description` text NOT NULL,
`status` text NOT NULL,
`data` text,
`items_per_request` integer NOT NULL DEFAULT 0,
`items_downloaded` integer NOT NULL DEFAULT 0,
`total_items` integer,
`type` text NOT NULL,
`url` text NOT NULL,
`request_interval` integer NOT NULL DEFAULT 0,
`last_requested_at` integer NOT NULL DEFAULT 0,
`time_since_new_items` integer NOT NULL DEFAULT 0,
`inactivity_timeout` integer NOT NULL DEFAULT 0,
`created_at` integer NOT NULL
);
--- StatementBreak
CREATE TABLE IF NOT EXISTS `active_watchers_to_tags` (
`active_watcher_id` text NOT NULL,
`tag_id` text NOT NULL,
PRIMARY KEY(`active_watcher_id`, `tag_id`),
FOREIGN KEY (`active_watcher_id`) REFERENCES `active_watchers`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON UPDATE no action ON DELETE cascade
);
--- StatementBreak
CREATE TABLE IF NOT EXISTS `active_watchers_to_media_items` (
`active_watcher_id` text NOT NULL,
`media_item_id` integer NOT NULL,
PRIMARY KEY(`active_watcher_id`, `media_item_id`),
FOREIGN KEY (`active_watcher_id`) REFERENCES `active_watchers`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`media_item_id`) REFERENCES `media_items`(`id`) ON UPDATE no action ON DELETE cascade
);
41 changes: 41 additions & 0 deletions backend/migrations/vault/0.6.0/migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { eq } from 'drizzle-orm';
import fs from 'fs/promises';
import path from 'path';
import { mediaItems } from '../../../src/db/vault/schema';
import { VaultBase } from '../../../src/lib/VaultBase';
import { mediaService } from '../../../src/services/MediaService';

/**
* Migrates 0.5.0 vaults to 0.6.0
* - Regenerates all .gif thumbnails
*/
export default async (vault: VaultBase) => {
// Regenerate all .gif thumbnails

const images = await vault.db.query.mediaItems.findMany({
where: eq(mediaItems.extension, 'png')
});
for (const potentialGif of images) {
let filePath = path.join(vault.path, 'media', 'images', `${potentialGif.fileName}.png`);
const fileBuffer = await fs.readFile(filePath);
// https://stackoverflow.com/questions/8473703/in-node-js-given-a-url-how-do-i-check-whether-its-a-jpg-png-gif
if (fileBuffer.toString('hex', 0, 4) === '47494638') {
await fs.unlink(filePath);

filePath = filePath.replace('.png', '.gif');
// Delete the old thumbnail
await fs.unlink(
path.join(vault.path, 'media', 'images', '.thumb', `${potentialGif.fileName}.jpg`)
);
await fs.writeFile(filePath, fileBuffer);

await vault.db
.update(mediaItems)
.set({ extension: 'gif' })
.where(eq(mediaItems.id, potentialGif.id));

potentialGif.extension = 'gif';
mediaService.generateItemThumbnail(vault, 'webp', filePath, potentialGif);
}
}
};
5 changes: 5 additions & 0 deletions backend/migrations/vault/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import migration_0_6_0 from './0.6.0/migration';

export default {
'0.6.0': migration_0_6_0
};
Loading

0 comments on commit 94b4049

Please sign in to comment.