Files
koc-loop/lib/partner-utils.ts

30 lines
761 B
TypeScript
Raw Normal View History

2026-07-30 12:06:41 +08:00
import { hashText } from "./mvp-db";
import {
extractXhsPublishUrl,
safeHttpUrl,
} from "./publish-url";
export { extractXhsPublishUrl } from "./publish-url";
export function accountFromPublishLink(input: string) {
2026-07-30 12:06:41 +08:00
const url = safeHttpUrl(extractXhsPublishUrl(input));
if (!url) return null;
const platform =
url.hostname.includes("xiaohongshu") || url.hostname.includes("xhslink")
? "小红书"
: "其他平台";
const noteId =
url.pathname.match(
/\/(?:discovery\/item|explore)\/([A-Za-z0-9_-]{8,80})/,
)?.[1] ?? "";
const platformUid = `pending-${hashText(
noteId || `${url.origin}${url.pathname}`,
)}`;
return {
platform,
platformUid,
nickname: "待识别账号",
2026-07-30 12:06:41 +08:00
profileUrl: "",
};
}