From 0c65c8f0d43a6f2df3569f1828600e787ae30a87 Mon Sep 17 00:00:00 2001 From: Tony Date: Wed, 4 Sep 2024 15:21:31 +0800 Subject: [PATCH] fix: BUG --- src/tdtmap/tdtmap.controller.ts | 2 +- src/tdtmap/tdtmap.service.ts | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tdtmap/tdtmap.controller.ts b/src/tdtmap/tdtmap.controller.ts index 27276cc..13fb33e 100644 --- a/src/tdtmap/tdtmap.controller.ts +++ b/src/tdtmap/tdtmap.controller.ts @@ -70,6 +70,7 @@ export class TdtmapController { // minio 中存在,从 minio 取出 const dbItem:Buffer = await this.tdtmapService.getTileFromLocal(tileFormattedName) // 从 minio 取出来 cacheMap.set(tileFormattedName, dbItem) + Buffer.from(dbItem as any, 'utf-8') return new StreamableFile(dbItem); } else { // 如果本地数据库都不存在 @@ -85,7 +86,6 @@ export class TdtmapController { cacheMap.set(tileFormattedName, res.data) const saveSuccess = await this.tdtmapService.setTileToLocal(tileFormattedName, res.data); if (saveSuccess) bloomFilter.add(tileFormattedName); - Buffer.from(res.data, 'utf-8') return new StreamableFile(res.data); // 请求成功 } else { diff --git a/src/tdtmap/tdtmap.service.ts b/src/tdtmap/tdtmap.service.ts index 697beb5..19f8166 100644 --- a/src/tdtmap/tdtmap.service.ts +++ b/src/tdtmap/tdtmap.service.ts @@ -30,10 +30,12 @@ export class TdtmapService { async getTileFromLocal(tile_name:string):Promise { return new Promise(async (resolve, reject) => { const stream = await this.minioClient.getObject("nestfiles", tile_name) - let res:any = null - stream.on("data", (data) => { res = data }) + const res:any[] = [] + stream.on("data", (data:Buffer) => { + if (Buffer.isBuffer(data)) res.push(data) + }) stream.on("end", () => { - if (res) resolve(res) + if (res.length > 0) resolve(Buffer.concat(res)) else reject() }) stream.on("error", () => { reject() })