Skip to content

Commit

Permalink
Add option to export comments and fix "Invalid input" error (#12)
Browse files Browse the repository at this point in the history
* add option to export comments

* change state loop from 800 to 8000

this helps when performing a large export that takes more time
  • Loading branch information
orellazri committed Dec 23, 2023
1 parent 25265a3 commit 3593326
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Create a `.env` file with the following properties ([How do I find all these val
NOTION_EXPORT_TYPE=markdown
# Create folders for nested pages? Options: true, false (default is false)
NOTION_FLATTEN_EXPORT_FILETREE=false
# Should export comments? Options: true, false (default is true)
NOTION_EXPORT_COMMENTS=true

# Google Drive (Optional)
GOOGLE_DRIVE_ROOT_FOLDER_ID=
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/greydev/notionbackup/NotionClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public class NotionClient {
private static final String KEY_NOTION_TOKEN_V2 = "NOTION_TOKEN_V2";
private static final String KEY_NOTION_EXPORT_TYPE = "NOTION_EXPORT_TYPE";
private static final String KEY_NOTION_FLATTEN_EXPORT_FILETREE = "NOTION_FLATTEN_EXPORT_FILETREE";
private static final String KEY_NOTION_EXPORT_COMMENTS = "NOTION_EXPORT_COMMENTS";
private static final String DEFAULT_NOTION_EXPORT_TYPE = "markdown";
private static final boolean DEFAULT_NOTION_FLATTEN_EXPORT_FILETREE = false;
private static final boolean DEFAULT_NOTION_EXPORT_COMMENTS = true;
private static final String DEFAULT_DOWNLOADS_PATH = "/downloads";

private final String notionSpaceId;
private final String notionTokenV2;
private final String exportType;
private final boolean flattenExportFiletree;
private final boolean exportComments;
private String downloadsDirectoryPath;

private final HttpClient newClient;
Expand Down Expand Up @@ -75,11 +78,15 @@ public class NotionClient {
flattenExportFiletree = StringUtils.isNotBlank(dotenv.get(KEY_NOTION_FLATTEN_EXPORT_FILETREE)) ?
Boolean.parseBoolean(dotenv.get(KEY_NOTION_FLATTEN_EXPORT_FILETREE)) :
DEFAULT_NOTION_FLATTEN_EXPORT_FILETREE;
exportComments = StringUtils.isNotBlank(dotenv.get(KEY_NOTION_EXPORT_COMMENTS)) ?
Boolean.parseBoolean(dotenv.get(KEY_NOTION_EXPORT_COMMENTS)) :
DEFAULT_NOTION_EXPORT_COMMENTS;

exitIfRequiredEnvVariablesNotValid();

log.info("Using export type: {}", exportType);
log.info("Flatten export file tree: {}", flattenExportFiletree);
log.info("Export comments: {}", exportComments);
}


Expand Down Expand Up @@ -194,7 +201,7 @@ private Optional<String> getDownloadLink(String taskId) throws IOException, Inte
.POST(HttpRequest.BodyPublishers.ofString(postBody))
.build();

for (int i = 0; i < 800; i++) {
for (int i = 0; i < 8000; i++) {
HttpResponse<String> response = newClient.send(request, HttpResponse.BodyHandlers.ofString());

// TODO Need to prepare Jackson Document and see how this is handled. I don't wan't this wrapper "Results" class
Expand Down Expand Up @@ -237,6 +244,7 @@ private String getTaskJson() {
" \"eventName\": \"exportSpace\"," +
" \"request\": {" +
" \"spaceId\": \"%s\"," +
" \"shouldExportComments\": %s," +
" \"exportOptions\": {" +
" \"exportType\": \"%s\"," +
" \"flattenExportFiletree\": %s," +
Expand All @@ -246,7 +254,7 @@ private String getTaskJson() {
" }" +
" }" +
"}";
return String.format(taskJsonTemplate, notionSpaceId, exportType.toLowerCase(), flattenExportFiletree);
return String.format(taskJsonTemplate, notionSpaceId, exportComments, exportType.toLowerCase(), flattenExportFiletree);
}


Expand Down

0 comments on commit 3593326

Please sign in to comment.