重构为Monorepo:拆分xhs/xhh应用与core包并完成双服务部署改造
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { extractLinkIdFromUrl, extractUserIdFromUrl } from './extractors.js';
|
||||
|
||||
interface FeedTargetInput {
|
||||
link_id?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
interface UserTargetInput {
|
||||
user_id?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface FeedTargetResolved {
|
||||
linkId: string;
|
||||
}
|
||||
|
||||
export interface UserTargetResolved {
|
||||
userId: string;
|
||||
}
|
||||
|
||||
function normalizeUrl(url: string): string {
|
||||
const trimmed = url.trim();
|
||||
if (!trimmed) {
|
||||
throw new Error('url cannot be empty');
|
||||
}
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
export function resolveFeedTarget(input: FeedTargetInput): FeedTargetResolved {
|
||||
const direct = input.link_id?.trim();
|
||||
if (direct) return { linkId: direct };
|
||||
|
||||
if (input.url) {
|
||||
const parsed = extractLinkIdFromUrl(normalizeUrl(input.url));
|
||||
if (parsed) return { linkId: parsed };
|
||||
}
|
||||
|
||||
throw new Error('xhh_get_feed_detail requires link_id or url containing link_id');
|
||||
}
|
||||
|
||||
export function resolveUserTarget(input: UserTargetInput): UserTargetResolved {
|
||||
const direct = input.user_id?.trim();
|
||||
if (direct) return { userId: direct };
|
||||
|
||||
if (input.url) {
|
||||
const parsed = extractUserIdFromUrl(normalizeUrl(input.url));
|
||||
if (parsed) return { userId: parsed };
|
||||
}
|
||||
|
||||
throw new Error('xhh_get_user_profile requires user_id or url containing user_id');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user