Compare commits
38 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
633bf05dad | |
|
|
37b359597c | |
|
|
c17bd87089 | |
|
|
59145cebdc | |
|
|
4895e126fb | |
|
|
a0a0a591bc | |
|
|
381dac72d4 | |
|
|
646241b45f | |
|
|
45f20ebfc8 | |
|
|
3d243252cd | |
|
|
0f83292e86 | |
|
|
be2afe55ff | |
|
|
5101c79c59 | |
|
|
e2bf28a29b | |
|
|
1a6fe13512 | |
|
|
ce6a6c6521 | |
|
|
3aa31955ce | |
|
|
24cec0bd81 | |
|
|
f4a1b2a1ea | |
|
|
e9d37caf7c | |
|
|
afe4ff535b | |
|
|
9e07ee1594 | |
|
|
7c5c4d3ccd | |
|
|
4bea802819 | |
|
|
c08e6473e9 | |
|
|
76a4c01577 | |
|
|
cae923b68a | |
|
|
5ff664e725 | |
|
|
eae1b3949f | |
|
|
9843f0b641 | |
|
|
3d9586147b | |
|
|
4f16088a3b | |
|
|
390d865e5a | |
|
|
1fa42c94a6 | |
|
|
b4e63c8c5e | |
|
|
828e8c5a16 | |
|
|
dfd9c87858 | |
|
|
ee003912d5 |
|
|
@ -27,12 +27,12 @@ runs:
|
||||||
name: Install pnpm
|
name: Install pnpm
|
||||||
id: pnpm-install
|
id: pnpm-install
|
||||||
with:
|
with:
|
||||||
version: 7
|
version: 9
|
||||||
run_install: false
|
run_install: false
|
||||||
|
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
node-version: "16"
|
node-version: "20"
|
||||||
cache: "pnpm"
|
cache: "pnpm"
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ on:
|
||||||
jobs:
|
jobs:
|
||||||
build_chrome:
|
build_chrome:
|
||||||
name: "Build Chrome Extension"
|
name: "Build Chrome Extension"
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
@ -30,14 +30,14 @@ jobs:
|
||||||
- name: Pack ZIP
|
- name: Pack ZIP
|
||||||
run: pnpm pack:zip
|
run: pnpm pack:zip
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Chrome Extension (Unsigned)
|
name: Chrome Extension (Unsigned)
|
||||||
path: extension.zip
|
path: extension.zip
|
||||||
|
|
||||||
build_unlisted_firefox:
|
build_unlisted_firefox:
|
||||||
name: "Build Unlisted Firefox Extension"
|
name: "Build Unlisted Firefox Extension"
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-24.04
|
||||||
# Doesn't really need the Chrome build, but we can reuse its cache.
|
# Doesn't really need the Chrome build, but we can reuse its cache.
|
||||||
needs: build_chrome
|
needs: build_chrome
|
||||||
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
|
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
|
||||||
|
|
@ -60,17 +60,20 @@ jobs:
|
||||||
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
|
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
|
||||||
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
|
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
|
||||||
|
|
||||||
- uses: actions/upload-artifact@v3
|
- name: Rename XPI
|
||||||
|
run: rename.ul szuruchrome_gh- SzuruChrome-v web-ext-artifacts/*.xpi
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: Firefox Extension (Signed)
|
name: Firefox Extension (Signed)
|
||||||
path: web-ext-artifacts/*.xpi
|
path: web-ext-artifacts/*.xpi
|
||||||
|
|
||||||
build_amo_firefox:
|
build_amo_firefox:
|
||||||
name: "Build Firefox Extension for AMO"
|
name: "Build Firefox Extension for AMO"
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-24.04
|
||||||
# Doesn't really need the Chrome build, but we can reuse its cache.
|
# Doesn't really need the Chrome build, but we can reuse its cache.
|
||||||
needs: build_chrome
|
needs: build_chrome
|
||||||
# Only run on master branch AND if tagging or manually dispatching.
|
# Only run (on master branch && if tagged) or (manually dispatching).
|
||||||
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish_amo_listed == true
|
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish_amo_listed == true
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
{
|
{
|
||||||
"recommendations": [
|
"recommendations": ["vue.volar", "dbaeumer.vscode-eslint", "esbenp.prettier-vscode"]
|
||||||
"vue.volar",
|
|
||||||
"dbaeumer.vscode-eslint",
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"typescript.tsdk": "node_modules/typescript/lib",
|
"typescript.tsdk": "node_modules/typescript/lib",
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll.eslint": true
|
"source.fixAll.eslint": "explicit"
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 36 KiB |
86
package.json
86
package.json
|
|
@ -4,7 +4,6 @@
|
||||||
"description": "Import media from various sites into szurubooru.",
|
"description": "Import media from various sites into szurubooru.",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"packageManager": "pnpm@7.8.0",
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*",
|
"dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*",
|
||||||
"dev:prepare": "esno scripts/prepare.ts",
|
"dev:prepare": "esno scripts/prepare.ts",
|
||||||
|
|
@ -20,60 +19,63 @@
|
||||||
"pack:xpi": "cross-env WEB_EXT_ARTIFACTS_DIR=./ web-ext build --source-dir ./extension --filename extension.xpi --overwrite-dest",
|
"pack:xpi": "cross-env WEB_EXT_ARTIFACTS_DIR=./ web-ext build --source-dir ./extension --filename extension.xpi --overwrite-dest",
|
||||||
"start:chromium": "web-ext run --source-dir ./extension --target=chromium",
|
"start:chromium": "web-ext run --source-dir ./extension --target=chromium",
|
||||||
"start:firefox": "web-ext run --source-dir ./extension --target=firefox-desktop",
|
"start:firefox": "web-ext run --source-dir ./extension --target=firefox-desktop",
|
||||||
"sign:firefox": "web-ext sign --use-submission-api --source-dir ./extension",
|
"sign:firefox": "web-ext sign --source-dir ./extension",
|
||||||
"clear": "rimraf extension/dist extension/manifest.json extension.*",
|
"clear": "rimraf extension/dist extension/manifest.json extension.*",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"test": "vitest test"
|
"extlint": "web-ext lint -s extension",
|
||||||
|
"test": "vitest test",
|
||||||
|
"pretty": "prettier -w ."
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.2.2",
|
"axios": "^1.19.0",
|
||||||
"byte-size": "^8.1.1",
|
"byte-size": "^8.2.1",
|
||||||
"deepmerge": "^4.3.1",
|
"deepmerge": "^4.3.1",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.18.1",
|
||||||
"markdown-it": "^13.0.1",
|
"markdown-it": "^14.3.0",
|
||||||
"neo-scraper": "^0.7.3",
|
"neo-scraper": "^0.11.1",
|
||||||
"normalize.css": "^8.0.1",
|
"normalize.css": "^8.0.1",
|
||||||
"pinia": "^2.0.36",
|
"pinia": "^2.3.1",
|
||||||
"primeflex": "^3.3.1",
|
"primeflex": "^3.3.1",
|
||||||
"primevue": "^3.33.0",
|
"primevue": "3.45.0",
|
||||||
"vue-router": "4"
|
"vue-router": "^4.6.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ffflorian/jszip-cli": "^3.1.6",
|
"@ffflorian/jszip-cli": "^3.16.5",
|
||||||
"@fortawesome/fontawesome-svg-core": "^6.2.1",
|
"@fortawesome/fontawesome-svg-core": "^6.7.2",
|
||||||
"@fortawesome/free-solid-svg-icons": "^6.2.1",
|
"@fortawesome/free-solid-svg-icons": "^6.7.2",
|
||||||
"@fortawesome/vue-fontawesome": "^3.0.3",
|
"@fortawesome/vue-fontawesome": "^3.3.3",
|
||||||
"@types/byte-size": "^8.1.0",
|
"@types/byte-size": "^8.1.2",
|
||||||
"@types/fs-extra": "^9.0.13",
|
"@types/fs-extra": "^11.0.4",
|
||||||
"@types/lodash": "^4.14.194",
|
"@types/lodash": "^4.17.25",
|
||||||
"@types/markdown-it": "^12.2.3",
|
"@types/markdown-it": "^13.0.9",
|
||||||
"@types/node": "^18.11.9",
|
"@types/node": "^20.19.43",
|
||||||
"@types/webextension-polyfill": "^0.9.1",
|
"@types/webextension-polyfill": "^0.10.7",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.44.0",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
"@vitejs/plugin-vue": "^3.2.0",
|
"@vitejs/plugin-vue": "^5.2.4",
|
||||||
"@vue/compiler-sfc": "^3.2.45",
|
"@vue/compiler-sfc": "^3.5.41",
|
||||||
"@vue/test-utils": "^2.2.4",
|
"@vue/test-utils": "^2.4.11",
|
||||||
"@vueuse/core": "^9.6.0",
|
"@vueuse/core": "^10.11.1",
|
||||||
"chokidar": "^3.5.3",
|
"chokidar": "^3.6.0",
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"crx": "^5.0.1",
|
"crx": "^5.0.1",
|
||||||
"eslint": "^8.32.0",
|
"eslint": "^8.57.1",
|
||||||
"eslint-plugin-vue": "^9.9.0",
|
"eslint-plugin-vue": "^9.33.0",
|
||||||
"esno": "^0.16.3",
|
"esno": "^4.8.0",
|
||||||
"fs-extra": "^10.1.0",
|
"fs-extra": "^11.4.0",
|
||||||
"jsdom": "^20.0.3",
|
"jsdom": "^23.2.0",
|
||||||
"kolorist": "^1.6.0",
|
"kolorist": "^1.8.0",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
|
"prettier": "^3.9.6",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"sass": "^1.57.1",
|
"sass": "^1.102.0",
|
||||||
"typescript": "^4.9.3",
|
"typescript": "^5.9.3",
|
||||||
"unplugin-auto-import": "^0.12.2",
|
"unplugin-auto-import": "^0.17.8",
|
||||||
"unplugin-vue-components": "^0.23.0",
|
"unplugin-vue-components": "^0.26.0",
|
||||||
"vite": "^3.2.4",
|
"vite": "^5.4.21",
|
||||||
"vitest": "^0.25.3",
|
"vitest": "^1.6.1",
|
||||||
"vue": "^3.2.45",
|
"vue": "^3.5.41",
|
||||||
"vue-eslint-parser": "^9.1.0",
|
"vue-eslint-parser": "^9.4.3",
|
||||||
"web-ext": "^7.5.0",
|
"web-ext": "^8.10.0",
|
||||||
"webextension-polyfill": "^0.10.0"
|
"webextension-polyfill": "^0.10.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10848
pnpm-lock.yaml
10848
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
|
@ -1,9 +1,9 @@
|
||||||
import { resolve } from 'path';
|
import { resolve } from "path";
|
||||||
import { bgCyan, black } from 'kolorist';
|
import { bgCyan, black } from "kolorist";
|
||||||
|
|
||||||
export const port = parseInt(process.env.PORT || '') || 3303;
|
export const port = parseInt(process.env.PORT || "") || 3303;
|
||||||
export const r = (...args: string[]) => resolve(__dirname, '..', ...args);
|
export const r = (...args: string[]) => resolve(__dirname, "..", ...args);
|
||||||
export const isDev = process.env.NODE_ENV !== 'production';
|
export const isDev = process.env.NODE_ENV !== "production";
|
||||||
|
|
||||||
export function log(name: string, message: string) {
|
export function log(name: string, message: string) {
|
||||||
console.log(black(bgCyan(` ${name} `)), message);
|
console.log(black(bgCyan(` ${name} `)), message);
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ import {
|
||||||
UpdatePoolRequest,
|
UpdatePoolRequest,
|
||||||
} from "./models";
|
} from "./models";
|
||||||
import { ScrapedPostDetails, SzuruSiteConfig } from "~/models";
|
import { ScrapedPostDetails, SzuruSiteConfig } from "~/models";
|
||||||
|
import { UploadMode } from "neo-scraper";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 1:1 wrapper around the szurubooru API.
|
* A 1:1 wrapper around the szurubooru API.
|
||||||
|
|
@ -121,7 +122,8 @@ export default class SzurubooruApi {
|
||||||
offset = 0,
|
offset = 0,
|
||||||
limit = 100,
|
limit = 100,
|
||||||
fields?: PoolFields[],
|
fields?: PoolFields[],
|
||||||
cancelToken?: CancelToken): Promise<PoolsResult> {
|
cancelToken?: CancelToken,
|
||||||
|
): Promise<PoolsResult> {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.append("offset", offset.toString());
|
params.append("offset", offset.toString());
|
||||||
params.append("limit", limit.toString());
|
params.append("limit", limit.toString());
|
||||||
|
|
@ -146,11 +148,42 @@ export default class SzurubooruApi {
|
||||||
return (await this.apiPost("posts/reverse-search", obj)).data;
|
return (await this.apiPost("posts/reverse-search", obj)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async uploadTempFile(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
async uploadTempFile(contentUrl: string, uploadMode: UploadMode): Promise<TemporaryFileUploadResult> {
|
||||||
|
// For some sources we need to download the image to the client and then upload it to szurubooru.
|
||||||
|
// We can't just pass the contentUrl because that would trigger the bot/hotlink protection.
|
||||||
|
|
||||||
|
if (uploadMode == "content") {
|
||||||
|
console.log("Upload from content");
|
||||||
|
return this.uploadTempFileFromContent(contentUrl);
|
||||||
|
} else {
|
||||||
|
console.log("Upload from URL");
|
||||||
|
return this.uploadTempFileFromUrl(contentUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async uploadTempFileFromUrl(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
||||||
const obj = { contentUrl };
|
const obj = { contentUrl };
|
||||||
return (await this.apiPost("uploads", obj)).data;
|
return (await this.apiPost("uploads", obj)).data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async uploadTempFileFromContent(contentUrl: string): Promise<TemporaryFileUploadResult> {
|
||||||
|
const content = await (await fetch(contentUrl)).blob();
|
||||||
|
|
||||||
|
const fullUrl = this.apiUrl + "uploads";
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("content", content);
|
||||||
|
|
||||||
|
const config: AxiosRequestConfig = {
|
||||||
|
method: "POST",
|
||||||
|
url: fullUrl,
|
||||||
|
data: formData,
|
||||||
|
};
|
||||||
|
|
||||||
|
config.headers = { ...this.baseHeaders, "Content-Type": "multipart/form-data" };
|
||||||
|
return (await this.execute(config)).data;
|
||||||
|
}
|
||||||
|
|
||||||
static createFromConfig(siteConfig: SzuruSiteConfig): SzurubooruApi {
|
static createFromConfig(siteConfig: SzuruSiteConfig): SzurubooruApi {
|
||||||
return new SzurubooruApi(siteConfig.domain, siteConfig.username, siteConfig.authToken);
|
return new SzurubooruApi(siteConfig.domain, siteConfig.username, siteConfig.authToken);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { encodeTagName, getErrorMessage } from "~/utils";
|
import { encodeTagName, getErrorMessage, getUrl } from "~/utils";
|
||||||
import {
|
import {
|
||||||
BrowserCommand,
|
BrowserCommand,
|
||||||
PostUploadCommandData,
|
PostUploadCommandData,
|
||||||
|
|
@ -19,6 +19,13 @@ if (import.meta.hot) {
|
||||||
import("./contentScriptHMR");
|
import("./contentScriptHMR");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browser.notifications.onClicked.addListener((url) => {
|
||||||
|
if (url) {
|
||||||
|
browser.tabs.create({ url });
|
||||||
|
browser.notifications.clear(url);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
async function uploadPost(data: PostUploadCommandData) {
|
async function uploadPost(data: PostUploadCommandData) {
|
||||||
const info: PostUploadInfo = {
|
const info: PostUploadInfo = {
|
||||||
state: "uploading",
|
state: "uploading",
|
||||||
|
|
@ -36,6 +43,12 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
pushInfo();
|
pushInfo();
|
||||||
|
|
||||||
const contentToken = data.post.instanceSpecificData[data.selectedSite.id]?.contentToken;
|
const contentToken = data.post.instanceSpecificData[data.selectedSite.id]?.contentToken;
|
||||||
|
|
||||||
|
if (!contentToken) {
|
||||||
|
// TODO: If donmai URL is the source then we need to do the uploadTempFileFromContent here!
|
||||||
|
console.log("contentToken is undefined. This could be a problem for some sources!");
|
||||||
|
}
|
||||||
|
|
||||||
const createdPost = await szuru.createPost(data.post, contentToken);
|
const createdPost = await szuru.createPost(data.post, contentToken);
|
||||||
|
|
||||||
info.state = "uploaded";
|
info.state = "uploaded";
|
||||||
|
|
@ -98,7 +111,7 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
} else {
|
} else {
|
||||||
// Pool exists, so add it to the existing pool.
|
// Pool exists, so add it to the existing pool.
|
||||||
const existingPool = existingPools.results[0];
|
const existingPool = existingPools.results[0];
|
||||||
const posts = existingPool.posts.map(x => x.id);
|
const posts = existingPool.posts.map((x) => x.id);
|
||||||
posts.push(createdPost.id);
|
posts.push(createdPost.id);
|
||||||
|
|
||||||
console.log(`Adding post ${createdPost.id} to existing pool ${existingPool.id}`);
|
console.log(`Adding post ${createdPost.id} to existing pool ${existingPool.id}`);
|
||||||
|
|
@ -111,6 +124,16 @@ async function uploadPost(data: PostUploadCommandData) {
|
||||||
await szuru.updatePool(existingPool.id, updateRequest);
|
await szuru.updatePool(existingPool.id, updateRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.sendNotifications && browser.notifications) {
|
||||||
|
const createdPostUrl = getUrl(data.selectedSite.domain, "post", createdPost.id.toString());
|
||||||
|
browser.notifications.create(createdPostUrl, {
|
||||||
|
type: "basic",
|
||||||
|
iconUrl: browser.runtime.getURL("assets/icon-128.png"),
|
||||||
|
title: data.selectedSite.domain,
|
||||||
|
message: `Uploaded ${data.post.contentUrl}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
if (ex.name && ex.name == "PostAlreadyUploadedError") {
|
if (ex.name && ex.name == "PostAlreadyUploadedError") {
|
||||||
|
|
|
||||||
|
|
@ -99,9 +99,14 @@ watch(props, (newValue) => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="autocomplete-items" v-bind:class="{ show: autocompleteShown }">
|
<div class="autocomplete-items" v-bind:class="{ show: autocompleteShown }">
|
||||||
<div v-for="(item, idx) in autocompleteItems" @click="onClickAutocompleteItem(item)" :key="item.name" :class="{
|
<div
|
||||||
|
v-for="(item, idx) in autocompleteItems"
|
||||||
|
@click="onClickAutocompleteItem(item)"
|
||||||
|
:key="item.name"
|
||||||
|
:class="{
|
||||||
active: idx == autocompleteIndex,
|
active: idx == autocompleteIndex,
|
||||||
}">
|
}"
|
||||||
|
>
|
||||||
<slot :item="item"></slot>
|
<slot :item="item"></slot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,8 @@ defineEmits(["removePool"]);
|
||||||
<li v-for="pool in pools" :key="pool.name">
|
<li v-for="pool in pools" :key="pool.name">
|
||||||
<a v-if="showRemovePool" class="remove-tag" @click="$emit('removePool', pool)">x</a>
|
<a v-if="showRemovePool" class="remove-tag" @click="$emit('removePool', pool)">x</a>
|
||||||
<span class="tag-general" v-html="breakTagName(pool.name)"></span>
|
<span class="tag-general" v-html="breakTagName(pool.name)"></span>
|
||||||
<span v-if="showPostCount" class="tag-usages tag-usages-reserve-space">{{ pool.postCount ? pool.postCount : ""
|
<span v-if="showPostCount" class="tag-usages tag-usages-reserve-space">{{
|
||||||
|
pool.postCount ? pool.postCount : ""
|
||||||
}}</span>
|
}}</span>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,7 @@ function addPoolFromCurrentInput(input: string) {
|
||||||
|
|
||||||
async function autocompletePopulator(input: string, ct: CancelToken) {
|
async function autocompletePopulator(input: string, ct: CancelToken) {
|
||||||
const query = decodeURIComponent(`*${encodeTagName(input)}*`);
|
const query = decodeURIComponent(`*${encodeTagName(input)}*`);
|
||||||
const res = await props.szuru?.getPools(
|
const res = await props.szuru?.getPools(query, 0, 100, ["id", "names", "category", "description", "postCount"], ct);
|
||||||
query,
|
|
||||||
0,
|
|
||||||
100,
|
|
||||||
["id", "names", "category", "description", "postCount"],
|
|
||||||
ct,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
// TODO: Maybe search on hamming distance or something?
|
// TODO: Maybe search on hamming distance or something?
|
||||||
|
|
@ -40,8 +34,13 @@ async function autocompletePopulator(input: string, ct: CancelToken) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AutocompleteInput :autocomplete-items="autocompleteItems" @add-item="addPool"
|
<AutocompleteInput
|
||||||
@add-from-current-input="addPoolFromCurrentInput" @autocomplete-populator="autocompletePopulator" v-slot="slotProps">
|
:autocomplete-items="autocompleteItems"
|
||||||
|
@add-item="addPool"
|
||||||
|
@add-from-current-input="addPoolFromCurrentInput"
|
||||||
|
@autocomplete-populator="autocompletePopulator"
|
||||||
|
v-slot="slotProps"
|
||||||
|
>
|
||||||
<span :class="getTagClasses(slotProps.item)">{{ slotProps.item.name }}</span>
|
<span :class="getTagClasses(slotProps.item)">{{ slotProps.item.name }}</span>
|
||||||
<span class="tag-usages">{{ slotProps.item.usages ? slotProps.item.usages : "" }}</span>
|
<span class="tag-usages">{{ slotProps.item.usages ? slotProps.item.usages : "" }}</span>
|
||||||
</AutocompleteInput>
|
</AutocompleteInput>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@
|
||||||
import { ScrapedNote } from "neo-scraper";
|
import { ScrapedNote } from "neo-scraper";
|
||||||
|
|
||||||
class Point {
|
class Point {
|
||||||
constructor(public x: any, public y: any) {}
|
constructor(
|
||||||
|
public x: any,
|
||||||
|
public y: any,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Copied from old client
|
// HACK: Copied from old client
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,7 @@ function addTagFromCurrentInput(input: string) {
|
||||||
|
|
||||||
async function autocompletePopulator(input: string, ct: CancelToken) {
|
async function autocompletePopulator(input: string, ct: CancelToken) {
|
||||||
const query = decodeURIComponent(`*${encodeTagName(input)}* sort:usages`);
|
const query = decodeURIComponent(`*${encodeTagName(input)}* sort:usages`);
|
||||||
const res = await props.szuru?.getTags(
|
const res = await props.szuru?.getTags(query, 0, 100, ["names", "category", "usages", "implications"], ct);
|
||||||
query,
|
|
||||||
0,
|
|
||||||
100,
|
|
||||||
["names", "category", "usages", "implications"],
|
|
||||||
ct
|
|
||||||
);
|
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
// TODO: Maybe search on hamming distance or something?
|
// TODO: Maybe search on hamming distance or something?
|
||||||
|
|
@ -41,8 +35,13 @@ async function autocompletePopulator(input: string, ct: CancelToken) {
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AutocompleteInput :autocomplete-items="autocompleteItems" @add-item="addTag"
|
<AutocompleteInput
|
||||||
@add-from-current-input="addTagFromCurrentInput" @autocomplete-populator="autocompletePopulator" v-slot="slotProps">
|
:autocomplete-items="autocompleteItems"
|
||||||
|
@add-item="addTag"
|
||||||
|
@add-from-current-input="addTagFromCurrentInput"
|
||||||
|
@autocomplete-populator="autocompletePopulator"
|
||||||
|
v-slot="slotProps"
|
||||||
|
>
|
||||||
<span :class="getTagClasses(slotProps.item)">{{ slotProps.item.name }}</span>
|
<span :class="getTagClasses(slotProps.item)">{{ slotProps.item.name }}</span>
|
||||||
<span class="tag-usages">{{ slotProps.item.usages ? slotProps.item.usages : "" }}</span>
|
<span class="tag-usages">{{ slotProps.item.usages ? slotProps.item.usages : "" }}</span>
|
||||||
</AutocompleteInput>
|
</AutocompleteInput>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export async function getManifest() {
|
||||||
page: "./dist/background/index.html",
|
page: "./dist/background/index.html",
|
||||||
// persistent: false,
|
// persistent: false,
|
||||||
},
|
},
|
||||||
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "<all_urls>"],
|
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "notifications", "<all_urls>"],
|
||||||
content_scripts: [
|
content_scripts: [
|
||||||
{
|
{
|
||||||
matches: ["http://*/*", "https://*/*"],
|
matches: ["http://*/*", "https://*/*"],
|
||||||
|
|
@ -44,6 +44,10 @@ export async function getManifest() {
|
||||||
manifest.browser_specific_settings = {
|
manifest.browser_specific_settings = {
|
||||||
gecko: {
|
gecko: {
|
||||||
id: `{${process.env.SZ_GECKO_ID}}`,
|
id: `{${process.env.SZ_GECKO_ID}}`,
|
||||||
|
strict_min_version: "113.0",
|
||||||
|
},
|
||||||
|
gecko_android: {
|
||||||
|
strict_min_version: "113.0",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,14 @@
|
||||||
import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag } from "neo-scraper";
|
import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag, UploadMode } from "neo-scraper";
|
||||||
import { MicroTag, Pool, Tag, UpdatePostRequest } from "~/api/models";
|
import { MicroTag, Pool, Tag, UpdatePostRequest } from "~/api/models";
|
||||||
|
|
||||||
export class TagDetails {
|
export class TagDetails {
|
||||||
public implications: TagDetails[] = [];
|
public implications: TagDetails[] = [];
|
||||||
|
|
||||||
constructor(public names: string[], public category?: string, public usages?: number) { }
|
constructor(
|
||||||
|
public names: string[],
|
||||||
|
public category?: string,
|
||||||
|
public usages?: number,
|
||||||
|
) {}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.names[0];
|
return this.names[0];
|
||||||
|
|
@ -30,7 +34,11 @@ export class TagDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PoolDetails {
|
export class PoolDetails {
|
||||||
constructor(public names: string[], public category?: string, public postCount?: number) { }
|
constructor(
|
||||||
|
public names: string[],
|
||||||
|
public category?: string,
|
||||||
|
public postCount?: number,
|
||||||
|
) {}
|
||||||
|
|
||||||
get name() {
|
get name() {
|
||||||
return this.names[0];
|
return this.names[0];
|
||||||
|
|
@ -65,7 +73,8 @@ export class ScrapedPostDetails {
|
||||||
contentType: ContentType;
|
contentType: ContentType;
|
||||||
contentSubType: string | undefined;
|
contentSubType: string | undefined;
|
||||||
rating: BooruTypes.SafetyRating;
|
rating: BooruTypes.SafetyRating;
|
||||||
source = "";
|
source;
|
||||||
|
uploadMode: UploadMode;
|
||||||
referrer?: string;
|
referrer?: string;
|
||||||
resolution?: [number, number];
|
resolution?: [number, number];
|
||||||
instanceSpecificData: MappedInstanceSpecificData = {};
|
instanceSpecificData: MappedInstanceSpecificData = {};
|
||||||
|
|
@ -82,6 +91,7 @@ export class ScrapedPostDetails {
|
||||||
this.tags = post.tags.map((x) => TagDetails.fromScapedTag(x));
|
this.tags = post.tags.map((x) => TagDetails.fromScapedTag(x));
|
||||||
this.notes = post.notes;
|
this.notes = post.notes;
|
||||||
this.resolution = post.resolution;
|
this.resolution = post.resolution;
|
||||||
|
this.uploadMode = post.uploadMode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +106,10 @@ export interface SimpleSimilarPost {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SimilarPostInfo {
|
export class SimilarPostInfo {
|
||||||
constructor(public readonly id: number, public readonly percentage: number) { }
|
constructor(
|
||||||
|
public readonly id: number,
|
||||||
|
public readonly percentage: number,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PostUploadState = "uploading" | "uploaded" | "error";
|
export type PostUploadState = "uploading" | "uploaded" | "error";
|
||||||
|
|
@ -132,11 +145,19 @@ export class BrowserCommand<T = any> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class PostUploadCommandData {
|
export class PostUploadCommandData {
|
||||||
constructor(public readonly post: ScrapedPostDetails, public readonly selectedSite: SzuruSiteConfig) { }
|
constructor(
|
||||||
|
public readonly post: ScrapedPostDetails,
|
||||||
|
public readonly selectedSite: SzuruSiteConfig,
|
||||||
|
public readonly sendNotifications: boolean,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetPostUploadInfoData {
|
export class SetPostUploadInfoData {
|
||||||
constructor(public instanceId: string, public postId: string, public info: PostUploadInfo) { }
|
constructor(
|
||||||
|
public instanceId: string,
|
||||||
|
public postId: string,
|
||||||
|
public info: PostUploadInfo,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SetExactPostId {
|
export class SetExactPostId {
|
||||||
|
|
@ -156,7 +177,10 @@ export class PostUpdateCommandData {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FetchCommandData {
|
export class FetchCommandData {
|
||||||
constructor(public readonly url: string, public readonly options: RequestInit | undefined = undefined) { }
|
constructor(
|
||||||
|
public readonly url: string,
|
||||||
|
public readonly options: RequestInit | undefined = undefined,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SzuruSiteConfig {
|
export class SzuruSiteConfig {
|
||||||
|
|
@ -167,7 +191,10 @@ export class SzuruSiteConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TagCategoryColor {
|
export class TagCategoryColor {
|
||||||
constructor(public name: string, public color: string) { }
|
constructor(
|
||||||
|
public name: string,
|
||||||
|
public color: string,
|
||||||
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getDefaultTagCategories = () => [
|
export const getDefaultTagCategories = () => [
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,11 @@ import TabView from "primevue/tabview";
|
||||||
import TabPanel from "primevue/tabpanel";
|
import TabPanel from "primevue/tabpanel";
|
||||||
import DataTable from "primevue/datatable";
|
import DataTable from "primevue/datatable";
|
||||||
import Column from "primevue/column";
|
import Column from "primevue/column";
|
||||||
import { SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
|
import { TagDetails, SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
|
||||||
import SzurubooruApi from "~/api";
|
import SzurubooruApi from "~/api";
|
||||||
|
|
||||||
|
type StatusType = "success" | "error" | "quiet";
|
||||||
|
|
||||||
const statusText = ref("");
|
const statusText = ref("");
|
||||||
const statusType = ref("status-quiet");
|
const statusType = ref("status-quiet");
|
||||||
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION ?? browser.runtime.getManifest().version);
|
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION ?? browser.runtime.getManifest().version);
|
||||||
|
|
@ -26,9 +28,7 @@ const selectedSite = computed(() => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
type StatusType = "success" | "error" | "quiet";
|
const mode = useColorMode({ emitAuto: true });
|
||||||
|
|
||||||
let mode = useColorMode({ emitAuto: true });
|
|
||||||
|
|
||||||
async function testConnection() {
|
async function testConnection() {
|
||||||
if (
|
if (
|
||||||
|
|
@ -102,6 +102,14 @@ async function importTagCategoriesFromInstance() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addTagIgnore() {
|
||||||
|
cfg.value.tagIgnores.push(new TagDetails([""]));
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetTagIgnores() {
|
||||||
|
cfg.value.tagIgnores.splice(0);
|
||||||
|
}
|
||||||
|
|
||||||
// For debugging
|
// For debugging
|
||||||
const wnd = window as any;
|
const wnd = window as any;
|
||||||
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
|
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
|
||||||
|
|
@ -110,33 +118,12 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="content-holder">
|
<div class="content-holder">
|
||||||
<div class="content-wrapper flex flex-column gap-3">
|
<div class="content-wrapper flex flex-auto flex-column gap-3">
|
||||||
<div><strong>SzuruChrome Settings</strong></div>
|
<div><strong>SzuruChrome Settings</strong></div>
|
||||||
|
|
||||||
<TabView>
|
<TabView>
|
||||||
<TabPanel header="General">
|
<TabPanel header="General">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<div class="col-12 md:col-6">
|
|
||||||
<label>Theme</label>
|
|
||||||
<select v-model="mode">
|
|
||||||
<option value="auto">System</option>
|
|
||||||
<option value="light">Light</option>
|
|
||||||
<option value="dark">Dark</option>
|
|
||||||
</select>
|
|
||||||
<p class="hint">This setting auto-saves.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
|
||||||
<label>
|
|
||||||
<input type="checkbox" v-model="cfg.autoSearchSimilar" />
|
|
||||||
Automatically search for similar posts
|
|
||||||
</label>
|
|
||||||
<p class="hint">
|
|
||||||
Automatically start searching for similar posts when opening the popup. Enabling this option will hide
|
|
||||||
the "Find Similar" button.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
<div class="col-12 md:col-6">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" v-model="cfg.addPageUrlToSource" />
|
<input type="checkbox" v-model="cfg.addPageUrlToSource" />
|
||||||
|
|
@ -160,6 +147,53 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 md:col-6">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" v-model="cfg.alwaysUploadAsContent" />
|
||||||
|
Always upload as content
|
||||||
|
</label>
|
||||||
|
<p class="hint">This will always upload the image content directly, instead of as an URL</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 md:col-6">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" v-model="cfg.sendUploadNotifications" />
|
||||||
|
Send browser notifications after uploading
|
||||||
|
</label>
|
||||||
|
<p class="hint">
|
||||||
|
This will send a browser notification after a successful upload. Clicking the notification will open the
|
||||||
|
uploaded post in a new tab.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<span class="col-12 status-quiet">{{ versionInfo }}</span>
|
||||||
|
</div>
|
||||||
|
</TabPanel>
|
||||||
|
|
||||||
|
<TabPanel header="Interface">
|
||||||
|
<div class="grid">
|
||||||
|
<div class="col-12 md:col-6 mb-2">
|
||||||
|
<label>Theme</label>
|
||||||
|
<select v-model="mode">
|
||||||
|
<option value="auto">System</option>
|
||||||
|
<option value="light">Light</option>
|
||||||
|
<option value="dark">Dark</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="grid">
|
||||||
|
<div class="col-12 md:col-6">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" v-model="cfg.autoSearchSimilar" />
|
||||||
|
Automatically search for similar posts
|
||||||
|
</label>
|
||||||
|
<p class="hint">
|
||||||
|
Automatically start searching for similar posts when opening the popup. Enabling this option will hide
|
||||||
|
the "Find Similar" button.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="col-12 md:col-6">
|
<div class="col-12 md:col-6">
|
||||||
<label>
|
<label>
|
||||||
<input type="checkbox" v-model="cfg.loadTagCounts" />
|
<input type="checkbox" v-model="cfg.loadTagCounts" />
|
||||||
|
|
@ -171,14 +205,33 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<span class="col-12 status-quiet">{{ versionInfo }}</span>
|
<div class="col-12 md:col-6">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" v-model="cfg.popup.showSource" />
|
||||||
|
Show source textbox in popup
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 md:col-6">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" v-model="cfg.popup.showPools" />
|
||||||
|
Show pools in popup
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-12 md:col-6">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" v-model="cfg.popup.showInstancePicker" />
|
||||||
|
Show instance picker in popup
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
<TabPanel header="Instances">
|
<TabPanel header="Instances">
|
||||||
<div class="formgrid grid">
|
<div class="formgrid grid">
|
||||||
<div class="field col-12">
|
<div class="field col-12">
|
||||||
<label>Szurubooru Instances</label>
|
<label>Selected Szurubooru Instance</label>
|
||||||
|
|
||||||
<div class="flex gap-1">
|
<div class="flex gap-1">
|
||||||
<select v-model="cfg.selectedSiteId">
|
<select v-model="cfg.selectedSiteId">
|
||||||
|
|
@ -223,6 +276,7 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
<TabPanel header="Tags">
|
<TabPanel header="Tags">
|
||||||
|
<div class="separated-content">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<DataTable :value="cfg.tagCategories" table-class="col-12" style="width: 100%">
|
<DataTable :value="cfg.tagCategories" table-class="col-12" style="width: 100%">
|
||||||
<Column v-for="col of columns" :key="col.field" :field="col.field" :header="col.header">
|
<Column v-for="col of columns" :key="col.field" :field="col.field" :header="col.header">
|
||||||
|
|
@ -263,12 +317,54 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
|
||||||
|
|
||||||
<!-- TODO: Tag category colors -->
|
<!-- TODO: Tag category colors -->
|
||||||
|
|
||||||
<!-- TODO: Tag ignore list -->
|
<div class="grid">
|
||||||
|
<DataTable :value="cfg.tagIgnores" table-class="col-12" style="width: 100%">
|
||||||
|
<Column field="names" header="Tags to ignore">
|
||||||
|
<template #body="{ data, field }">
|
||||||
|
<input type="text" :name="field" v-model="data[field][0]" />
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
|
||||||
|
<Column field="remove">
|
||||||
|
<template #body="{ index }">
|
||||||
|
<a class="color-primary cursor-pointer" @click="() => cfg.tagIgnores.splice(index, 1)">Remove</a>
|
||||||
|
</template>
|
||||||
|
</Column>
|
||||||
|
</DataTable>
|
||||||
|
|
||||||
|
<div class="col-12 flex flex-wrap grid grid-nogutter gap-1">
|
||||||
|
<button class="primary" @click="addTagIgnore">Add tag</button>
|
||||||
|
<button class="bg-danger sm:ml-auto" @click="resetTagIgnores">Clear</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- TODO: Category ignore list -->
|
<!-- TODO: Category ignore list -->
|
||||||
|
</div>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
<!-- TODO: Settings import/export? -->
|
<!-- <TabPanel header="About">
|
||||||
|
<div class="grid">
|
||||||
|
<div v-for="engine in scraper.engines" :key="engine.name" class="col-12 md:col-4 flex flex-column">
|
||||||
|
<span class="font-bold">{{ engine.name }}</span>
|
||||||
|
<span>Features: {{ engine.features.join(", ") }}</span>
|
||||||
|
<span>Hosts: {{ engine.supportedHosts.join(", ") }}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabPanel> -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<TabPanel header="Developer">
|
||||||
|
<div class="flex flex-column gap-2">
|
||||||
|
<b>Config</b>
|
||||||
|
<Textarea v-model="configText" autoResize rows="16" />
|
||||||
|
|
||||||
|
<div class="flex flex-wrap gap-1">
|
||||||
|
<button class="primary" @click="showConfig">Show config</button>
|
||||||
|
<button class="bg-danger" @click="importConfig">Import config</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TabPanel>
|
||||||
|
-->
|
||||||
</TabView>
|
</TabView>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ watch(
|
||||||
(value) => {
|
(value) => {
|
||||||
el = refreshTagCategoryColorMap(value.tagCategories, el);
|
el = refreshTagCategoryColorMap(value.tagCategories, el);
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
|
@ -93,7 +93,7 @@ onMounted(() => {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
{ urls: ["<all_urls>"] },
|
{ urls: ["<all_urls>"] },
|
||||||
extraInfoSpec
|
extraInfoSpec,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
<!DOCTYPE html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { Post, UpdatePostRequest } from "~/api/models";
|
||||||
import { isMobile } from "~/env";
|
import { isMobile } from "~/env";
|
||||||
import { BrowserCommand, PostUpdateCommandData, TagDetails } from "~/models";
|
import { BrowserCommand, PostUpdateCommandData, TagDetails } from "~/models";
|
||||||
import { cfg, useMergeStore, usePopupStore } from "~/stores";
|
import { cfg, useMergeStore, usePopupStore } from "~/stores";
|
||||||
import { emptyPost, getUrl } from "~/utils";
|
import { emptyPost, ensurePostHasContentToken, getUrl } from "~/utils";
|
||||||
|
|
||||||
const props = defineProps(["siteId", "postId"]);
|
const props = defineProps(["siteId", "postId"]);
|
||||||
const merge = useMergeStore();
|
const merge = useMergeStore();
|
||||||
|
|
@ -129,7 +129,7 @@ async function mergeChanges() {
|
||||||
if (
|
if (
|
||||||
!isEqual(
|
!isEqual(
|
||||||
newTags,
|
newTags,
|
||||||
existingPostRo.tags.map((x) => x.names[0])
|
existingPostRo.tags.map((x) => x.names[0]),
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
req.tags = newTags;
|
req.tags = newTags;
|
||||||
|
|
@ -140,7 +140,10 @@ async function mergeChanges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageToKeep.value == "new") {
|
if (imageToKeep.value == "new") {
|
||||||
req.contentUrl = scrapedPost?.contentUrl;
|
// In practice this should not be needed, because finding similar posts requires the use of content tokens.
|
||||||
|
// So if a similar post is found, it means that a contentToken has already been set.
|
||||||
|
await ensurePostHasContentToken(szuru, scrapedPost, cfg);
|
||||||
|
req.contentToken = scrapedPost.instanceSpecificData[cfg.value.selectedSiteId!].contentToken!;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!req.safety && !req.source && !(req.contentUrl || req.contentToken) && req.tags === undefined) {
|
if (!req.safety && !req.source && !(req.contentUrl || req.contentToken) && req.tags === undefined) {
|
||||||
|
|
@ -165,7 +168,7 @@ watch(
|
||||||
// TODO: Implement this.
|
// TODO: Implement this.
|
||||||
sourcesAdded.value = 0;
|
sourcesAdded.value = 0;
|
||||||
sourcesRemoved.value = 0;
|
sourcesRemoved.value = 0;
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -176,7 +179,7 @@ watch(
|
||||||
} else if (existingPostRo) {
|
} else if (existingPostRo) {
|
||||||
tagsToAdd.splice(0);
|
tagsToAdd.splice(0);
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -187,7 +190,7 @@ watch(
|
||||||
} else if (existingPostRo) {
|
} else if (existingPostRo) {
|
||||||
post.value.source = existingPostRo.source;
|
post.value.source = existingPostRo.source;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
@ -198,7 +201,7 @@ watch(
|
||||||
} else if (existingPostRo) {
|
} else if (existingPostRo) {
|
||||||
post.value.safety = existingPostRo.safety;
|
post.value.safety = existingPostRo.safety;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
import { useDark } from "@vueuse/core";
|
import { useDark } from "@vueuse/core";
|
||||||
import { cloneDeep } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import { ScrapeResults } from "neo-scraper";
|
import { ScrapeResults } from "neo-scraper";
|
||||||
import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary } from "~/utils";
|
import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary, ensurePostHasContentToken } from "~/utils";
|
||||||
import {
|
import {
|
||||||
BrowserCommand,
|
BrowserCommand,
|
||||||
ScrapedPostDetails,
|
ScrapedPostDetails,
|
||||||
|
|
@ -14,7 +14,6 @@ import {
|
||||||
SzuruSiteConfig,
|
SzuruSiteConfig,
|
||||||
PoolDetails,
|
PoolDetails,
|
||||||
} from "~/models";
|
} from "~/models";
|
||||||
import { ImageSearchResult } from "~/api/models";
|
|
||||||
import { isMobile } from "~/env";
|
import { isMobile } from "~/env";
|
||||||
import { DeepReadonly } from "vue";
|
import { DeepReadonly } from "vue";
|
||||||
import { cfg, usePopupStore } from "~/stores";
|
import { cfg, usePopupStore } from "~/stores";
|
||||||
|
|
@ -74,40 +73,56 @@ function openOptionsPage() {
|
||||||
browser.runtime.openOptionsPage();
|
browser.runtime.openOptionsPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getActiveTabId(): Promise<number> {
|
async function getSelectedTabIds(): Promise<number[]> {
|
||||||
const activeTabs = await browser.tabs.query({
|
const selectedTabs = await browser.tabs.query({
|
||||||
active: true,
|
highlighted: true,
|
||||||
currentWindow: true,
|
currentWindow: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (activeTabs.length > 0 && activeTabs[0].id) return activeTabs[0].id;
|
if (selectedTabs.length > 0 && selectedTabs[0].id) {
|
||||||
|
return selectedTabs.filter((tab) => tab.id).map((tab) => tab.id as number);
|
||||||
|
}
|
||||||
throw new Error("No active tab.");
|
throw new Error("No active tab.");
|
||||||
}
|
}
|
||||||
|
|
||||||
async function grabPost() {
|
async function grabPost() {
|
||||||
// Get active tab
|
// Get active tab
|
||||||
const activeTabId = await getActiveTabId();
|
const selectedTabIds = await getSelectedTabIds();
|
||||||
|
|
||||||
// Send 'grab_post' to the content script on the active tab
|
let scrapeResults: ScrapeResults = new ScrapeResults();
|
||||||
const x = await browser.tabs.sendMessage(activeTabId, new BrowserCommand("grab_post"));
|
for (const selectedTabId of selectedTabIds) {
|
||||||
|
// Send 'grab_post' to the content script on the active tabs
|
||||||
|
const x = await browser.tabs.sendMessage(selectedTabId, new BrowserCommand("grab_post"));
|
||||||
// We need to create a new ScrapeResults object and fill it with our data, because the get_posts()
|
// We need to create a new ScrapeResults object and fill it with our data, because the get_posts()
|
||||||
// method gets 'lost' when sent from the contentscript to the popup (it gets JSON.stringified and any prototype defines are lost there)
|
// method gets 'lost' when sent from the contentscript to the popup (it gets JSON.stringified and any prototype defines are lost there)
|
||||||
const res = Object.assign(new ScrapeResults(), x);
|
const results: ScrapeResults = Object.assign(new ScrapeResults(), x);
|
||||||
|
|
||||||
console.dir(res);
|
for (const result of results.results) {
|
||||||
|
const res = scrapeResults.results.find((r) => r.engine === result.engine);
|
||||||
|
if (res) res.posts.push(...result.posts);
|
||||||
|
else scrapeResults.results.push(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.dir(scrapeResults);
|
||||||
|
|
||||||
// Clear current posts array
|
// Clear current posts array
|
||||||
pop.posts.splice(0);
|
pop.posts.splice(0);
|
||||||
|
|
||||||
for (const result of res.results) {
|
for (const result of scrapeResults.results) {
|
||||||
for (const i in result.posts) {
|
for (const i in result.posts) {
|
||||||
const vm = new ScrapedPostDetails(result.posts[i]);
|
const vm = new ScrapedPostDetails(result.posts[i]);
|
||||||
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
|
const name = result.posts[i].name ?? `Post ${parseInt(i) + 1}`; // parseInt() is required!
|
||||||
|
vm.name = `[${result.engine}] ${name}`;
|
||||||
|
|
||||||
if (!cfg.value.addAllParsedTags) {
|
if (!cfg.value.addAllParsedTags) {
|
||||||
vm.tags.splice(0);
|
vm.tags.splice(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cfg.value.alwaysUploadAsContent && vm.name !== "[fallback] Upload as URL") {
|
||||||
|
vm.uploadMode = "content";
|
||||||
|
}
|
||||||
|
|
||||||
// Add current pageUrl to the source if either
|
// Add current pageUrl to the source if either
|
||||||
// a. user has addPageUrlToSource set to true
|
// a. user has addPageUrlToSource set to true
|
||||||
// b. source is empty
|
// b. source is empty
|
||||||
|
|
@ -121,6 +136,14 @@ async function grabPost() {
|
||||||
vm.instanceSpecificData[site.id] = {};
|
vm.instanceSpecificData[site.id] = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove ignored tags
|
||||||
|
// The complexity for this is quite bad but all the other ways I tried were even worse
|
||||||
|
vm.tags = vm.tags.filter((tag) =>
|
||||||
|
cfg.value.tagIgnores.every(
|
||||||
|
(ignoredTag) => tag.name != ignoredTag.names[0], // no getters after deserializing
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
pop.posts.push(vm);
|
pop.posts.push(vm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +160,7 @@ async function grabPost() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.value.fetchPostInfo) {
|
if (cfg.value.fetchPostInfo) {
|
||||||
await fetchPostInfo();
|
await fetchPostsInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delayed call to findSimilar, as fetchPostInfo might change the post's contentUrl.
|
// Delayed call to findSimilar, as fetchPostInfo might change the post's contentUrl.
|
||||||
|
|
@ -160,8 +183,18 @@ async function upload() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const post: any = cloneDeep(pop.selectedPost);
|
const post: ScrapedPostDetails = cloneDeep(pop.selectedPost)!;
|
||||||
const cmdData = new PostUploadCommandData(post, <SzuruSiteConfig>cloneDeep(selectedSite.value));
|
|
||||||
|
// uploadMode "content" requires a content token to work. So ensure it is set.
|
||||||
|
if (post.uploadMode === "content") {
|
||||||
|
await ensurePostHasContentToken(szuru.value!, post, cfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cmdData = new PostUploadCommandData(
|
||||||
|
post,
|
||||||
|
<SzuruSiteConfig>cloneDeep(selectedSite.value),
|
||||||
|
cfg.value.sendUploadNotifications,
|
||||||
|
);
|
||||||
const cmd = new BrowserCommand("upload_post", cmdData);
|
const cmd = new BrowserCommand("upload_post", cmdData);
|
||||||
await browser.runtime.sendMessage(cmd);
|
await browser.runtime.sendMessage(cmd);
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
|
|
@ -243,6 +276,10 @@ async function findSimilar(post: ScrapedPostDetails | undefined) {
|
||||||
if (!post || !szuru.value || !cfg.value.selectedSiteId) return;
|
if (!post || !szuru.value || !cfg.value.selectedSiteId) return;
|
||||||
|
|
||||||
// TODO: This code might not work.
|
// TODO: This code might not work.
|
||||||
|
// Why is toRaw used?
|
||||||
|
// I guess it could happen that the selectedInstance changes halfway during this function?
|
||||||
|
// And in that case toRaw would ensure we have the original selected instance (as it was at the start of this function).
|
||||||
|
// In theory this sounds correct, but idk if it is needed in practice.
|
||||||
const selectedInstance = toRaw(szuru.value); // Get current object, and not reactive.
|
const selectedInstance = toRaw(szuru.value); // Get current object, and not reactive.
|
||||||
let instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
|
let instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
|
||||||
|
|
||||||
|
|
@ -252,23 +289,14 @@ async function findSimilar(post: ScrapedPostDetails | undefined) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't load this again if it is already loaded.
|
// Don't load this again if it is already loaded.
|
||||||
if (instanceSpecificData?.reverseSearchResult) return;
|
if (instanceSpecificData.reverseSearchResult) return;
|
||||||
|
|
||||||
isSearchingForSimilarPosts.value++;
|
isSearchingForSimilarPosts.value++;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let res: ImageSearchResult | undefined;
|
await ensurePostHasContentToken(selectedInstance, post, cfg);
|
||||||
|
|
||||||
if (cfg.value.useContentTokens) {
|
const res = await selectedInstance.reverseSearchToken(instanceSpecificData.contentToken!);
|
||||||
let tmpRes = await selectedInstance.uploadTempFile(post.contentUrl);
|
|
||||||
// TODO: Error handling?
|
|
||||||
// Save contentToken in PostViewModel so that we can reuse it when creating/uploading the post.
|
|
||||||
instanceSpecificData.contentToken = tmpRes.token;
|
|
||||||
|
|
||||||
res = await selectedInstance.reverseSearchToken(tmpRes.token);
|
|
||||||
} else {
|
|
||||||
res = await selectedInstance.reverseSearch(post.contentUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
instanceSpecificData.reverseSearchResult = {
|
instanceSpecificData.reverseSearchResult = {
|
||||||
exactPostId: res.exactPost?.id,
|
exactPostId: res.exactPost?.id,
|
||||||
|
|
@ -295,43 +323,66 @@ async function loadTagCounts() {
|
||||||
// Not the best code, but it works I guess?
|
// Not the best code, but it works I guess?
|
||||||
if (resp) {
|
if (resp) {
|
||||||
for (let post of pop.posts)
|
for (let post of pop.posts)
|
||||||
for (let tag of resp.results)
|
for (let tag of resp.results) {
|
||||||
for (let postTag of post.tags)
|
const postTag = post.tags.find((postTag) => tag.names.includes(postTag.name));
|
||||||
if (postTag.name == tag.names[0]) {
|
if (postTag) postTag.usages = tag.usages;
|
||||||
postTag.usages = tag.usages;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchPostInfo() {
|
async function updatePostWithRemoteInfo(post: ScrapedPostDetails, contentUrl: string) {
|
||||||
for (const post of pop.posts) {
|
|
||||||
if (!post.contentSize || post.extraContentUrl) {
|
|
||||||
// We are missing cookies/etc which means that the request might fail.
|
// We are missing cookies/etc which means that the request might fail.
|
||||||
// If you want access to the cookies/session/etc then you need to execute this code inside the content script.
|
// If you want access to the cookies/session/etc then you need to execute this code inside the content script.
|
||||||
try {
|
try {
|
||||||
const contentUrl = post.extraContentUrl ?? post.contentUrl;
|
// This request follows redirects.
|
||||||
|
|
||||||
// TODO: Check whether we need to call this in the background page, or if it is fine to call it from the popup.
|
|
||||||
const res = await fetch(contentUrl, { method: "HEAD" });
|
const res = await fetch(contentUrl, { method: "HEAD" });
|
||||||
const size = res.headers.get("Content-Length");
|
const size = res.headers.get("Content-Length");
|
||||||
const type = res.headers.get("Content-Type");
|
const type = res.headers.get("Content-Type");
|
||||||
|
|
||||||
if (size) post.contentSize = parseInt(size);
|
|
||||||
|
|
||||||
if (type) {
|
if (type) {
|
||||||
|
if (type.indexOf("text/html") != -1) {
|
||||||
|
// If we get a HTML page back it usually means that the request failed.
|
||||||
|
// Not all sites (e.g. e-hentai) reply with a 403.
|
||||||
|
throw new Error(
|
||||||
|
"Received a text/html content type. This probably means that we don't have permission to access the resource.",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const [_main, sub] = type.split("/");
|
const [_main, sub] = type.split("/");
|
||||||
if (sub) post.contentSubType = sub.toUpperCase();
|
if (sub) post.contentSubType = sub.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resolve extraContentUrl redirects.
|
// This should be after the type check, because the type check also checks whether the response we get is valid/unsable.
|
||||||
if (post.extraContentUrl && res.url != post.contentUrl) {
|
if (size) post.contentSize = parseInt(size);
|
||||||
|
|
||||||
|
// Update url if it changes. The url can change when:
|
||||||
|
// a. the extraContentUrl was successfully loaded
|
||||||
|
// b. because of redirects
|
||||||
|
if (res.url != post.contentUrl) {
|
||||||
|
// The developer needs to make sure that the remote server can load this URL if `post.uploadMode == 'url'`!
|
||||||
|
console.log(`Updating post.contentUrl to '${res.url}'`);
|
||||||
post.contentUrl = res.url;
|
post.contentUrl = res.url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
// TODO: Maybe display an error in the UI.
|
|
||||||
console.error(ex);
|
console.error(ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchPostsInfo() {
|
||||||
|
for (const post of pop.posts) {
|
||||||
|
if (!post.contentSize || post.extraContentUrl) {
|
||||||
|
let ok = false;
|
||||||
|
if (post.extraContentUrl) {
|
||||||
|
// Prioritize info from extraContentUrl.
|
||||||
|
ok = await updatePostWithRemoteInfo(post, post.extraContentUrl);
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
// Fall back to normal contentUrl if we can't get the data from the extraContentUrl.
|
||||||
|
await updatePostWithRemoteInfo(post, post.contentUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -343,7 +394,8 @@ function getUpdatedTagsText(count: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onResolutionLoaded(res: any) {
|
function onResolutionLoaded(res: any) {
|
||||||
if (pop.selectedPost && !pop.selectedPost.resolution) {
|
// This no longer checks for `!pop.selectedPost.resolution` because the resolution can change if the contentUrl is updated.
|
||||||
|
if (pop.selectedPost) {
|
||||||
pop.selectedPost.resolution = res;
|
pop.selectedPost.resolution = res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -380,13 +432,17 @@ useDark();
|
||||||
<!-- TODO: Maybe a 5px gap here? -->
|
<!-- TODO: Maybe a 5px gap here? -->
|
||||||
|
|
||||||
<div style="display: flex; background: purple; border-radius: 0 2px 2px 0">
|
<div style="display: flex; background: purple; border-radius: 0 2px 2px 0">
|
||||||
<router-link :to="{
|
<router-link
|
||||||
|
:to="{
|
||||||
name: 'merge',
|
name: 'merge',
|
||||||
params: {
|
params: {
|
||||||
siteId: cfg.selectedSiteId,
|
siteId: cfg.selectedSiteId,
|
||||||
postId: instanceSpecificData?.reverseSearchResult?.exactPostId,
|
postId: instanceSpecificData?.reverseSearchResult?.exactPostId,
|
||||||
},
|
},
|
||||||
}" style="padding: 5px 20px">Merge</router-link>
|
}"
|
||||||
|
style="padding: 5px 20px"
|
||||||
|
>Merge</router-link
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -407,10 +463,15 @@ useDark();
|
||||||
-->
|
-->
|
||||||
|
|
||||||
<!-- TODO: Clicking a link doesn't actually open it in a new tab, see https://stackoverflow.com/questions/8915845 -->
|
<!-- TODO: Clicking a link doesn't actually open it in a new tab, see https://stackoverflow.com/questions/8915845 -->
|
||||||
<div v-if="instanceSpecificData?.uploadState?.state == 'uploaded' && instanceSpecificData?.uploadState.instancePostId
|
<div
|
||||||
" class="bg-success">
|
v-if="
|
||||||
<a :href="getActiveSitePostUrl(instanceSpecificData.uploadState.instancePostId)">Uploaded post {{
|
instanceSpecificData?.uploadState?.state == 'uploaded' && instanceSpecificData?.uploadState.instancePostId
|
||||||
instanceSpecificData.uploadState.instancePostId }}</a>
|
"
|
||||||
|
class="bg-success"
|
||||||
|
>
|
||||||
|
<a :href="getActiveSitePostUrl(instanceSpecificData.uploadState.instancePostId)"
|
||||||
|
>Uploaded post {{ instanceSpecificData.uploadState.instancePostId }}</a
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="instanceSpecificData?.uploadState?.updateTagsState?.totalChanged" class="bg-success">
|
<div v-if="instanceSpecificData?.uploadState?.updateTagsState?.totalChanged" class="bg-success">
|
||||||
|
|
@ -423,45 +484,64 @@ useDark();
|
||||||
|
|
||||||
<div v-if="instanceSpecificData?.uploadState?.state == 'uploading'"><span>Uploading...</span></div>
|
<div v-if="instanceSpecificData?.uploadState?.state == 'uploading'"><span>Uploading...</span></div>
|
||||||
|
|
||||||
<div v-if="instanceSpecificData?.uploadState?.updateTagsState?.total &&
|
<div
|
||||||
|
v-if="
|
||||||
|
instanceSpecificData?.uploadState?.updateTagsState?.total &&
|
||||||
instanceSpecificData.uploadState?.updateTagsState?.current == undefined
|
instanceSpecificData.uploadState?.updateTagsState?.current == undefined
|
||||||
">
|
"
|
||||||
|
>
|
||||||
<span>{{ instanceSpecificData.uploadState?.updateTagsState?.total }} tags need a different category</span>
|
<span>{{ instanceSpecificData.uploadState?.updateTagsState?.total }} tags need a different category</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="instanceSpecificData?.uploadState?.updateTagsState?.current &&
|
<div
|
||||||
|
v-if="
|
||||||
|
instanceSpecificData?.uploadState?.updateTagsState?.current &&
|
||||||
instanceSpecificData?.uploadState?.updateTagsState?.totalChanged == undefined
|
instanceSpecificData?.uploadState?.updateTagsState?.totalChanged == undefined
|
||||||
">
|
"
|
||||||
<span>Updating tag {{ instanceSpecificData.uploadState?.updateTagsState?.current }}/{{
|
>
|
||||||
|
<span
|
||||||
|
>Updating tag {{ instanceSpecificData.uploadState?.updateTagsState?.current }}/{{
|
||||||
instanceSpecificData.uploadState?.updateTagsState?.total
|
instanceSpecificData.uploadState?.updateTagsState?.total
|
||||||
}}</span>
|
}}</span
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="isSearchingForSimilarPosts > 0 && instanceSpecificData?.uploadState == undefined">
|
<div v-if="isSearchingForSimilarPosts > 0 && instanceSpecificData?.uploadState == undefined">
|
||||||
<span>Searching for similar posts...</span>
|
<span>Searching for similar posts...</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="instanceSpecificData?.reverseSearchResult?.similarPosts.length == 0 &&
|
<div
|
||||||
|
v-if="
|
||||||
|
instanceSpecificData?.reverseSearchResult?.similarPosts.length == 0 &&
|
||||||
instanceSpecificData.uploadState == undefined
|
instanceSpecificData.uploadState == undefined
|
||||||
">
|
"
|
||||||
|
>
|
||||||
<span>No similar posts found</span>
|
<span>No similar posts found</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-for="similarPost in getSimilarPosts(instanceSpecificData?.reverseSearchResult)" :key="similarPost.id"
|
<div
|
||||||
class="has-merge-button">
|
v-for="similarPost in getSimilarPosts(instanceSpecificData?.reverseSearchResult)"
|
||||||
<a :href="getActiveSitePostUrl(similarPost.id)">Post {{ similarPost.id }} looks {{ similarPost.percentage }}%
|
:key="similarPost.id"
|
||||||
similar</a>
|
class="has-merge-button"
|
||||||
|
>
|
||||||
|
<a :href="getActiveSitePostUrl(similarPost.id)"
|
||||||
|
>Post {{ similarPost.id }} looks {{ similarPost.percentage }}% similar</a
|
||||||
|
>
|
||||||
|
|
||||||
<!-- TODO: Maybe a 5px gap here? -->
|
<!-- TODO: Maybe a 5px gap here? -->
|
||||||
|
|
||||||
<div style="display: flex; background: purple; border-radius: 0 2px 2px 0">
|
<div style="display: flex; background: purple; border-radius: 0 2px 2px 0">
|
||||||
<router-link :to="{
|
<router-link
|
||||||
|
:to="{
|
||||||
name: 'merge',
|
name: 'merge',
|
||||||
params: {
|
params: {
|
||||||
siteId: cfg.selectedSiteId,
|
siteId: cfg.selectedSiteId,
|
||||||
postId: similarPost.id,
|
postId: similarPost.id,
|
||||||
},
|
},
|
||||||
}" style="padding: 5px 20px">Merge</router-link>
|
}"
|
||||||
|
style="padding: 5px 20px"
|
||||||
|
>Merge</router-link
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -500,7 +580,7 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-row">
|
<div v-if="cfg.popup.showSource" class="section-row">
|
||||||
<span class="section-label">Source</span>
|
<span class="section-label">Source</span>
|
||||||
<textarea v-model="pop.selectedPost.source"></textarea>
|
<textarea v-model="pop.selectedPost.source"></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -512,23 +592,31 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<CompactTags :tags="pop.selectedPost.tags" :show-remove-tag="true" :show-usages="cfg.loadTagCounts"
|
<CompactTags
|
||||||
@remove-tag="removeTag" />
|
:tags="pop.selectedPost.tags"
|
||||||
|
:show-remove-tag="true"
|
||||||
|
:show-usages="cfg.loadTagCounts"
|
||||||
|
@remove-tag="removeTag"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</PopupSection>
|
</PopupSection>
|
||||||
|
|
||||||
<PopupSection header="Pools" toggleable v-model="cfg.popup.expandPools">
|
<PopupSection v-if="cfg.popup.showPools" header="Pools" toggleable v-model="cfg.popup.expandPools">
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<PoolInput :szuru="szuru" @add-pool="addPool" />
|
<PoolInput :szuru="szuru" @add-pool="addPool" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<CompactPools :pools="pop.selectedPost.pools" :show-remove-pool="true" show-post-count
|
<CompactPools
|
||||||
@remove-pool="removePool" />
|
:pools="pop.selectedPost.pools"
|
||||||
|
:show-remove-pool="true"
|
||||||
|
show-post-count
|
||||||
|
@remove-pool="removePool"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</PopupSection>
|
</PopupSection>
|
||||||
|
|
||||||
<div class="popup-section">
|
<div v-if="cfg.popup.showInstancePicker" class="popup-section">
|
||||||
<div class="section-row">
|
<div class="section-row">
|
||||||
<select v-model="cfg.selectedSiteId">
|
<select v-model="cfg.selectedSiteId">
|
||||||
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
|
<option v-for="site in cfg.sites" :key="site.id" :value="site.id">
|
||||||
|
|
@ -558,8 +646,11 @@ useDark();
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="popup-section">
|
<div class="popup-section">
|
||||||
<PostContentDisplay :content-url="pop.selectedPost.contentUrl" :content-type="pop.selectedPost.contentType"
|
<PostContentDisplay
|
||||||
@on-resolution-loaded="onResolutionLoaded" />
|
:content-url="pop.selectedPost.contentUrl"
|
||||||
|
:content-type="pop.selectedPost.contentType"
|
||||||
|
@on-resolution-loaded="onResolutionLoaded"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import deepMerge from "deepmerge";
|
import deepMerge from "deepmerge";
|
||||||
import {
|
import {
|
||||||
|
type TagDetails,
|
||||||
getDefaultTagCategories,
|
getDefaultTagCategories,
|
||||||
type ScrapedPostDetails,
|
type ScrapedPostDetails,
|
||||||
type SetPostUploadInfoData,
|
type SetPostUploadInfoData,
|
||||||
|
|
@ -14,6 +15,8 @@ export const cfg = useStorageLocal(
|
||||||
{
|
{
|
||||||
version: 0,
|
version: 0,
|
||||||
addPageUrlToSource: true,
|
addPageUrlToSource: true,
|
||||||
|
alwaysUploadAsContent: false,
|
||||||
|
sendUploadNotifications: false,
|
||||||
autoSearchSimilar: false,
|
autoSearchSimilar: false,
|
||||||
loadTagCounts: true,
|
loadTagCounts: true,
|
||||||
fetchPostInfo: true,
|
fetchPostInfo: true,
|
||||||
|
|
@ -33,8 +36,12 @@ export const cfg = useStorageLocal(
|
||||||
popup: {
|
popup: {
|
||||||
expandTags: true,
|
expandTags: true,
|
||||||
expandPools: false,
|
expandPools: false,
|
||||||
|
showSource: true,
|
||||||
|
showPools: true,
|
||||||
|
showInstancePicker: true,
|
||||||
},
|
},
|
||||||
tagCategories: [] as Array<TagCategoryColor>,
|
tagCategories: [] as Array<TagCategoryColor>,
|
||||||
|
tagIgnores: [] as Array<TagDetails>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
mergeDefaults(storageValue, defaults) {
|
mergeDefaults(storageValue, defaults) {
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,15 @@
|
||||||
font-family: "Open Sans";
|
font-family: "Open Sans";
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
src: local(""), url("/assets/open-sans-v34-latin-regular.woff2") format("woff2");
|
src:
|
||||||
|
local(""),
|
||||||
|
url("/assets/open-sans-v34-latin-regular.woff2") format("woff2");
|
||||||
|
}
|
||||||
|
|
||||||
|
*,
|
||||||
|
*:before,
|
||||||
|
*:after {
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
|
|
@ -91,7 +99,7 @@ select {
|
||||||
border: 2px solid var(--border-color);
|
border: 2px solid var(--border-color);
|
||||||
|
|
||||||
padding: 0.2em 0.3em;
|
padding: 0.2em 0.3em;
|
||||||
box-sizing: border-box;
|
// box-sizing: border-box;
|
||||||
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
|
@ -117,7 +125,7 @@ textarea {
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
outline: var(--primary-color) solid 2px;
|
outline: var(--primary-color) solid 2px;
|
||||||
box-sizing: content-box;
|
// box-sizing: content-box;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,7 +149,8 @@ ul.compact {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.compact-tags, .compact-pools {
|
.compact-tags,
|
||||||
|
.compact-pools {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
display: inline;
|
display: inline;
|
||||||
|
|
@ -259,3 +268,9 @@ a.remove-tag {
|
||||||
.color-primary {
|
.color-primary {
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.separated-content > * + * {
|
||||||
|
padding-top: 1rem;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
border-top: 3px solid #333;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { describe, expect, it } from 'vitest';
|
import { describe, expect, it } from "vitest";
|
||||||
|
|
||||||
describe('Demo', () => {
|
describe("Demo", () => {
|
||||||
it('should work', () => {
|
it("should work", () => {
|
||||||
expect(1 + 1).toBe(2);
|
expect(1 + 1).toBe(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
26
src/utils.ts
26
src/utils.ts
|
|
@ -1,6 +1,7 @@
|
||||||
import byteSize from "byte-size";
|
import byteSize from "byte-size";
|
||||||
import { MicroUser, Post } from "./api/models";
|
import { MicroUser, Post } from "./api/models";
|
||||||
import { ScrapedPostDetails, TagDetails } from "./models";
|
import { ScrapedPostDetails, TagDetails } from "./models";
|
||||||
|
import SzurubooruApi from "./api";
|
||||||
|
|
||||||
export function getUrl(root: string, ...parts: string[]): string {
|
export function getUrl(root: string, ...parts: string[]): string {
|
||||||
let url = root.replace(/\/+$/, "");
|
let url = root.replace(/\/+$/, "");
|
||||||
|
|
@ -102,3 +103,28 @@ export function getPostInfoSummary(post: ScrapedPostDetails) {
|
||||||
}
|
}
|
||||||
return parts.join(" / ");
|
return parts.join(" / ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function ensurePostHasContentToken(selectedInstance: SzurubooruApi, post: ScrapedPostDetails, cfg: any) {
|
||||||
|
if (!selectedInstance || !cfg.value.selectedSiteId) return;
|
||||||
|
|
||||||
|
const instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
|
||||||
|
|
||||||
|
if (!instanceSpecificData) {
|
||||||
|
console.error("instanceSpecificData is undefined. This should never happen!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (instanceSpecificData.contentToken) {
|
||||||
|
console.log("[ensurePostHasContentToken] contentToken is already set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const tmpRes = await selectedInstance.uploadTempFile(post.contentUrl, post.uploadMode);
|
||||||
|
// Save contentToken in PostViewModel so that we can reuse it when creating/uploading the post.
|
||||||
|
instanceSpecificData.contentToken = tmpRes.token;
|
||||||
|
} catch (ex) {
|
||||||
|
instanceSpecificData.genericError = "Couldn't upload content. " + getErrorMessage(ex);
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"module": "ESNext",
|
"module": "ESNext",
|
||||||
"target": "es2016",
|
"target": "es2016",
|
||||||
"lib": [
|
"lib": ["DOM", "ESNext"],
|
||||||
"DOM",
|
|
||||||
"ESNext"
|
|
||||||
],
|
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"incremental": false,
|
"incremental": false,
|
||||||
|
|
@ -16,17 +13,10 @@
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"types": [
|
"types": ["vite/client"],
|
||||||
"vite/client"
|
|
||||||
],
|
|
||||||
"paths": {
|
"paths": {
|
||||||
"~/*": [
|
"~/*": ["src/*"]
|
||||||
"src/*"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exclude": [
|
"exclude": ["dist", "node_modules"]
|
||||||
"dist",
|
|
||||||
"node_modules"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
{
|
||||||
|
"addons": {
|
||||||
|
"suzuruchrome@goblincave": {
|
||||||
|
"updates": [
|
||||||
|
{
|
||||||
|
"version": "0.1.4",
|
||||||
|
"update_link": "https://gitea.goblincave.synology.me/Nes/SzuruChrome/releases/download/mod-v0.1.X/SzuruChrome_v0.1.4.xpi"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue