feat: duitang support

This commit is contained in:
hyperdefined 2025-06-27 20:12:37 -04:00
parent 14b9a590d9
commit 4b5bf5e556
No known key found for this signature in database
GPG Key ID: 38C93C4835071D4A
6 changed files with 107 additions and 1 deletions

View File

@ -104,6 +104,7 @@ export default function({
case "snapchat":
case "bsky":
case "xiaohongshu":
case "duitang":
params = { picker: r.picker };
break;

View File

@ -29,6 +29,7 @@ import loom from "./services/loom.js";
import facebook from "./services/facebook.js";
import bluesky from "./services/bluesky.js";
import xiaohongshu from "./services/xiaohongshu.js";
import duitang from "./services/duitang.js";
let freebind;
@ -268,6 +269,13 @@ export default async function({ host, patternMatch, params, authType }) {
});
break;
case "duitang":
r = await duitang({
id: patternMatch.id,
type: patternMatch.type,
});
break;
default:
return createResponse("error", {
code: "error.api.service.unsupported"

View File

@ -22,6 +22,10 @@ export const services = {
dailymotion: {
patterns: ["video/:id"],
},
duitang: {
patterns: [ ":type?id=:id" ],
subdomains: ["m"]
},
facebook: {
patterns: [
"_shortLink/:shortLink",
@ -213,7 +217,7 @@ export const services = {
"v/:id"
],
subdomains: ["music", "m"],
}
},
}
Object.values(services).forEach(service => {

View File

@ -5,6 +5,10 @@ export const testers = {
"dailymotion": pattern => pattern.id?.length <= 32,
"duitang": pattern =>
(pattern.type == 'blog' || pattern.type == 'atlas') &&
pattern.id?.length <= 10,
"instagram": pattern =>
pattern.postId?.length <= 48
|| pattern.shareId?.length <= 16

View File

@ -0,0 +1,84 @@
import { genericUserAgent, env } from "../../config.js";
import { createStream } from "../../stream/manage.js"
export default async function(post) {
let filenameBase = `duitang_${post.id}`
if (post.type == 'blog') {
let req = await fetch(`https://www.duitang.com/napi/blog/detail/?blog_id=${post.id}`, {
headers: {
'User-Agent': genericUserAgent,
}
})
.then(request => request.text())
.catch(() => {});
if (!req) return { error: 'fetch.fail' };
let json;
try {
json = JSON.parse(req);
} catch { return { error: 'fetch.empty' }; }
let originalUrl = json.data.photo.path.toString();
const image = {
// always proxy here because of headers
type: "photo",
url: createStream({
service: "duitang",
type: "proxy",
url: originalUrl,
filename: `${filenameBase}_photo.jpg`,
headers: {
'Host': 'c-ssl.dtstatic.com',
'Referer': 'https://duitang.com'
}
})
}
return {
picker: [image]
};
}
if (post.type == 'atlas') {
let req = await fetch(`https://www.duitang.com/napi/vienna/atlas/detail/?atlas_id=${post.id}`, {
headers: {
'User-Agent': genericUserAgent,
}
})
.then(request => request.text())
.catch(() => {});
if (!req) return { error: 'fetch.fail' };
let json;
try {
json = JSON.parse(req);
} catch { return { error: 'fetch.empty' }; }
let imageLinks = json.data.blogs
.map(blog => blog.photo?.path)
.map((url, i) => {
// always proxy here because of headers
url = createStream({
service: "duitang",
type: "proxy",
url: url,
filename: `${filenameBase}_photo_${i + 1}.jpg`,
headers: {
'Host': 'c-ssl.dtstatic.com',
'Referer': 'https://duitang.com'
}
});
return {
type: "photo",
url
};
});
return {
picker: imageLinks
}
}
}

View File

@ -134,6 +134,11 @@ function cleanURL(url) {
}
switch (host) {
case "duitang":
if (url.searchParams.get('id')) {
limitQuery('id');
}
break;
case "pinterest":
url.hostname = 'pinterest.com';
break;