209 похожих чатов

Всем привет. Сразу извиняюсь потому что я не профессионал, обращаюсь

к вам и надеюсь что поможете с находкой правильного решения поставленной задачей потому что я не уверен в моём подходе.

Стоит такая задача - Воплотить возможность скачивать все бэкап файлы в .zip формате с помощью выполнения скрипта на удаленном сервере.

По скрипту - обычный скрипт который в stdout возвращает .zip файл, в нём уже находятся все файлы для определенного бэкапа.

Сама команда выглядит примерно так:

restore.py --id south1-a-10 --time 1693170301 --path serverpro-us/www --pxar wpn10.pxar.didx --dst stdout dl

Как на данный момент я думаю о выполнении решения

- Создать метод в микросервисе который будет выполнять этот скрипт с помощью promisify(execFile)('restore.py', [...]), так весь микросервис построен на данный момент и все работает вроде стабильно

Потом с помощью ReadableBufferStream из пакета stream-buffers, поставить ответ из stdout, примерно вот таким образом

const bufferStream = new ReadableStreamBuffer();
bufferStream.put(stdout);
bufferStream.stop();

return bufferStream;

И уже в главном сервисе возвращать его так -

async exportAllAsZip(exportAllAsZipDTO: ExportAllAsZipRequestDTO): Promise<ReadableStreamBuffer> {
return await lastValueFrom(
this.backupClient.send('export-all-as-zip', exportAllAsZipDTO)
).catch((error) => {
throw new HttpException('Something went wrong', error.status);
});
}

и так в контроллере

@ApiBearerAuth('JWT-auth')
@ResourceAuthGuard(ResourceTypeEnum.site, GuardResourceTypeEnum.update)
@Post('export-all-as-zip/:externalId')
@Header('Content-Type', 'application/zip')
@Header('Content-Disposition', 'attachment; filename=backup.zip')
async exportAllAsZip(
@Body() exportAllAsZipDTO: ExportAllAsZipRequestDTO,
@Param('externalId') externalId: string,
@InjectItems() allowedIds: string[] | undefined
): Promise<ReadableStreamBuffer> {
if (allowedIds && !allowedIds.includes(externalId?.toLowerCase()))
throw new ForbiddenException('You have no access to this site');
try {
return this.backupService.exportAllAsZip(exportAllAsZipDTO);
} catch (error) {
throw new BadRequestException(error.message);
}
}

Можете пожалуйста подсказать, правильный ли подход? Можно ли его улучшить, если нет, как правильно воплотить такой функионал? Заранее огромное спасибо!

1 ответов

17 просмотров

Что конкретно ты хочешь улучшить? Если оно работает и не вызывает проблем, то я бы не трогал

Похожие вопросы

Обсуждают сегодня

Friends, how can I find my Wazirx wallet address?
Silm Silm
31
My 7 year old daughter recognizes the Bitcoin symbol and knows it's currency. What are the top ,3-5 most basic important concepts to convey to a kid about BCH? I started with ...
Big Hair
24
How the price of ANVL is decided? The buying pressure comes just from staking which is very slow, while the selling pressure might be huge. What are the benefits for those who...
MJ Javvaji @muralijavvaji
13
How many Cashfusion server now?
Crypto life
22
But I'm wondering how exactly we can increase our chances of winning. Do you think it's just a matter of luck, or are there specific actions we need to take to qualify?
Luqman Ayman
12
The main vulnerable points of #Monero There is an axiom in computer security that says that a system is as safe as its most vulnerable point. Monero is a #privacy blockchain ...
LiberLion
15
About MEXC If anyone uses it, tell me please Is there a chance (how high) of forced KYC or assets freeze if I deposit XMR to swap and withdraw to stablecoins?
:)
9
Anyone aware of any active or past frauds going in in the BCH ecosystem?
CRYPTOwhistleblowers
14
When will the snapshot of AGIX be taken for the pending airdrops (RJV, CGV, HYPC, SOPH, TWIN)? I assume it will be before ASI, right? In that case, is it better to leave them ...
Javi B.
23
Pelé, how can I send you screenshots of the airdrop scam? It's a Telegram page just like this one. It says official and sends you to a page where it gives you the addresses wh...
Piketi
8
Карта сайта