Skip to content

Commit

Permalink
Fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marode-cap committed Aug 31, 2023
1 parent 46e7055 commit 22cfe6e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export class ContentFileUrlParams {
@ApiProperty()
@IsString()
@IsNotEmpty()
file!: string;
filename!: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ export class H5PEditorModelResponse {
@ApiProperty()
integration: IIntegration;

// This is a list of URLs that point to the Javascript files the H5P editor needs to load
@ApiProperty()
scripts: string[];

// This is a list of URLs that point to the CSS files the H5P editor needs to load
@ApiProperty()
styles: string[];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class H5PEditorController {
return content;
}

@Get('content/:id/:file(*)')
@Get('content/:id/:filename(*)')
async getContentFile(
@Param() params: ContentFileUrlParams,
@Req() req: Request,
Expand All @@ -88,23 +88,12 @@ export class H5PEditorController {
) {
const { data, contentType, contentLength, contentRange } = await this.h5pEditorUc.getContentFile(
params.id,
params.file,
params.filename,
req,
currentUser
);

if (contentRange) {
const contentRangeHeader = `bytes ${contentRange.start}-${contentRange.end}/${contentLength}`;

res.set({
'Accept-Ranges': 'bytes',
'Content-Range': contentRangeHeader,
});

res.status(HttpStatus.PARTIAL_CONTENT);
} else {
res.status(HttpStatus.OK);
}
H5PEditorController.setRangeResponseHeaders(res, contentLength, contentRange);

req.on('close', () => data.destroy());

Expand All @@ -124,18 +113,7 @@ export class H5PEditorController {
currentUser
);

if (contentRange) {
const contentRangeHeader = `bytes ${contentRange.start}-${contentRange.end}/${contentLength}`;

res.set({
'Accept-Ranges': 'bytes',
'Content-Range': contentRangeHeader,
});

res.status(HttpStatus.PARTIAL_CONTENT);
} else {
res.status(HttpStatus.OK);
}
H5PEditorController.setRangeResponseHeaders(res, contentLength, contentRange);

req.on('close', () => data.destroy());

Expand Down Expand Up @@ -224,4 +202,19 @@ export class H5PEditorController {
const saveResponse = new H5PSaveResponse(response.id, response.metadata);
return saveResponse;
}

private static setRangeResponseHeaders(res: Response, contentLength: number, range?: { start: number; end: number }) {
if (range) {
const contentRangeHeader = `bytes ${range.start}-${range.end}/${contentLength}`;

res.set({
'Accept-Ranges': 'bytes',
'Content-Range': contentRangeHeader,
});

res.status(HttpStatus.PARTIAL_CONTENT);
} else {
res.status(HttpStatus.OK);
}
}
}

0 comments on commit 22cfe6e

Please sign in to comment.