MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / sendLocalUpload

Method sendLocalUpload

music_hub/music_hub.ts:858–1007  ·  view source on GitHub ↗
(
    client: any,
    msg: Api.Message,
    song: ApiSong,
    urlInfo: SongUrlInfo,
    config: MusicHubConfig,
    caption: string,
    session?: SearchSession,
    onProgress?: TransferProgressReporter
  )

Source from the content-addressed store, hash-verified

856 clearInterval(timer);
857 timer = undefined;
858 }
859 await sendLatest(true);
860 await updateQueue.catch(() => undefined);
861 },
862 };
863 }
864
865 private async sendLocalUpload(
866 client: any,
867 msg: Api.Message,
868 song: ApiSong,
869 urlInfo: SongUrlInfo,
870 config: MusicHubConfig,
871 caption: string,
872 session?: SearchSession,
873 onProgress?: TransferProgressReporter
874 ): Promise<void> {
875 let tempFilePath = "";
876 try {
877 const response = await axios.get<any>(urlInfo.url, {
878 responseType: "stream",
879 timeout: DOWNLOAD_TIMEOUT_MS,
880 maxContentLength: config.maxUploadBytes,
881 maxBodyLength: config.maxUploadBytes,
882 headers: {
883 "User-Agent": "TeleBox-MusicHub/1.0",
884 },
885 });
886
887 const reader = response.data as any;
888 if (!reader || typeof reader.pipe !== "function") {
889 throw new Error("下载响应不是可读流");
890 }
891
892 const contentLength = Number(response.headers?.["content-length"]);
893 const totalBytes =
894 Number.isFinite(contentLength) && contentLength > 0
895 ? contentLength
896 : urlInfo.size;
897 if (totalBytes && totalBytes > config.maxUploadBytes) {
898 throw new Error(`文件过大 (${formatBytes(totalBytes)}),超过上传限制 ${formatBytes(config.maxUploadBytes)}`);
899 }
900 const extension = detectAudioExtension(
901 urlInfo.url,
902 String(response.headers?.["content-type"] || "")
903 );
904 const filename = `${sanitizeFilename(`${song.name}-${formatArtists(song.artist)}`)}.${extension}`;
905 tempFilePath = path.join(TEMP_DIR, `${Date.now()}_${filename}`);
906 let downloadedBytes = 0;
907
908 await onProgress?.({
909 stage: "download",
910 loadedBytes: 0,
911 totalBytes,
912 force: true,
913 });
914
915 await new Promise<void>((resolve, reject) => {

Callers 1

sendSongMethod · 0.95

Calls 6

getReplyTargetMethod · 0.95
detectAudioExtensionFunction · 0.85
sanitizeFilenameFunction · 0.85
formatArtistsFunction · 0.85
clampFractionFunction · 0.85
formatBytesFunction · 0.70

Tested by

no test coverage detected