-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from ably/add-link-to-download-crash-report
Add link to download crash report
- Loading branch information
Showing
7 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Controller, Get, Param, Res, Header } from '@nestjs/common'; | ||
import { CrashReportsService } from './crashReports.service'; | ||
import { Response } from 'express'; | ||
|
||
@Controller('repos/:owner/:name/crash_reports') | ||
export class CrashReportsController { | ||
constructor(private readonly crashReportsService: CrashReportsService) {} | ||
|
||
@Get(':id/download') | ||
@Header('Content-Type', 'application/octet-stream') | ||
async download( | ||
@Param('id') id: string, | ||
@Res({ passthrough: true }) res: Response, | ||
): Promise<string> { | ||
const crashReport = await this.crashReportsService.find(id); | ||
|
||
// Only repeat the extension of the original file if it’s one of our expected ones. Not really sure if this is of any use, but I don’t really like the idea of being tricked into giving somebody a malicious .dmg file or something. | ||
const allowedExtensions = ['.crash', '.ips']; | ||
const extensionToUse = allowedExtensions.find((allowedExtension) => | ||
crashReport.filename.endsWith(allowedExtension), | ||
); | ||
|
||
res.header( | ||
'Content-Disposition', | ||
`filename="crash_report_${crashReport.id}${extensionToUse ?? ''}"`, | ||
); | ||
return crashReport.data; | ||
} | ||
} |
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,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { CrashReport } from '../uploads/crashReport.entity'; | ||
import { CrashReportsController } from './crashReports.controller'; | ||
import { CrashReportsService } from './crashReports.service'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([CrashReport])], | ||
controllers: [CrashReportsController], | ||
providers: [CrashReportsService], | ||
}) | ||
export class CrashReportsModule {} |
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,19 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { CrashReport } from '../uploads/crashReport.entity'; | ||
|
||
@Injectable() | ||
export class CrashReportsService { | ||
constructor( | ||
@InjectRepository(CrashReport) | ||
private crashReportsRepository: Repository<CrashReport>, | ||
) {} | ||
|
||
async find(id: string): Promise<CrashReport> { | ||
const results = await this.crashReportsRepository.find({ | ||
where: { id }, | ||
}); | ||
return results[0]; | ||
} | ||
} |
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
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