From ab6b0186ee78b8ee1248c60441e43a6c0f699d25 Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:12:05 +0200 Subject: [PATCH] Add config migration code This should ensure that each user has the default tag categories when updating from an older version. --- src/api/index.ts | 3 +-- src/config.ts | 10 ---------- src/dynamicStyle.ts | 2 +- src/models/index.ts | 19 ++++++++++++++++++- src/options/App.vue | 11 +++-------- src/popup/pages/PopupMain.vue | 2 +- src/stores/index.ts | 34 +++++++++++++++++++++++++++++++--- 7 files changed, 55 insertions(+), 26 deletions(-) diff --git a/src/api/index.ts b/src/api/index.ts index 4353129..c605a00 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -11,8 +11,7 @@ import { TemporaryFileUploadResult, UpdatePostRequest, } from "./models"; -import { ScrapedPostDetails } from "~/models"; -import { SzuruSiteConfig } from "~/config"; +import { ScrapedPostDetails, SzuruSiteConfig } from "~/models"; /** * A 1:1 wrapper around the szurubooru API. diff --git a/src/config.ts b/src/config.ts index c692847..e69de29 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,10 +0,0 @@ -export class SzuruSiteConfig { - id = window.crypto.randomUUID(); - domain = "https://example.com"; - username = "user"; - authToken = ""; -} - -export class TagCategoryColor { - constructor(public name: string, public color: string) {} -} diff --git a/src/dynamicStyle.ts b/src/dynamicStyle.ts index 263580b..f921abd 100644 --- a/src/dynamicStyle.ts +++ b/src/dynamicStyle.ts @@ -1,4 +1,4 @@ -import { TagCategoryColor } from "./config"; +import { TagCategoryColor } from "./models"; export function makeCssName(prefix: string, name: string) { return prefix + "-" + name.replace(/[^a-z0-9]/g, "_"); diff --git a/src/models/index.ts b/src/models/index.ts index dc2672d..8a069d5 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -1,6 +1,5 @@ import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag } from "neo-scraper"; import { MicroTag, Tag, UpdatePostRequest } from "~/api/models"; -import { SzuruSiteConfig } from "~/config"; export class TagDetails { public implications: TagDetails[] = []; @@ -146,3 +145,21 @@ export class PostUpdateCommandData { export class FetchCommandData { constructor(public readonly url: string, public readonly options: RequestInit | undefined = undefined) {} } + +export class SzuruSiteConfig { + id = window.crypto.randomUUID(); + domain = "https://example.com"; + username = "user"; + authToken = ""; +} + +export class TagCategoryColor { + constructor(public name: string, public color: string) {} +} + +export const getDefaultTagCategories = () => [ + new TagCategoryColor("copyright", "#a0a"), + new TagCategoryColor("character", "#0a0"), + new TagCategoryColor("artist", "#a00"), + new TagCategoryColor("meta", "#f80"), +]; diff --git a/src/options/App.vue b/src/options/App.vue index 0ca2e49..6215bf4 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -1,7 +1,6 @@