From 76d1b1e7687bf172321f4f34a2210de8d25bbbfb Mon Sep 17 00:00:00 2001 From: neobooru <50623835+neobooru@users.noreply.github.com> Date: Fri, 4 Feb 2022 00:54:07 +0100 Subject: [PATCH] Use temp upload for reverse searching and subsequent post creation --- package.json | 3 +-- src/Config.ts | 1 + src/SzuruTypes.ts | 4 ++++ src/SzuruWrapper.ts | 23 +++++++++++++++++++---- src/ViewModels.ts | 1 + src/options/App.vue | 19 ++++++++++++++++--- src/popup/App.vue | 17 ++++++++++++++--- src/scripts/background.ts | 5 +++-- 8 files changed, 59 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index a5876aa..c17511b 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,7 @@ "build:dev": "webpack --config webpack.dev.js", "build-zip": "node scripts/build-zip.js", "sign-xpi": "node scripts/sign-xpi.js", - "watch": "webpack --watch --config webpack.dev.js", - "prepare": "npm run build" + "watch": "webpack --watch --config webpack.dev.js" }, "dependencies": { "axios": "^0.23.0", diff --git a/src/Config.ts b/src/Config.ts index 69b2090..260e8d6 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -13,6 +13,7 @@ export class Config { useOriginalSource: boolean = true; autoSearchSimilar: boolean = false; loadTagCounts: boolean = true; + useContentTokens: boolean = true; sites: Array = []; public async save() { diff --git a/src/SzuruTypes.ts b/src/SzuruTypes.ts index cfc915e..98712c3 100644 --- a/src/SzuruTypes.ts +++ b/src/SzuruTypes.ts @@ -111,3 +111,7 @@ export interface ImageSearchResult { exactPost: Post | null; similarPosts: SimilarPost[]; } + +export interface TemporaryFileUploadResult { + token: string; +} diff --git a/src/SzuruWrapper.ts b/src/SzuruWrapper.ts index 71af247..e168c49 100644 --- a/src/SzuruWrapper.ts +++ b/src/SzuruWrapper.ts @@ -8,7 +8,7 @@ import { SzuruError, ImageSearchResult, TagFields, - SzuruNote + TemporaryFileUploadResult } from "./SzuruTypes"; import { PostViewModel } from "./ViewModels"; @@ -71,14 +71,19 @@ export default class SzuruWrapper { } async createPost(post: PostViewModel): Promise { - var obj = { + var obj = { tags: post.tags.map(x => x.name), safety: post.rating, source: post.source, - notes: post.notes, - contentUrl: post.contentUrl + notes: post.notes }; + if (post.contentToken) { + obj.contentToken = post.contentToken; + } else { + obj.contentUrl = post.contentUrl; + } + console.log("Create new post object"); console.dir(obj); @@ -90,6 +95,16 @@ export default class SzuruWrapper { return (await this.apiPost("posts/reverse-search", obj)).data; } + async reverseSearchToken(contentToken: string): Promise { + var obj = { contentToken }; + return (await this.apiPost("posts/reverse-search", obj)).data; + } + + async uploadTempFile(contentUrl: string): Promise { + var obj = { contentUrl }; + return (await this.apiPost("uploads", obj)).data; + } + static createFromConfig(siteConfig: SzuruSiteConfig): SzuruWrapper | null { return new SzuruWrapper(siteConfig.domain, siteConfig.username, siteConfig.authToken); } diff --git a/src/ViewModels.ts b/src/ViewModels.ts index f123022..4d38e92 100644 --- a/src/ViewModels.ts +++ b/src/ViewModels.ts @@ -30,6 +30,7 @@ export class PostViewModel { tags: TagViewModel[] = []; notes: ScrapedNote[]; contentUrl: string; + contentToken: string | undefined; pageUrl: string; contentType: ContentType; rating: BooruTypes.SafetyRating; diff --git a/src/options/App.vue b/src/options/App.vue index e8ce531..f46c7a5 100644 --- a/src/options/App.vue +++ b/src/options/App.vue @@ -19,7 +19,7 @@
  • @@ -29,7 +29,7 @@

  • @@ -39,7 +39,7 @@

  • @@ -47,6 +47,16 @@ the tag does not yet exist.

  • +
  • + +

    + When reverse searching for a post this will (temporarily) upload the post to the server. This makes creating + the post faster because then the file already exists on the server. +

    +