Skip to content

Commit

Permalink
apiFileService将tgz解压函数独立实现
Browse files Browse the repository at this point in the history
  • Loading branch information
Val-istar-Guo committed Aug 12, 2024
1 parent 8d14a31 commit 9420794
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
21 changes: 12 additions & 9 deletions app/backend/src/modules/api-file/api-file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ export class ApiFileService {
return path.join('api-file', file.sheet.id, sheetVersion.version, file.path)
}

async createByTgz(dto: CreateApiFileByTgzDTO): Promise<ApiFile[]> {
/**
* Decompress tgz file buffer to files
* @param raw the tgz file buffer
*/
async decompress(raw: Buffer): Promise<FileRawDTO[]> {
const { temporaryDirectory } = (await import('tempy'))

const dir = temporaryDirectory()

await compressing.tgz.uncompress(dto.raw, dir)
await compressing.tgz.uncompress(raw, dir)

const pw = new PathScurry(dir, {
nocase: false,
Expand All @@ -71,17 +76,15 @@ export class ApiFileService {
filter: (file) => file.isFile(),
})

const fileRaws = await Promise.all(pwFiles.map(async (file): Promise<FileRawDTO> => ({
return await Promise.all(pwFiles.map(async (file): Promise<FileRawDTO> => ({
path: file.relative(),
raw: await fs.readFile(file.fullpath()),
})))
}


const apiFiles = await this.create({
...dto,
files: fileRaws,
})

async createByTgz(dto: CreateApiFileByTgzDTO): Promise<ApiFile[]> {
const fileRaws = await this.decompress(dto.raw)
const apiFiles = await this.create({ ...dto, files: fileRaws })
return apiFiles
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common'
import { AsyncapiSheetService } from './asyncapi-sheet.service'


@Module({
imports: [],
providers: [AsyncapiSheetService],
})
export class AsyncapiSheetModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injectable, Logger } from '@nestjs/common'


@Injectable()
export class AsyncapiSheetService {
private readonly logger = new Logger(AsyncapiSheetService.name)

constructor(
) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Module } from '@nestjs/common'
import { OpenapiSheetService } from './openapi-sheet.service'


@Module({
imports: [],
providers: [OpenapiSheetService],
})
export class OpenapiSheetModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Injectable, Logger } from '@nestjs/common'


@Injectable()
export class OpenapiSheetService {
private readonly logger = new Logger(OpenapiSheetService.name)

constructor(
) {}
}
6 changes: 6 additions & 0 deletions app/backend/src/modules/sheet/types/type-sheet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { SheetVersion } from '~/modules/sheet-version/entities/sheet-version.entity'
import { Sheet } from '../entities/sheet.entity'

export interface TypeSheet {
bumpSheetVersion(sheet: Sheet, tag?: string): Promise<SheetVersion>
}

0 comments on commit 9420794

Please sign in to comment.