diff --git a/package.json b/package.json index 828e426..460364e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "szuru-chrome", - "version": "0.7.6", + "version": "0.7.7", "description": "Import media from various sites into szurubooru.", "author": "neobooru", "license": "MIT", @@ -16,7 +16,7 @@ }, "dependencies": { "axios": "^0.23.0", - "neo-scraper": "^0.4.7", + "neo-scraper": "^0.5.0", "vue": "^2.6.14", "webextension-polyfill": "^0.8.0" }, diff --git a/src/SzuruTypes.ts b/src/SzuruTypes.ts index 27479cc..cfc915e 100644 --- a/src/SzuruTypes.ts +++ b/src/SzuruTypes.ts @@ -97,6 +97,11 @@ export interface Post { comments: any[]; // Comment resource } +export interface SzuruNote { + polygon: number[][]; + text: string; +} + export interface SimilarPost { distance: number; post: Post; diff --git a/src/SzuruWrapper.ts b/src/SzuruWrapper.ts index 00046fc..cbb650a 100644 --- a/src/SzuruWrapper.ts +++ b/src/SzuruWrapper.ts @@ -1,7 +1,16 @@ import axios, { AxiosRequestConfig, CancelToken } from "axios"; -import { ScrapedPost } from "neo-scraper"; import { SzuruSiteConfig } from "./Config"; -import { TagsResult, TagCategoriesResult, Post, Tag, SzuruError, ImageSearchResult, TagFields } from "./SzuruTypes"; +import { + TagsResult, + TagCategoriesResult, + Post, + Tag, + SzuruError, + ImageSearchResult, + TagFields, + SzuruNote +} from "./SzuruTypes"; +import { PostViewModel } from "./ViewModels"; /** * A 1:1 wrapper around the szurubooru API. @@ -61,11 +70,12 @@ export default class SzuruWrapper { return (await this.apiGet("tag-categories")).data; } - async createPost(post: ScrapedPost): Promise { + async createPost(post: PostViewModel): Promise { var obj = { tags: post.tags.map(x => x.name), safety: post.rating, source: post.source, + notes: post.notes.map(note => { polygon: note.polygons, text: note.text }), contentUrl: post.contentUrl }; @@ -83,6 +93,10 @@ export default class SzuruWrapper { return (await this.apiPost("posts/reverse-search", obj)).data; } + static async createFromConfig(siteConfig: SzuruSiteConfig): Promise { + return new SzuruWrapper(siteConfig.domain, siteConfig.username, siteConfig.authToken); + } + private async apiGet( url: string, additionalHeaders: any = {}, @@ -137,8 +151,4 @@ export default class SzuruWrapper { throw error ? error : ex; } } - - static async createFromConfig(siteConfig: SzuruSiteConfig): Promise { - return new SzuruWrapper(siteConfig.domain, siteConfig.username, siteConfig.authToken); - } } diff --git a/src/ViewModels.ts b/src/ViewModels.ts new file mode 100644 index 0000000..ac9e634 --- /dev/null +++ b/src/ViewModels.ts @@ -0,0 +1,49 @@ +import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag } from "neo-scraper"; +import { MicroTag, Tag } from "./SzuruTypes"; + +export class TagViewModel { + public implications: TagViewModel[] = []; + + constructor(public name: string, public category?: BooruTypes.TagCategory, public usages?: number | undefined) {} + + static fromTag(tag: Tag) { + let x = new TagViewModel(tag.names[0], tag.category, tag.usages); + + if (tag.implications) { + x.implications = tag.implications.map(y => TagViewModel.fromMicroTag(y)); + } + + return x; + } + + static fromMicroTag(tag: MicroTag) { + return new TagViewModel(tag.names[0], tag.category, tag.usages); + } + + static fromScapedTag(tag: ScrapedTag): TagViewModel { + return new TagViewModel(tag.name, tag.category); + } +} + +export class PostViewModel { + name: string = ""; + tags: TagViewModel[] = []; + notes: ScrapedNote[]; + contentUrl: string; + pageUrl: string; + contentType: ContentType; + rating: BooruTypes.SafetyRating; + source: string | undefined; + referrer: string | undefined; + + constructor(post: ScrapedPost) { + this.contentUrl = post.contentUrl; + this.pageUrl = post.pageUrl; + this.contentType = post.contentType; + this.rating = post.rating; + this.source = post.source; + this.referrer = post.referrer; + this.tags = post.tags.map(x => TagViewModel.fromScapedTag(x)); + this.notes = post.notes; + } +} diff --git a/src/popup/App.vue b/src/popup/App.vue index bd89f65..ae4cc2c 100644 --- a/src/popup/App.vue +++ b/src/popup/App.vue @@ -127,58 +127,14 @@