diff --git a/package.json b/package.json
index 8c7aad1..62f144f 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,7 @@
"dependencies": {
"axios": "^1.2.2",
"basscss": "^8.1.0",
+ "byte-size": "^8.1.1",
"deepmerge": "^4.3.1",
"lodash": "^4.17.21",
"markdown-it": "^13.0.1",
@@ -41,6 +42,7 @@
"@fortawesome/fontawesome-svg-core": "^6.2.1",
"@fortawesome/free-solid-svg-icons": "^6.2.1",
"@fortawesome/vue-fontawesome": "^3.0.3",
+ "@types/byte-size": "^8.1.0",
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.194",
"@types/markdown-it": "^12.2.3",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index af9abe4..06fb67b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -5,6 +5,7 @@ specifiers:
'@fortawesome/fontawesome-svg-core': ^6.2.1
'@fortawesome/free-solid-svg-icons': ^6.2.1
'@fortawesome/vue-fontawesome': ^3.0.3
+ '@types/byte-size': ^8.1.0
'@types/fs-extra': ^9.0.13
'@types/lodash': ^4.14.194
'@types/markdown-it': ^12.2.3
@@ -17,6 +18,7 @@ specifiers:
'@vueuse/core': ^9.6.0
axios: ^1.2.2
basscss: ^8.1.0
+ byte-size: ^8.1.1
chokidar: ^3.5.3
cross-env: ^7.0.3
crx: ^5.0.1
@@ -49,6 +51,7 @@ specifiers:
dependencies:
axios: 1.4.0
basscss: 8.1.0
+ byte-size: 8.1.1
deepmerge: 4.3.1
lodash: 4.17.21
markdown-it: 13.0.1
@@ -62,6 +65,7 @@ devDependencies:
'@fortawesome/fontawesome-svg-core': 6.4.0
'@fortawesome/free-solid-svg-icons': 6.4.0
'@fortawesome/vue-fontawesome': 3.0.3_5vq7vkrflr3ckmegqnktogj5ty
+ '@types/byte-size': 8.1.0
'@types/fs-extra': 9.0.13
'@types/lodash': 4.14.194
'@types/markdown-it': 12.2.3
@@ -872,6 +876,10 @@ packages:
engines: {node: '>= 10'}
dev: true
+ /@types/byte-size/8.1.0:
+ resolution: {integrity: sha512-LCIlZh8vyx+I2fgRycE1D34c33QDppYY6quBYYoaOpQ1nGhJ/avSP2VlrAefVotjJxgSk6WkKo0rTcCJwGG7vA==}
+ dev: true
+
/@types/chai-subset/1.3.3:
resolution: {integrity: sha512-frBecisrNGz+F4T6bcc+NLeolfiojh5FxW2klu669+8BARtyQv2C/GkNW6FUodVe4BroGMP/wER/YDGc7rEllw==}
dependencies:
@@ -1687,6 +1695,11 @@ packages:
safe-json-stringify: 1.2.0
dev: true
+ /byte-size/8.1.1:
+ resolution: {integrity: sha512-tUkzZWK0M/qdoLEqikxBWe4kumyuwjl3HO6zHTr4yEI23EojPtLYXdG1+AQY7MN0cGyNDvEaJ8wiYQm6P2bPxg==}
+ engines: {node: '>=12.17'}
+ dev: false
+
/c12/1.4.1:
resolution: {integrity: sha512-0x7pWfLZpZsgtyotXtuepJc0rZYE0Aw8PwNAXs0jSG9zq6Sl5xmbWnFqfmRY01ieZLHNbvneSFm9/x88CvzAuw==}
dependencies:
diff --git a/src/components/PostInfoSummary.vue b/src/components/PostInfoSummary.vue
new file mode 100644
index 0000000..f3472e1
--- /dev/null
+++ b/src/components/PostInfoSummary.vue
@@ -0,0 +1,29 @@
+
+
+
+
+ {{ byteSize(modelValue.contentSize) }}
+ {{ modelValue.contentSubType }}
+ ({{ resolutionToString(modelValue.resolution) }})
+
+
+
+
diff --git a/src/models/index.ts b/src/models/index.ts
index b009ace..b1a68af 100644
--- a/src/models/index.ts
+++ b/src/models/index.ts
@@ -47,8 +47,10 @@ export class ScrapedPostDetails {
tags: TagDetails[] = [];
notes: ScrapedNote[];
contentUrl: string;
+ contentSize: number | undefined;
pageUrl: string;
contentType: ContentType;
+ contentSubType: string | undefined;
rating: BooruTypes.SafetyRating;
source = "";
referrer?: string;
@@ -57,6 +59,7 @@ export class ScrapedPostDetails {
constructor(post: ScrapedPost) {
this.contentUrl = post.contentUrl;
+ // this.contentSize = post.contentSize;
this.pageUrl = post.pageUrl;
this.contentType = post.contentType;
this.rating = post.rating;
@@ -118,11 +121,7 @@ export class PostUploadCommandData {
}
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 {
@@ -134,5 +133,9 @@ export class SetExactPostId {
}
export class PostUpdateCommandData {
- constructor(public readonly postId: number, public readonly updateRequest: UpdatePostRequest, public readonly selectedSite: SzuruSiteConfig) {}
+ constructor(
+ public readonly postId: number,
+ public readonly updateRequest: UpdatePostRequest,
+ public readonly selectedSite: SzuruSiteConfig
+ ) {}
}
diff --git a/src/popup/pages/PopupMain.vue b/src/popup/pages/PopupMain.vue
index c591f14..53d0b06 100644
--- a/src/popup/pages/PopupMain.vue
+++ b/src/popup/pages/PopupMain.vue
@@ -2,7 +2,7 @@
import { useDark } from "@vueuse/core";
import { cloneDeep } from "lodash";
import { ScrapeResults } from "neo-scraper";
-import { getUrl, encodeTagName, getErrorMessage } from "~/utils";
+import { getUrl, encodeTagName, getErrorMessage, getPostInfoSummary } from "~/utils";
import {
BrowserCommand,
ScrapedPostDetails,
@@ -124,8 +124,10 @@ async function grabPost() {
if (cfg.value.loadTagCounts) {
loadTagCounts();
}
- } else {
- // pushInfo("No posts found.");
+
+ if (cfg.value.fetchPostInfo) {
+ fetchPostInfo();
+ }
}
}
@@ -154,13 +156,6 @@ async function upload() {
}
}
-function resolutionToString(resolution: [number, number]) {
- if (resolution && resolution.length == 2) {
- return resolution[0] + "x" + resolution[1];
- }
- return "";
-}
-
function removeTag(tag: TagDetails) {
if (pop.selectedPost) {
const idx = pop.selectedPost.tags.indexOf(tag);
@@ -275,6 +270,29 @@ async function loadTagCounts() {
}
}
+async function fetchPostInfo() {
+ for (const post of pop.posts) {
+ if (!post.contentSize) {
+ // 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 {
+ const res = await fetch(post.contentUrl, { method: "HEAD" });
+ const size = res.headers.get("Content-Length");
+ const type = res.headers.get("Content-Type");
+
+ if (size) post.contentSize = parseInt(size);
+
+ if (type) {
+ const [_main, sub] = type.split("/");
+ if (sub) post.contentSubType = sub.toUpperCase();
+ }
+ } catch {
+ // TODO: Log errors.
+ }
+ }
+ }
+}
+
// Cool people would use https://kazupon.github.io/vue-i18n/guide/pluralization.html
function getUpdatedTagsText(count: number) {
return `Updated ${count} tag${count > 1 ? "s" : ""}`;
@@ -438,10 +456,8 @@ useDark();
-
-
- - Resolution: {{ resolutionToString(pop.selectedPost.resolution) }}
-
+
@@ -500,7 +516,10 @@ useDark();