-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mimic hue dump file download for deconz (#1620)
- Loading branch information
Showing
14 changed files
with
220 additions
and
70 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/modules/custom-plugins/homebridge-deconz/homebridge-deconz.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Controller, UseGuards, Get, Header, StreamableFile } from '@nestjs/common'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger'; | ||
import { AdminGuard } from '../../../core/auth/guards/admin.guard'; | ||
import { HomebridgeDeconzService } from './homebridge-deconz.service'; | ||
|
||
@ApiTags('Plugins') | ||
@ApiBearerAuth() | ||
@UseGuards(AuthGuard()) | ||
@Controller('plugins/custom-plugins/homebridge-deconz') | ||
export class HomebridgeDeconzController { | ||
|
||
constructor( | ||
private homebridgeDeconzService: HomebridgeDeconzService, | ||
) { } | ||
|
||
@UseGuards(AdminGuard) | ||
@Get('/dump-file') | ||
@Header('Content-disposition', 'attachment; filename=homebridge-deconz.json.gz') | ||
@Header('Content-Type', 'application/json+gzip') | ||
async exchangeCredentials(): Promise<StreamableFile> { | ||
return this.homebridgeDeconzService.streamDumpFile(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/modules/custom-plugins/homebridge-deconz/homebridge-deconz.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PassportModule } from '@nestjs/passport'; | ||
import { LoggerModule } from '../../../core/logger/logger.module'; | ||
import { ConfigModule } from '../../../core/config/config.module'; | ||
import { HomebridgeDeconzController } from './homebridge-deconz.controller'; | ||
import { HomebridgeDeconzService } from './homebridge-deconz.service'; | ||
|
||
@Module({ | ||
imports: [ | ||
PassportModule.register({ defaultStrategy: 'jwt' }), | ||
ConfigModule, | ||
LoggerModule, | ||
], | ||
providers: [ | ||
HomebridgeDeconzService, | ||
], | ||
exports: [ | ||
], | ||
controllers: [ | ||
HomebridgeDeconzController, | ||
], | ||
}) | ||
export class HomebridgeDeconzModule { } |
23 changes: 23 additions & 0 deletions
23
src/modules/custom-plugins/homebridge-deconz/homebridge-deconz.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs-extra'; | ||
import { Injectable, NotFoundException, StreamableFile } from '@nestjs/common'; | ||
import { ConfigService } from '../../../core/config/config.service'; | ||
|
||
@Injectable() | ||
export class HomebridgeDeconzService { | ||
constructor( | ||
private configService: ConfigService, | ||
) { } | ||
|
||
async streamDumpFile(): Promise<StreamableFile> { | ||
const dumpPath = path.resolve(this.configService.storagePath, 'homebridge-deconz.json.gz'); | ||
|
||
// check file exists | ||
if (!await fs.pathExists(dumpPath)) { | ||
throw new NotFoundException(); | ||
} | ||
|
||
// stream file to client | ||
return new StreamableFile(fs.createReadStream(dumpPath)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.