Add sampled_name

This commit is contained in:
2023-06-25 13:42:24 +08:00
parent 214c419593
commit 494a0f66e3
3 changed files with 23 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import { DOMParser, Element } from "deno_dom/deno-dom-wasm-noinit.ts";
import { extname } from "std/path/mod.ts";
import { Client } from "../client.ts";
import { EhFile, PMeta } from "../db.ts";
import { initDOMParser, map, parse_bool } from "../utils.ts";
@@ -75,6 +76,15 @@ class Image {
get page_token() {
return this.base.token;
}
get sampled_name() {
const name = this.data?.name;
if (name) return name;
const n = this.base.name;
const e = extname(n);
const b = n.slice(0, n.length - e.length);
if (n === ".gif") return `${b}.gif`;
return `${b}.jpg`;
}
get src() {
return this.data?.img_url;
}

View File

@@ -1,4 +1,5 @@
import { DOMParser } from "deno_dom/deno-dom-wasm-noinit.ts";
import { extname } from "std/path/mod.ts";
import { Client } from "../client.ts";
import { initDOMParser } from "../utils.ts";
import { EhFile, PMeta } from "../db.ts";
@@ -122,6 +123,13 @@ class MPVImage {
get page_token() {
return this.base.k;
}
get sampled_name() {
const n = this.base.n;
const e = extname(n);
const b = n.slice(0, n.length - e.length);
if (n === ".gif") return `${b}.gif`;
return `${b}.jpg`;
}
get src() {
return this.data?.i;
}