Add experimental post filetype and (byte)size display
parent
1376ea8fd5
commit
96466b9199
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
<script setup lang="ts">
|
||||
import byteSize from "byte-size";
|
||||
import { PropType } from "vue";
|
||||
import { ScrapedPostDetails } from "~/models";
|
||||
import { resolutionToString } from "~/utils";
|
||||
|
||||
defineProps({
|
||||
modelValue: {
|
||||
required: true,
|
||||
type: Object as PropType<ScrapedPostDetails>,
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="basic-info-inline">
|
||||
<span v-if="modelValue.contentSize">{{ byteSize(modelValue.contentSize) }}</span>
|
||||
<span v-if="modelValue.contentSubType">{{ modelValue.contentSubType }}</span>
|
||||
<span v-if="modelValue.resolution">({{ resolutionToString(modelValue.resolution) }})</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.basic-info-inline {
|
||||
display: flex;
|
||||
gap: 0 1ch;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -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
|
||||
) {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
|||
<font-awesome-icon icon="fa-solid fa-cog" class="cursor-pointer" @click="openOptionsPage" />
|
||||
</template>
|
||||
|
||||
<div class="section-row" v-if="pop.selectedPost?.resolution">
|
||||
<ul class="compact">
|
||||
<li>Resolution: {{ resolutionToString(pop.selectedPost.resolution) }}</li>
|
||||
</ul>
|
||||
<div class="section-row" v-if="pop.selectedPost?.resolution || pop.selectedPost?.contentSize">
|
||||
<PostInfoSummary v-model="pop.selectedPost" />
|
||||
</div>
|
||||
|
||||
<div class="section-row">
|
||||
|
|
@ -500,7 +516,10 @@ useDark();
|
|||
<div class="popup-right">
|
||||
<div class="popup-section">
|
||||
<select v-model="pop.selectedPostId">
|
||||
<option v-for="post in pop.posts" :key="post.id" :value="post.id">{{ post.name }}</option>
|
||||
<!--    is used because duplicate space characters are usually removed by the browser. -->
|
||||
<option v-for="post in pop.posts" :key="post.id" :value="post.id">
|
||||
{{ post.name }}  -  {{ getPostInfoSummary(post) }}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export const cfg = useStorageLocal(
|
|||
addPageUrlToSource: true,
|
||||
autoSearchSimilar: false,
|
||||
loadTagCounts: true,
|
||||
fetchPostInfo: true,
|
||||
useContentTokens: true,
|
||||
sites: [] as Array<SzuruSiteConfig>,
|
||||
selectedSiteId: undefined as string | undefined,
|
||||
|
|
|
|||
24
src/utils.ts
24
src/utils.ts
|
|
@ -1,5 +1,6 @@
|
|||
import byteSize from "byte-size";
|
||||
import { MicroUser, Post } from "./api/models";
|
||||
import { TagDetails } from "./models";
|
||||
import { ScrapedPostDetails, TagDetails } from "./models";
|
||||
|
||||
export function getUrl(root: string, ...parts: string[]): string {
|
||||
let url = root.replace(/\/+$/, "");
|
||||
|
|
@ -80,3 +81,24 @@ export function breakTagName(tagName: string) {
|
|||
// Based on https://stackoverflow.com/a/6316913
|
||||
return tagName.replace(/_/g, "_<wbr>");
|
||||
}
|
||||
|
||||
export function resolutionToString(resolution: [number, number]) {
|
||||
if (resolution && resolution.length == 2) {
|
||||
return resolution[0] + "x" + resolution[1];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
export function getPostInfoSummary(post: ScrapedPostDetails) {
|
||||
const parts = [];
|
||||
if (post.contentSize) {
|
||||
parts.push(byteSize(post.contentSize));
|
||||
}
|
||||
if (post.contentSubType) {
|
||||
parts.push(post.contentSubType);
|
||||
}
|
||||
if (post.resolution) {
|
||||
parts.push(resolutionToString(post.resolution));
|
||||
}
|
||||
return parts.join(" / ");
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue