Skip to content

Commit 7aa679c

Browse files
author
Manuel.PirkerIhl
committed
Updated documentation
Add flag for postBackWait (true/false)
1 parent 15b9afc commit 7aa679c

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,36 @@ The port is required if you want to start the application on a differnt port.
8989
{
9090
"url": "http://orf.at",
9191
"filename": "my-wished-filename",
92+
"postBackWait": true,
9293
"postBackUrl": "http://where-should-it-be-posted",
93-
"postBackBody": "{}", // String cause form data does not accept json
94-
"token": "CUSTOM AUTH-TOKEN" // Provide a valid authentication key if you do not want to use the JWT Authentication
94+
"postBackBody": "{}",
95+
"token": "CUSTOM AUTH-TOKEN"
9596
}
9697
```
9798

99+
#### url
100+
101+
Provide the url of the page you want to be tranformed to a pdf document.
102+
103+
#### filename
104+
105+
If you do not provide a filename (without the extension) a uuid will be used as filename. Please choose a unique string otherwise you potentially overwrite documents (name conflicts).
106+
107+
#### postBackUrl
108+
109+
If you provide a postBackUrl the api will try to post the document to the given url.
110+
111+
#### postBackBody
112+
113+
Provide a string of data you wanna send back to the url. Please be aware that only string (NOT json) is supported.
114+
115+
#### postBackWait
116+
Default: true
117+
118+
Provide a boolean value if you want to wait for the complete answer of the postBackProcess.
119+
120+
If set to false the return value "uploaded" will always be false.
121+
98122
### [GET] /api/browse/:id
99123

100124
This endpoint will return the file. Please be aware that there will be a query string required query string param *signed*.

src/browser/browser.controller.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,37 @@ export class BrowserController {
4646
let result = await this.browserService.savePage(createSession.url, createSession.filename);
4747
let resultUpload = false;
4848

49+
createSession.postBackWait = createSession.postBackWait == true;
50+
4951
if (createSession.postBackUrl) {
5052

51-
resultUpload = await this.browserService.uploadFile(request, result.id, createSession);
53+
if (createSession.postBackWait != false) {
54+
55+
resultUpload = await this.browserService.uploadFile(request, result.id, createSession);
56+
57+
// Delete the file after uploading to the endpoint
58+
if (resultUpload) {
59+
await this.browserService.deleteFile(result.storagePath);
60+
}
61+
62+
}
63+
else {
64+
65+
this.browserService.uploadFile(request, result.id, createSession).then(() => {
66+
this.browserService.deleteFile(result.storagePath)
67+
});
5268

53-
// Delete the file after uploading to the endpoint
54-
if (resultUpload) {
55-
await this.browserService.deleteFile(result.storagePath);
5669
}
5770

5871
}
5972

60-
console.error(result);
61-
6273
res.status(HttpStatus.OK).json(new PdfResult({
6374
statusCode: HttpStatus.OK,
6475
requestUrl: createSession.url,
6576
downloadUrl: resultUpload == false ? this.signature.sign(`http://${request.headers.host}/api/browse/${result.id}`) : null,
6677
filename: result.id,
67-
uploaded: resultUpload
78+
uploaded: resultUpload,
79+
waited: createSession.postBackWait
6880
}));
6981

7082
}

src/dto/create-browser.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export class CreateBrowserDto {
66
url: String;
77

88
filename: String;
9+
postBackWait: boolean = true;
910
postBackUrl: String;
1011
postBackBody: Object;
1112
token: String;

0 commit comments

Comments
 (0)