import http from '@src/http'; import { uploadLogApi } from '@src/http/api'; import sso from '@src/http/sso'; import { VideoItem } from '@src/views/publishContent/types'; import { RecentNotUsedType, SortTypeEnum, TagType, VideoLibraryType } from '@src/views/publishContent/weCom/components/videoSelectModal'; import { VideoSearchPlanType } from '@src/views/publishContent/weCom/type'; type NormalLogParams = { traceId: number; requestId: number; planType?: VideoSearchPlanType; gzhAccountId?: number; subChannel?: string; } type VideoListQueryLogParams = { category?: string; title?: string; recentNotUsed?: RecentNotUsedType; sortType?: SortTypeEnum; tags?: TagType[]; videoLibraryType?: VideoLibraryType; } & NormalLogParams; type VideoLogParams = { videoId: number; score?: number; tags?: TagType[]; title?: string; cover?: string; libraryType?: VideoLibraryType; playTime?: number; idx?: number; collect?: number; } & NormalLogParams; interface PublishPlanLogParams extends NormalLogParams { videoList: VideoItem[]; } const useLogger = () => { const token = sso.getUserInfo()?.token; const channel = sso.getUserInfo()?.channel; const userId = sso.getUserInfo()?.id; const timestamp = Date.now(); const userAgent = navigator.userAgent; const page = window.location.pathname; const uploadLog = async ({ businessType, objectType, extParams }: { businessType: string, objectType?: string, extParams?: Record }) => { const log = { token, channel, userId, page, userAgent, timestamp, businessType, objectType, extParams, }; const response = await http.post(uploadLogApi, { key: 'content-platform-user-behavior', data: log, }); return response; } const uploadLogVideoListQuery = ({ traceId, requestId, planType, gzhAccountId, subChannel, category, title, recentNotUsed, sortType, tags, videoLibraryType, }:VideoListQueryLogParams) => { return uploadLog({ businessType: 'video_list_query', objectType: 'video_list', extParams: { traceId, requestId, planType, gzhAccountId, subChannel, category, title, recentNotUsed, sortType, tags, videoLibraryType, }, }); } const uploadLogVideoPlay = ({videoId, traceId, requestId, planType, gzhAccountId, subChannel}: VideoLogParams) => { return uploadLog({ businessType: 'video_play', objectType: 'video', extParams: { videoId, traceId, requestId, planType, gzhAccountId, subChannel, }, }); } const uploadLogVideoPlayEnd = ({videoId, playTime, traceId, requestId, planType, gzhAccountId, subChannel}: VideoLogParams) => { return uploadLog({ businessType: 'video_play_end', objectType: 'video', extParams: { videoId, playTime, traceId, requestId, planType, gzhAccountId, subChannel, }, }); } const uploadLogVideoView = ({videoId, idx, score, tags, title, cover, libraryType, traceId, requestId, planType, gzhAccountId, subChannel}: VideoLogParams) => { return uploadLog({ businessType: 'video_view', objectType: 'video', extParams: { videoId, idx, score, tags, title, cover, libraryType, traceId, requestId, planType, gzhAccountId, subChannel, }, }); } const uploadLogVideoCollect = ({videoId, traceId, requestId, collect, planType, gzhAccountId, subChannel}: VideoLogParams) => { return uploadLog({ businessType: 'video_collect', objectType: 'video', extParams: { videoId, traceId, requestId, collect, planType, gzhAccountId, subChannel, }, }); } const uploadLogVideoCreatePublish = ({ videoList, traceId, requestId, planType, gzhAccountId, subChannel }: PublishPlanLogParams) => { return uploadLog({ businessType: 'publish_plan_create', objectType: 'publish_plan', extParams: { videoList, traceId, requestId, planType, gzhAccountId, subChannel, }, }); } return { uploadLog, uploadLogVideoPlay, uploadLogVideoView, uploadLogVideoPlayEnd, uploadLogVideoCollect, uploadLogVideoListQuery, uploadLogVideoCreatePublish, }; }; export default useLogger;