Initial commit: KOC LOOP platform
This commit is contained in:
29
lib/partner-utils.ts
Normal file
29
lib/partner-utils.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { hashText } from "./mvp-db";
|
||||
import {
|
||||
extractXhsPublishUrl,
|
||||
safeHttpUrl,
|
||||
} from "./publish-url";
|
||||
|
||||
export { extractXhsPublishUrl } from "./publish-url";
|
||||
|
||||
export function accountFromPublishLink(input: string, nickname: string) {
|
||||
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,
|
||||
profileUrl: "",
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user