adding tracks swiper
This commit is contained in:
@@ -7,6 +7,20 @@ import { ConfigService } from '@nestjs/config';
|
||||
|
||||
private containerName: string;
|
||||
|
||||
private streamToBuffer(readableStream: NodeJS.ReadableStream) {
|
||||
return new Promise<Buffer>((resolve, reject) => {
|
||||
const chunks = [];
|
||||
|
||||
readableStream.on('data', (data) => {
|
||||
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
|
||||
});
|
||||
readableStream.on('end', () => {
|
||||
resolve(Buffer.concat(chunks));
|
||||
});
|
||||
readableStream.on('error', reject)
|
||||
})
|
||||
}
|
||||
|
||||
async getBlobServiceInstance() {
|
||||
const connectionString = this.configService.get<string>('azureStorageConnectionString');
|
||||
const blobServiceClient: BlobServiceClient = await BlobServiceClient.fromConnectionString(connectionString)
|
||||
@@ -23,7 +37,7 @@ import { ConfigService } from '@nestjs/config';
|
||||
return blockBlobClient;
|
||||
}
|
||||
|
||||
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string) {
|
||||
async uploadFile(file: Express.Multer.File, containerName: string, rowKey: string): Promise<string> {
|
||||
this.containerName = containerName;
|
||||
|
||||
const blockBlobClient = await this.getBlobClient(`${rowKey}/${file.originalname}`);
|
||||
@@ -34,7 +48,17 @@ import { ConfigService } from '@nestjs/config';
|
||||
return fileUrl;
|
||||
}
|
||||
|
||||
async deleteFile(containerName: string, rowKey:string, fileName: string) {
|
||||
async downloadFile(containerName: string, rowKey: string, fileName: string): Promise<string> {
|
||||
this.containerName = containerName;
|
||||
|
||||
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
|
||||
const downloadBlockBlobResponse = await blockBlobClient.download();
|
||||
const downloaded: string = (await this.streamToBuffer(downloadBlockBlobResponse.readableStreamBody)).toString()
|
||||
|
||||
return downloaded
|
||||
}
|
||||
|
||||
async deleteFile(containerName: string, rowKey:string, fileName: string): Promise<void> {
|
||||
this.containerName = containerName;
|
||||
|
||||
const blockBlobClient = await this.getBlobClient(`${rowKey}/${fileName}`);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
StreamableFile,
|
||||
UploadedFile,
|
||||
UseGuards,
|
||||
UseInterceptors
|
||||
@@ -22,14 +23,15 @@ import { FileService } from '../file/file.service';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
|
||||
@Controller('logs')
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
export class LogController {
|
||||
constructor(
|
||||
private readonly fileService: FileService,
|
||||
private readonly logService: LogService
|
||||
) {}
|
||||
|
||||
|
||||
@Get(':partitionKey/:rowKey')
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
async find(
|
||||
@Param('partitionKey') partitionKey: string,
|
||||
@Param('rowKey') rowKey: string
|
||||
@@ -44,6 +46,7 @@ export class LogController {
|
||||
}
|
||||
|
||||
@Get()
|
||||
@UseInterceptors(new LogInterceptor())
|
||||
async findAll(): Promise<Log[]> {
|
||||
try {
|
||||
return await this.logService.findAll();
|
||||
@@ -121,11 +124,18 @@ export class LogController {
|
||||
}
|
||||
}
|
||||
|
||||
@Get(':partitionKey/:rowKey/track')
|
||||
async downloadTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<string> {
|
||||
const containerName = 'tracks';
|
||||
const downloadedFile: string = await this.fileService.downloadFile(containerName, rowKey, fileName)
|
||||
|
||||
return downloadedFile;
|
||||
}
|
||||
|
||||
@UseGuards(AuthGuard)
|
||||
@Delete(':partitionKey/:rowKey/track')
|
||||
async deleteTrack(@Param('rowKey') rowKey: string, @Query('fileName') fileName: string): Promise<void> {
|
||||
try {
|
||||
console.log(fileName)
|
||||
const containerName = 'tracks';
|
||||
|
||||
return await this.fileService.deleteFile(containerName, rowKey, fileName)
|
||||
|
||||
Reference in New Issue
Block a user