{"record":{"id":"f5f6fc956be49aa0","repo":"yikart/AiToEarn","slug":"invalidworklink","errorCode":"InvalidWorkLink","errorMessage":"ResponseCode.InvalidWorkLink","messagePattern":"ResponseCode\\.InvalidWorkLink","errorType":"exception","errorClass":"AppException","httpStatus":null,"severity":"error","filePath":"project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/bilibili/bilibili-work.provider.ts","lineNumber":16,"sourceCode":"import type { ChannelWorkDataResult, WorkLinkInfoInput, WorkProvider } from '../platforms.interface'\nimport { Injectable, Logger } from '@nestjs/common'\nimport { PublishType } from '@yikart/aitoearn-server-shared'\nimport { AccountType, AppException, ResponseCode } from '@yikart/common'\nimport axios from 'axios'\n\n@Injectable()\nexport class BilibiliWorkProvider implements WorkProvider {\n  readonly requiresCredentialForLinkInfo = false\n  private readonly logger = new Logger(BilibiliWorkProvider.name)\n\n  async getLinkInfo(input: WorkLinkInfoInput): Promise<ChannelWorkDataResult> {\n    const resolvedUrl = await this.normalizeLink(input.link)\n    const dataId = this.parseVideoId(resolvedUrl)\n    if (!dataId) {\n      throw new AppException(ResponseCode.InvalidWorkLink)\n    }\n\n    const url = `https://www.bilibili.com/video/${dataId}`\n    return {\n      snapshots: [],\n      work: {\n        id: dataId,\n        url,\n        mediaType: PublishType.VIDEO,\n      },\n      extra: {\n        dataId,\n        uniqueId: `${AccountType.Bilibili}_${dataId}`,\n        type: PublishType.VIDEO,\n        videoType: 'long',\n        resolvedUrl: url,\n      },\n      rawResponse: { resolvedUrl },","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/yikart/AiToEarn/blob/d3aa8bea5b146a8675607cf0144d891aad3e9683/project/aitoearn-backend/apps/aitoearn-server/src/core/channels/platforms/bilibili/bilibili-work.provider.ts#L1-L34","documentation":"BilibiliWorkProvider.getLinkInfo normalizes the given work link and tries to extract a Bilibili video ID (BV/av). If parseVideoId returns null the link is not a recognizable Bilibili video URL, so it throws AppException InvalidWorkLink.","triggerScenarios":"getLinkInfo called with a link that, after normalizeLink/redirect resolution, does not match Bilibili video URL patterns (no BVxxx/avxxx ID), e.g. a space/album/article/live URL or an unrelated site URL.","commonSituations":"User pastes a mobile share link whose redirect target is not a video page; URL contains b23.tv short link that resolves to a non-video page; malformed/truncated URL; platform changed URL format.","solutions":["Validate the URL resolves to a /video/BV... or /video/av... path before calling getLinkInfo.","Ask the user to paste the canonical video URL (www.bilibili.com/video/BV...).","Update normalizeLink/parseVideoId regexes if Bilibili introduced new valid URL formats.","Catch InvalidWorkLink and return 'this link is not a Bilibili video' to the caller."],"exampleFix":"// before\nawait workProvider.getLinkInfo({ link: 'https://www.bilibili.com/space/xyz' })\n\n// after\nconst m = link.match(/bilibili\\.com\\/video\\/(BV[\\w]+|av\\d+)/)\nif (!m) throw new InvalidWorkLink()\nawait workProvider.getLinkInfo({ link })","handlingStrategy":"validation","validationCode":"const VIDEO_RE = /^https?:\\/\\/(www\\.)?bilibili\\.com\\/video\\/(BV[\\w]+|av\\d+)/i\nif (!VIDEO_RE.test(link) && !/^https?:\\/\\/b23\\.tv\\//.test(link)) {\n  throw new Error('Not a Bilibili video link')\n}","typeGuard":"function isBilibiliVideoUrl(url: string): boolean {\n  return /bilibili\\.com\\/video\\/(BV[\\w]+|av\\d+)/i.test(url)\n}","tryCatchPattern":"try {\n  info = await workProvider.getLinkInfo({ link })\n} catch (e) {\n  if (e.code === 'InvalidWorkLink') return { error: '请粘贴 B 站视频链接（/video/BV...）' }\n  throw e\n}","preventionTips":["Validate/normalize the URL client-side before submitting","Accept both canonical and b23.tv short links; resolve shorts first","Keep parseVideoId regexes updated with Bilibili URL formats"],"tags":["bilibili","url-parsing","validation"],"backgroundTag":"invalid-work-link","analyzedSha":"d3aa8bea5b146a8675607cf0144d891aad3e9683","analyzedAt":"2026-08-31T14:19:24.185Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}