import { Injectable } from '@angular/core'; import { FmodeParse } from "fmode-ng/core"; @Injectable({ providedIn: 'root' }) export class TikHubService { private Parse: any; // Cloud Function IDs private readonly FUNCTIONS = { SEARCH_USER: 'BHmiTlSNA4', GET_PROFILE: 'UfDBWNeH90', GET_POSTS: 'rZ5HSTDpMm', GET_COMMENTS: '6sjEatiEN8' }; constructor() { this.Parse = FmodeParse.initialize({ appId: "ncloudmaster", serverURL: "https://server.fmode.cn/parse" }); } /** * Search for TikTok users * @param keyword Search keyword * @param cursor Pagination cursor */ async searchUsers(keyword: string, cursor: number = 0): Promise { try { const result = await this.Parse.Cloud.function({ id: this.FUNCTIONS.SEARCH_USER, keyword, cursor }); if (result.code === 200 && result.success) { return result.data; } else { throw new Error(result.error || 'Search failed'); } } catch (error) { console.error('TikHub Search Error:', error); throw error; } } /** * Get user profile details * @param uniqueId User handle (e.g. @username) */ async getUserProfile(uniqueId: string): Promise { try { const result = await this.Parse.Cloud.function({ id: this.FUNCTIONS.GET_PROFILE, unique_id: uniqueId }); if (result.code === 200 && result.success) { return result.data; } else { throw new Error(result.error || 'Get Profile failed'); } } catch (error) { console.error('TikHub Profile Error:', error); throw error; } } /** * Get user posts * @param secUid User secure UID * @param count Number of posts * @param cursor Pagination cursor */ async getUserPosts(secUid: string, count: number = 20, cursor: number = 0): Promise { try { const result = await this.Parse.Cloud.function({ id: this.FUNCTIONS.GET_POSTS, sec_user_id: secUid, count, cursor }); if (result.code === 200 && result.success) { return result.data; } else { throw new Error(result.error || 'Get Posts failed'); } } catch (error) { console.error('TikHub Posts Error:', error); throw error; } } /** * Get video comments * @param videoId Video ID * @param count Number of comments * @param cursor Pagination cursor */ async getPostComments(videoId: string, count: number = 50, cursor: number = 0): Promise { try { const result = await this.Parse.Cloud.function({ id: this.FUNCTIONS.GET_COMMENTS, video_id: videoId, count, cursor }); if (result.code === 200 && result.success) { return result.data; } else { throw new Error(result.error || 'Get Comments failed'); } } catch (error) { console.error('TikHub Comments Error:', error); throw error; } } }