0.3.0原版

This commit is contained in:
2026-07-19 19:10:32 +08:00
commit 0b6afa0665
39 changed files with 5690 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
import { Throttler } from "../../throttler";
import Axios from "axios";
import { Agent } from "https";
import { handleForbiddenErr, MOCK_UA, TIME_OUT } from "./common";
import { logger } from "../../logger";
import { waitMs } from "../../../utils";
export class DomainNotFoundError extends Error {
constructor(domain: string) {
super(`domain: ${domain}`);
}
}
export const createDomainAPI = () => {
const runner = new Throttler('domain');
const httpsAgent = new Agent({ keepAlive: true });
const axiosInstance = Axios.create({
timeout: TIME_OUT,
httpsAgent
});
return {
getUIDByDomain: (domain: string) => runner.runFunc<string>(async (disable) => {
logger.debug(`[domain] convert ${domain}`);
await waitMs(Math.floor(Math.random() * 100));
return await axiosInstance.get(`https://m.weibo.cn/${domain}?&jumpfrom=weibocom`, {
headers: {
'User-Agent': MOCK_UA,
},
}).then(res => {
const uid = res.request.path.split("/u/")[1] as string;
if (!uid) {
throw new DomainNotFoundError(domain);
}
return uid;
}).catch(err => handleForbiddenErr(err, disable));
}),
};
};
export type GetUIDByDomainFunc = ReturnType<typeof createDomainAPI>['getUIDByDomain'];