Small fixes and update neo-scraper to 0.4.6

next v0.7.4
neobooru 2021-09-12 23:47:20 +02:00
parent 2589af93ea
commit 836219212c
4 changed files with 40 additions and 29 deletions

View File

@ -1,6 +1,6 @@
{
"name": "szuru-chrome",
"version": "0.7.3",
"version": "0.7.4",
"description": "Import media from various sites into szurubooru.",
"author": "neobooru",
"license": "MIT",
@ -17,7 +17,7 @@
},
"dependencies": {
"axios": "^0.21.1",
"neo-scraper": "^0.4.5",
"neo-scraper": "^0.4.6",
"vue": "^2.6.11",
"webextension-polyfill": "^0.3.1"
},

View File

@ -132,7 +132,7 @@ export default class SzuruWrapper {
try {
return await axios(config);
} catch (ex) {
const error = ex.response.data as SzuruError;
const error = ex.response?.data as SzuruError | undefined;
throw error ? error : ex;
}
}

View File

@ -2,7 +2,12 @@
<div class="popup-container">
<div class="popup-messages">
<ul class="messages">
<li v-for="msg in messages" :key="msg.content" :class="getMessageClasses(msg)" v-html="msg.content"></li>
<li
v-for="msg in messages"
:key="msg.content"
:class="getMessageClasses(msg)"
v-html="msg.content"
></li>
</ul>
</div>
@ -128,13 +133,13 @@ import axios, { CancelTokenSource } from "axios";
class TagViewModel {
public implications: TagViewModel[] = [];
constructor(public name: string, public category?: BooruTypes.TagCategory, public usages?: number | undefined) {}
constructor(public name: string, public category?: BooruTypes.TagCategory, public usages?: number | undefined) { }
static fromTag(tag: Tag) {
let x = new TagViewModel(tag.names[0], <BooruTypes.TagCategory>tag.category, tag.usages);
if (tag.implications) {
x.implications = tag.implications.map((x) => TagViewModel.fromMicroTag(x));
x.implications = tag.implications.map((y) => TagViewModel.fromMicroTag(y));
}
return x;
@ -202,7 +207,7 @@ export default Vue.extend({
});
if (activeTabs.length > 0) return activeTabs[0].id!;
throw "No active tab.";
throw new Error("No active tab.");
},
// Try to scrape the post from the page
async grabPost() {
@ -301,7 +306,7 @@ export default Vue.extend({
return msg;
},
// Clear messages of given category. When category is empty clear all messages.
clearMessages(category: string | null) {
clearMessages(category: string | null = null) {
if (category) {
for (let i = 0; i < this.messages.length; i++) {
if (this.messages[i].category == category) {
@ -340,29 +345,35 @@ export default Vue.extend({
this.clearMessages("FIND_SIMILAR");
const msg = this.pushInfo("Searching for similar posts...", "FIND_SIMILAR");
const res = await this.szuru.reverseSearch(this.selectedPost.contentUrl);
if (!res.exactPost && res.similarPosts.length == 0) {
msg.content = "No similar posts found";
} else {
if (res.exactPost) {
msg.content = `<a href='${this.getPostUrl(res.exactPost)}' target='_blank'>
try {
const res = await this.szuru.reverseSearch(this.selectedPost.contentUrl);
if (!res.exactPost && res.similarPosts.length == 0) {
msg.content = "No similar posts found";
} else {
if (res.exactPost) {
msg.content = `<a href='${this.getPostUrl(res.exactPost)}' target='_blank'>
Post already uploaded (${res.exactPost.id})</a>`;
msg.level = "error";
}
for (const similarPost of res.similarPosts) {
// Don't show this message for the exactPost (because we have a different message for that)
if (res.exactPost && res.exactPost.id == similarPost.post.id) {
continue;
msg.level = "error";
}
this.pushInfo(
`<a href='${this.getPostUrl(similarPost.post)}' target='_blank'>Post ${similarPost.post.id}
for (const similarPost of res.similarPosts) {
// Don't show this message for the exactPost (because we have a different message for that)
if (res.exactPost && res.exactPost.id == similarPost.post.id) {
continue;
}
this.pushInfo(
`<a href='${this.getPostUrl(similarPost.post)}' target='_blank'>Post ${similarPost.post.id}
looks ${Math.round(100 - similarPost.distance * 100)}% similar</a>`,
"FIND_SIMILAR"
);
"FIND_SIMILAR"
);
}
}
} catch (ex) {
this.clearMessages();
this.pushError("Error: couldn't reverse search.");
}
},
// Returns ScrapedPost for a contentUrl, or undefined if the given contentUrl does not belong to a ScrapedPost.

View File

@ -2690,10 +2690,10 @@ neo-async@^2.5.0, neo-async@^2.6.1:
resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f"
integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==
neo-scraper@^0.4.5:
version "0.4.5"
resolved "https://registry.yarnpkg.com/neo-scraper/-/neo-scraper-0.4.5.tgz#86c1d1ebb6c04ad607282b08460dd090990dbe20"
integrity sha512-w6xnIv8qKD7ogamhVp6oprNLymtb4bUwnahOiRmEtpxwEx4drzYRDenH7hNFp8MAv6vb2+VUSYgCVwfS6NWpLA==
neo-scraper@^0.4.6:
version "0.4.6"
resolved "https://registry.yarnpkg.com/neo-scraper/-/neo-scraper-0.4.6.tgz#2344c08eb7ddb621a183ed5ef8145a4acaee7407"
integrity sha512-DYfnewkfNd3hBbtRq3EFvd+Dmr50O1zp7Gto0GjyGPb+KaSEoynmgymYUMIxsufVi6VTIaCny6wwE4+agX3iDg==
nice-try@^1.0.4:
version "1.0.5"