Skip to content

Commit

Permalink
exapanging mail service
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Nov 10, 2023
1 parent f8aecc3 commit 14688b3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions src/features/children/children.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { AllUserEntity } from 'src/entities/user.entity';
import { checkIfFileOrDirectoryExists, moveFile } from 'src/utils/file';
import fs from 'fs';
import { CampaignService } from '../campaign/campaign.service';
import { File } from '@web-std/file';

@ApiTags('Children')
@ApiSecurity('flask-access-token')
Expand All @@ -88,7 +89,7 @@ export class ChildrenController {
@UseInterceptors(FileInterceptor('voiceFile', voiceStorage))
async approvePreregister(
@Req() req: Request,
@UploadedFile() voiceFile,
@UploadedFile() voiceFile: Express.Multer.File,
@Param('id') id: string,
@Body(ValidateChildTsPipe) body: CreateFlaskChildDto,
) {
Expand Down Expand Up @@ -132,12 +133,20 @@ export class ChildrenController {
`${preRegister.sleptUrl}`,
);

const fileBuffer = await fs.promises.readFile(
`uploads/children/voices/${voiceFile.filename}`,
);

const file = new File([fileBuffer], `${voiceFile.filename}`, {
type: voiceFile.mimetype,
});

const formData = new FormData();
formData.append('ngo_id', String(preRegister.flaskNgoId));
formData.append('sw_id', String(preRegister.flaskSwId));
formData.append('awakeAvatarUrl', awakeFile);
formData.append('sleptAvatarUrl', sleptFile);
formData.append('voiceUrl', voiceFile);
formData.append('voiceUrl', file);
formData.append(
'gender',
String(preRegister.sex === SexEnum.MALE ? true : false),
Expand Down
1 change: 1 addition & 0 deletions src/features/download/download.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export class DownloadService {
console.log('Downloaded !! ' + name);
return file;
} catch (e) {
console.log(e);
throw new WalletExceptionFilter(e.status, e.message);
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/storage/voiceStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { uuid } from 'uuidv4';
import path from 'path';

export const voiceStorage = {
storage: diskStorage({
destination: './uploads/children/voices',
filename: (req, file, cb) => {
const fileName: string = path.parse(file.originalname).name.replace(/\s/g, '') + uuid() // unique id
const extension: string = path.parse(file.originalname).ext
return cb(null, `${fileName}${extension}`)
}
})
}
storage: diskStorage({
destination: './uploads/children/voices',
filename: (req, file, cb) => {
const fileName: string =
path.parse(file.originalname).name.replace(/\s/g, '') + uuid(); // unique id
const extension: string = path.parse(file.originalname).ext;
return cb(null, `${fileName}${extension}`);
},
}),
};

0 comments on commit 14688b3

Please sign in to comment.