Compare commits

..

No commits in common. "master" and "v0.11.2" have entirely different histories.

16 changed files with 4679 additions and 5936 deletions

View File

@ -27,12 +27,12 @@ runs:
name: Install pnpm
id: pnpm-install
with:
version: 9
version: 7
run_install: false
- uses: actions/setup-node@v3
with:
node-version: "20"
node-version: "16"
cache: "pnpm"
- name: Install dependencies

View File

@ -15,7 +15,7 @@ on:
jobs:
build_chrome:
name: "Build Chrome Extension"
runs-on: ubuntu-24.04
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
@ -30,14 +30,14 @@ jobs:
- name: Pack ZIP
run: pnpm pack:zip
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v3
with:
name: Chrome Extension (Unsigned)
path: extension.zip
build_unlisted_firefox:
name: "Build Unlisted Firefox Extension"
runs-on: ubuntu-24.04
runs-on: ubuntu-20.04
# Doesn't really need the Chrome build, but we can reuse its cache.
needs: build_chrome
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
@ -60,20 +60,17 @@ jobs:
WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }}
WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }}
- name: Rename XPI
run: rename.ul szuruchrome_gh- SzuruChrome-v web-ext-artifacts/*.xpi
- uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v3
with:
name: Firefox Extension (Signed)
path: web-ext-artifacts/*.xpi
build_amo_firefox:
name: "Build Firefox Extension for AMO"
runs-on: ubuntu-24.04
runs-on: ubuntu-20.04
# Doesn't really need the Chrome build, but we can reuse its cache.
needs: build_chrome
# Only run (on master branch && if tagged) or (manually dispatching).
# Only run on master branch AND if tagging or manually dispatching.
if: startsWith(github.ref, 'refs/tags/v') || github.event.inputs.publish_amo_listed == true
steps:
- name: Checkout

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

After

Width:  |  Height:  |  Size: 33 KiB

View File

@ -4,6 +4,7 @@
"description": "Import media from various sites into szurubooru.",
"version": "0.0.0",
"private": true,
"packageManager": "pnpm@7.8.0",
"scripts": {
"dev": "npm run clear && cross-env NODE_ENV=development run-p dev:*",
"dev:prepare": "esno scripts/prepare.ts",
@ -19,7 +20,7 @@
"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:firefox": "web-ext run --source-dir ./extension --target=firefox-desktop",
"sign:firefox": "web-ext sign --source-dir ./extension",
"sign:firefox": "web-ext sign --use-submission-api --source-dir ./extension",
"clear": "rimraf extension/dist extension/manifest.json extension.*",
"lint": "eslint .",
"extlint": "web-ext lint -s extension",
@ -27,55 +28,55 @@
"pretty": "prettier -w ."
},
"dependencies": {
"axios": "^1.19.0",
"byte-size": "^8.2.1",
"axios": "^1.6.3",
"byte-size": "^8.1.1",
"deepmerge": "^4.3.1",
"lodash": "^4.18.1",
"markdown-it": "^14.3.0",
"neo-scraper": "^0.11.1",
"lodash": "^4.17.21",
"markdown-it": "^14.0.0",
"neo-scraper": "^0.7.5",
"normalize.css": "^8.0.1",
"pinia": "^2.3.1",
"pinia": "^2.1.7",
"primeflex": "^3.3.1",
"primevue": "3.45.0",
"vue-router": "^4.6.4"
"primevue": "^3.45.0",
"vue-router": "^4.2.5"
},
"devDependencies": {
"@ffflorian/jszip-cli": "^3.16.5",
"@fortawesome/fontawesome-svg-core": "^6.7.2",
"@fortawesome/free-solid-svg-icons": "^6.7.2",
"@fortawesome/vue-fontawesome": "^3.3.3",
"@ffflorian/jszip-cli": "^3.5.8",
"@fortawesome/fontawesome-svg-core": "^6.5.1",
"@fortawesome/free-solid-svg-icons": "^6.5.1",
"@fortawesome/vue-fontawesome": "^3.0.5",
"@types/byte-size": "^8.1.2",
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.17.25",
"@types/markdown-it": "^13.0.9",
"@types/node": "^20.19.43",
"@types/lodash": "^4.14.202",
"@types/markdown-it": "^13.0.7",
"@types/node": "^20.10.5",
"@types/webextension-polyfill": "^0.10.7",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@vitejs/plugin-vue": "^5.2.4",
"@vue/compiler-sfc": "^3.5.41",
"@vue/test-utils": "^2.4.11",
"@vueuse/core": "^10.11.1",
"chokidar": "^3.6.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@vitejs/plugin-vue": "^5.0.1",
"@vue/compiler-sfc": "^3.4.0",
"@vue/test-utils": "^2.4.3",
"@vueuse/core": "^10.7.1",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"crx": "^5.0.1",
"eslint": "^8.57.1",
"eslint-plugin-vue": "^9.33.0",
"esno": "^4.8.0",
"fs-extra": "^11.4.0",
"jsdom": "^23.2.0",
"eslint": "^8.56.0",
"eslint-plugin-vue": "^9.19.2",
"esno": "^4.0.0",
"fs-extra": "^11.2.0",
"jsdom": "^23.0.1",
"kolorist": "^1.8.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.9.6",
"prettier": "^3.1.1",
"rimraf": "^3.0.2",
"sass": "^1.102.0",
"typescript": "^5.9.3",
"unplugin-auto-import": "^0.17.8",
"sass": "^1.69.6",
"typescript": "^5.3.3",
"unplugin-auto-import": "^0.17.3",
"unplugin-vue-components": "^0.26.0",
"vite": "^5.4.21",
"vitest": "^1.6.1",
"vue": "^3.5.41",
"vue-eslint-parser": "^9.4.3",
"web-ext": "^8.10.0",
"vite": "^5.0.10",
"vitest": "^1.1.0",
"vue": "^3.4.0",
"vue-eslint-parser": "^9.3.2",
"web-ext": "^7.9.0",
"webextension-polyfill": "^0.10.0"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,6 @@ import {
UpdatePoolRequest,
} from "./models";
import { ScrapedPostDetails, SzuruSiteConfig } from "~/models";
import { UploadMode } from "neo-scraper";
/**
* A 1:1 wrapper around the szurubooru API.
@ -148,11 +147,11 @@ export default class SzurubooruApi {
return (await this.apiPost("posts/reverse-search", obj)).data;
}
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.
async uploadTempFile(contentUrl: string): Promise<TemporaryFileUploadResult> {
// HACK: 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") {
if (contentUrl.indexOf("donmai.us") != -1) {
console.log("Upload from content");
return this.uploadTempFileFromContent(contentUrl);
} else {

View File

@ -1,4 +1,4 @@
import { encodeTagName, getErrorMessage, getUrl } from "~/utils";
import { encodeTagName, getErrorMessage } from "~/utils";
import {
BrowserCommand,
PostUploadCommandData,
@ -19,13 +19,6 @@ if (import.meta.hot) {
import("./contentScriptHMR");
}
browser.notifications.onClicked.addListener((url) => {
if (url) {
browser.tabs.create({ url });
browser.notifications.clear(url);
}
});
async function uploadPost(data: PostUploadCommandData) {
const info: PostUploadInfo = {
state: "uploading",
@ -124,16 +117,6 @@ async function uploadPost(data: PostUploadCommandData) {
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) {
console.error(ex);
if (ex.name && ex.name == "PostAlreadyUploadedError") {

View File

@ -31,7 +31,7 @@ export async function getManifest() {
page: "./dist/background/index.html",
// persistent: false,
},
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "notifications", "<all_urls>"],
permissions: ["storage", "activeTab", "webRequest", "webRequestBlocking", "<all_urls>"],
content_scripts: [
{
matches: ["http://*/*", "https://*/*"],

View File

@ -1,4 +1,4 @@
import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag, UploadMode } from "neo-scraper";
import { BooruTypes, ContentType, ScrapedNote, ScrapedPost, ScrapedTag } from "neo-scraper";
import { MicroTag, Pool, Tag, UpdatePostRequest } from "~/api/models";
export class TagDetails {
@ -73,8 +73,7 @@ export class ScrapedPostDetails {
contentType: ContentType;
contentSubType: string | undefined;
rating: BooruTypes.SafetyRating;
source;
uploadMode: UploadMode;
source = "";
referrer?: string;
resolution?: [number, number];
instanceSpecificData: MappedInstanceSpecificData = {};
@ -91,7 +90,6 @@ export class ScrapedPostDetails {
this.tags = post.tags.map((x) => TagDetails.fromScapedTag(x));
this.notes = post.notes;
this.resolution = post.resolution;
this.uploadMode = post.uploadMode;
}
}
@ -148,7 +146,6 @@ export class PostUploadCommandData {
constructor(
public readonly post: ScrapedPostDetails,
public readonly selectedSite: SzuruSiteConfig,
public readonly sendNotifications: boolean,
) {}
}

View File

@ -8,11 +8,9 @@ import TabView from "primevue/tabview";
import TabPanel from "primevue/tabpanel";
import DataTable from "primevue/datatable";
import Column from "primevue/column";
import { TagDetails, SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
import { SzuruSiteConfig, TagCategoryColor, getDefaultTagCategories } from "~/models";
import SzurubooruApi from "~/api";
type StatusType = "success" | "error" | "quiet";
const statusText = ref("");
const statusType = ref("status-quiet");
const versionInfo = "Version: " + (import.meta.env.VITE_SZ_VERSION ?? browser.runtime.getManifest().version);
@ -28,7 +26,9 @@ const selectedSite = computed(() => {
}
});
const mode = useColorMode({ emitAuto: true });
type StatusType = "success" | "error" | "quiet";
let mode = useColorMode({ emitAuto: true });
async function testConnection() {
if (
@ -102,14 +102,6 @@ async function importTagCategoriesFromInstance() {
}
}
function addTagIgnore() {
cfg.value.tagIgnores.push(new TagDetails([""]));
}
function resetTagIgnores() {
cfg.value.tagIgnores.splice(0);
}
// For debugging
const wnd = window as any;
wnd.szc_get_config = () => JSON.parse(JSON.stringify(cfg.value));
@ -147,25 +139,6 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
</p>
</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>
@ -248,13 +221,8 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
<template v-if="selectedSite">
<div class="field col-12">
<label>URL</label>
<input
v-if="selectedSite"
text="Szurubooru URL"
type="text"
name="domain"
v-model="selectedSite.domain"
/>
<input v-if="selectedSite" text="Szurubooru URL" type="text" name="domain"
v-model="selectedSite.domain" />
</div>
<div class="field col-12 md:col-6">
@ -276,7 +244,6 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
</TabPanel>
<TabPanel header="Tags">
<div class="separated-content">
<div class="grid">
<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">
@ -284,14 +251,10 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
<template v-if="field == 'color'">
<div class="color-preview">
<input type="text" class="color" v-model="data[field]" />
<div
class="preview background-preview"
:style="{ 'border-color': data[field], 'background-color': data[field] }"
></div>
<div
class="preview text-preview"
:style="{ 'border-color': data[field], color: data[field] }"
></div>
<div class="preview background-preview"
:style="{ 'border-color': data[field], 'background-color': data[field] }"></div>
<div class="preview text-preview" :style="{ 'border-color': data[field], color: data[field] }">
</div>
</div>
</template>
@ -317,41 +280,11 @@ wnd.szc_set_config_version = (v = 0) => (cfg.value.version = v);
<!-- TODO: Tag category colors -->
<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: Tag ignore list -->
<!-- TODO: Category ignore list -->
</div>
</TabPanel>
<!-- <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">

View File

@ -5,7 +5,7 @@ import { Post, UpdatePostRequest } from "~/api/models";
import { isMobile } from "~/env";
import { BrowserCommand, PostUpdateCommandData, TagDetails } from "~/models";
import { cfg, useMergeStore, usePopupStore } from "~/stores";
import { emptyPost, ensurePostHasContentToken, getUrl } from "~/utils";
import { emptyPost, getUrl } from "~/utils";
const props = defineProps(["siteId", "postId"]);
const merge = useMergeStore();
@ -140,10 +140,7 @@ async function mergeChanges() {
}
if (imageToKeep.value == "new") {
// 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!;
req.contentUrl = scrapedPost?.contentUrl;
}
if (!req.safety && !req.source && !(req.contentUrl || req.contentToken) && req.tags === undefined) {

View File

@ -2,7 +2,7 @@
import { useDark } from "@vueuse/core";
import { cloneDeep } from "lodash";
import { ScrapeResults } from "neo-scraper";
import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary, ensurePostHasContentToken } from "~/utils";
import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary } from "~/utils";
import {
BrowserCommand,
ScrapedPostDetails,
@ -14,6 +14,7 @@ import {
SzuruSiteConfig,
PoolDetails,
} from "~/models";
import { ImageSearchResult } from "~/api/models";
import { isMobile } from "~/env";
import { DeepReadonly } from "vue";
import { cfg, usePopupStore } from "~/stores";
@ -73,56 +74,40 @@ function openOptionsPage() {
browser.runtime.openOptionsPage();
}
async function getSelectedTabIds(): Promise<number[]> {
const selectedTabs = await browser.tabs.query({
highlighted: true,
async function getActiveTabId(): Promise<number> {
const activeTabs = await browser.tabs.query({
active: true,
currentWindow: true,
});
if (selectedTabs.length > 0 && selectedTabs[0].id) {
return selectedTabs.filter((tab) => tab.id).map((tab) => tab.id as number);
}
if (activeTabs.length > 0 && activeTabs[0].id) return activeTabs[0].id;
throw new Error("No active tab.");
}
async function grabPost() {
// Get active tab
const selectedTabIds = await getSelectedTabIds();
const activeTabId = await getActiveTabId();
let scrapeResults: ScrapeResults = new ScrapeResults();
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"));
// Send 'grab_post' to the content script on the active tab
const x = await browser.tabs.sendMessage(activeTabId, new BrowserCommand("grab_post"));
// 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)
const results: ScrapeResults = Object.assign(new ScrapeResults(), x);
const res = Object.assign(new ScrapeResults(), x);
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);
console.dir(res);
// Clear current posts array
pop.posts.splice(0);
for (const result of scrapeResults.results) {
for (const result of res.results) {
for (const i in result.posts) {
const vm = new ScrapedPostDetails(result.posts[i]);
const name = result.posts[i].name ?? `Post ${parseInt(i) + 1}`; // parseInt() is required!
vm.name = `[${result.engine}] ${name}`;
vm.name = `[${result.engine}] Post ${parseInt(i) + 1}`; // parseInt() is required!
if (!cfg.value.addAllParsedTags) {
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
// a. user has addPageUrlToSource set to true
// b. source is empty
@ -136,14 +121,6 @@ async function grabPost() {
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);
}
}
@ -160,7 +137,7 @@ async function grabPost() {
}
if (cfg.value.fetchPostInfo) {
await fetchPostsInfo();
await fetchPostInfo();
}
// Delayed call to findSimilar, as fetchPostInfo might change the post's contentUrl.
@ -183,18 +160,8 @@ async function upload() {
}
try {
const post: ScrapedPostDetails = cloneDeep(pop.selectedPost)!;
// 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 post: any = cloneDeep(pop.selectedPost);
const cmdData = new PostUploadCommandData(post, <SzuruSiteConfig>cloneDeep(selectedSite.value));
const cmd = new BrowserCommand("upload_post", cmdData);
await browser.runtime.sendMessage(cmd);
} catch (ex: any) {
@ -276,10 +243,6 @@ async function findSimilar(post: ScrapedPostDetails | undefined) {
if (!post || !szuru.value || !cfg.value.selectedSiteId) return;
// 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.
let instanceSpecificData = post.instanceSpecificData[cfg.value.selectedSiteId];
@ -289,14 +252,23 @@ async function findSimilar(post: ScrapedPostDetails | undefined) {
}
// Don't load this again if it is already loaded.
if (instanceSpecificData.reverseSearchResult) return;
if (instanceSpecificData?.reverseSearchResult) return;
isSearchingForSimilarPosts.value++;
try {
await ensurePostHasContentToken(selectedInstance, post, cfg);
let res: ImageSearchResult | undefined;
const res = await selectedInstance.reverseSearchToken(instanceSpecificData.contentToken!);
if (cfg.value.useContentTokens) {
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 = {
exactPostId: res.exactPost?.id,
@ -323,66 +295,43 @@ async function loadTagCounts() {
// Not the best code, but it works I guess?
if (resp) {
for (let post of pop.posts)
for (let tag of resp.results) {
const postTag = post.tags.find((postTag) => tag.names.includes(postTag.name));
if (postTag) postTag.usages = tag.usages;
for (let tag of resp.results)
for (let postTag of post.tags)
if (postTag.name == tag.names[0]) {
postTag.usages = tag.usages;
break;
}
}
}
}
async function updatePostWithRemoteInfo(post: ScrapedPostDetails, contentUrl: string) {
async function fetchPostInfo() {
for (const post of pop.posts) {
if (!post.contentSize || post.extraContentUrl) {
// 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.
try {
// This request follows redirects.
const contentUrl = post.extraContentUrl ?? post.contentUrl;
// 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 size = res.headers.get("Content-Length");
const type = res.headers.get("Content-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.",
);
}
if (size) post.contentSize = parseInt(size);
if (type) {
const [_main, sub] = type.split("/");
if (sub) post.contentSubType = sub.toUpperCase();
}
// This should be after the type check, because the type check also checks whether the response we get is valid/unsable.
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}'`);
// Resolve extraContentUrl redirects.
if (post.extraContentUrl && res.url != post.contentUrl) {
post.contentUrl = res.url;
}
return true;
} catch (ex) {
// TODO: Maybe display an error in the UI.
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);
}
}
}
@ -394,8 +343,7 @@ function getUpdatedTagsText(count: number) {
}
function onResolutionLoaded(res: any) {
// This no longer checks for `!pop.selectedPost.resolution` because the resolution can change if the contentUrl is updated.
if (pop.selectedPost) {
if (pop.selectedPost && !pop.selectedPost.resolution) {
pop.selectedPost.resolution = res;
}
}

View File

@ -1,7 +1,6 @@
import { defineStore } from "pinia";
import deepMerge from "deepmerge";
import {
type TagDetails,
getDefaultTagCategories,
type ScrapedPostDetails,
type SetPostUploadInfoData,
@ -15,8 +14,6 @@ export const cfg = useStorageLocal(
{
version: 0,
addPageUrlToSource: true,
alwaysUploadAsContent: false,
sendUploadNotifications: false,
autoSearchSimilar: false,
loadTagCounts: true,
fetchPostInfo: true,
@ -41,7 +38,6 @@ export const cfg = useStorageLocal(
showInstancePicker: true,
},
tagCategories: [] as Array<TagCategoryColor>,
tagIgnores: [] as Array<TagDetails>,
},
{
mergeDefaults(storageValue, defaults) {

View File

@ -268,9 +268,3 @@ a.remove-tag {
.color-primary {
color: var(--primary-color);
}
.separated-content > * + * {
padding-top: 1rem;
margin-top: 1.5rem;
border-top: 3px solid #333;
}

View File

@ -1,7 +1,6 @@
import byteSize from "byte-size";
import { MicroUser, Post } from "./api/models";
import { ScrapedPostDetails, TagDetails } from "./models";
import SzurubooruApi from "./api";
export function getUrl(root: string, ...parts: string[]): string {
let url = root.replace(/\/+$/, "");
@ -103,28 +102,3 @@ export function getPostInfoSummary(post: ScrapedPostDetails) {
}
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;
}
}

View File

@ -1,12 +0,0 @@
{
"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"
}
]
}
}
}