From 55c48a5bd48c21bc8ca9f26b2e8497a343227842 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Sat, 5 Mar 2022 02:10:10 +0530 Subject: [PATCH 01/12] conversation export named after room --- src/utils/exportUtils/Exporter.ts | 2 +- src/utils/exportUtils/JSONExport.ts | 2 +- src/utils/exportUtils/PlainTextExport.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 7b4a7bf342f..cbcf8d197a4 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -77,7 +77,7 @@ export default abstract class Exporter { protected async downloadZIP(): Promise { const brand = SdkConfig.get().brand; - const filenameWithoutExt = `${brand} - Chat Export - ${formatFullDateNoDay(new Date())}`; + const filenameWithoutExt = `${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`; const filename = `${filenameWithoutExt}.zip`; const { default: JSZip } = await import('jszip'); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index 27fdb5a8478..61da728091c 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -108,7 +108,7 @@ export default class JSONExporter extends Exporter { this.addFile("export.json", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `matrix-export-${formatFullDateNoDay(new Date())}.json`; + const fileName = `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`; this.downloadPlainText(fileName, text); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index edabb80fe02..aa7a65f2c83 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -136,7 +136,7 @@ export default class PlainTextExporter extends Exporter { this.addFile("export.txt", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `matrix-export-${formatFullDateNoDay(new Date())}.txt`; + const fileName = `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`; this.downloadPlainText(fileName, text); } From 04d7e625db1986f9c8d472291bba627b5833080e Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Wed, 9 Mar 2022 01:46:06 +0530 Subject: [PATCH 02/12] sanitization added for exported file name --- src/utils/exportUtils/Exporter.ts | 8 +++++++- src/utils/exportUtils/JSONExport.ts | 8 +++++++- src/utils/exportUtils/PlainTextExport.ts | 9 ++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index cbcf8d197a4..44f21f2af41 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -75,9 +75,15 @@ export default abstract class Exporter { this.files.push(file); } + public santizeFileName(filename:string): string { + filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""); + filename = filename.replace(/[ ]/gim,"-"); + return filename.trim(); + } + protected async downloadZIP(): Promise { const brand = SdkConfig.get().brand; - const filenameWithoutExt = `${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`; + const filenameWithoutExt = this.santizeFileName(`${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`); const filename = `${filenameWithoutExt}.zip`; const { default: JSZip } = await import('jszip'); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index 61da728091c..22e13a3fa9a 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -91,6 +91,12 @@ export default class JSONExporter extends Exporter { return this.createJSONString(); } + public santizeFileName(filename:string): string { + filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""); + filename = filename.replace(/[ ]/gim,"-"); + return filename.trim(); + } + public async export() { logger.info("Starting export process..."); logger.info("Fetching events..."); @@ -108,7 +114,7 @@ export default class JSONExporter extends Exporter { this.addFile("export.json", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`; + const fileName = this.santizeFileName(`matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`); this.downloadPlainText(fileName, text); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index aa7a65f2c83..f3382eb0133 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -24,6 +24,7 @@ import { _t } from "../../languageHandler"; import { haveTileForEvent } from "../../components/views/rooms/EventTile"; import { ExportType, IExportOptions } from "./exportUtils"; import { textForEvent } from "../../TextForEvent"; +import { string } from "prop-types"; export default class PlainTextExporter extends Exporter { protected totalSize: number; @@ -119,6 +120,12 @@ export default class PlainTextExporter extends Exporter { return content; } + public santizeFileName(filename:string): string { + filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""); + filename = filename.replace(/[ ]/gim,"-"); + return filename.trim(); + } + public async export() { this.updateProgress(_t("Starting export process...")); this.updateProgress(_t("Fetching events...")); @@ -136,7 +143,7 @@ export default class PlainTextExporter extends Exporter { this.addFile("export.txt", new Blob([text])); await this.downloadZIP(); } else { - const fileName = `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`; + const fileName = this.santizeFileName(`matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`); this.downloadPlainText(fileName, text); } From 65bdb674439c4f9e2b487d5c1bc0613238d9bdc3 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Wed, 9 Mar 2022 02:07:53 +0530 Subject: [PATCH 03/12] sanitization added for exported file name --- src/utils/exportUtils/Exporter.ts | 6 +++--- src/utils/exportUtils/JSONExport.ts | 6 +++--- src/utils/exportUtils/PlainTextExport.ts | 7 +++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 44f21f2af41..d00aa7bf737 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -75,9 +75,9 @@ export default abstract class Exporter { this.files.push(file); } - public santizeFileName(filename:string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""); - filename = filename.replace(/[ ]/gim,"-"); + public santizeFileName(filename: string): string { + filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, ""); + filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index 22e13a3fa9a..6adcda4b760 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -91,9 +91,9 @@ export default class JSONExporter extends Exporter { return this.createJSONString(); } - public santizeFileName(filename:string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""); - filename = filename.replace(/[ ]/gim,"-"); + public santizeFileName(filename: string): string { + filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, ""); + filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index f3382eb0133..1f85124fc95 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -24,7 +24,6 @@ import { _t } from "../../languageHandler"; import { haveTileForEvent } from "../../components/views/rooms/EventTile"; import { ExportType, IExportOptions } from "./exportUtils"; import { textForEvent } from "../../TextForEvent"; -import { string } from "prop-types"; export default class PlainTextExporter extends Exporter { protected totalSize: number; @@ -120,9 +119,9 @@ export default class PlainTextExporter extends Exporter { return content; } - public santizeFileName(filename:string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim,""); - filename = filename.replace(/[ ]/gim,"-"); + public santizeFileName(filename: string): string { + filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, ""); + filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } From cb4a957379895c6a05f32b97e4cabe9062be85fe Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Wed, 9 Mar 2022 02:15:14 +0530 Subject: [PATCH 04/12] sanitization added for exported file name --- src/utils/exportUtils/Exporter.ts | 2 +- src/utils/exportUtils/JSONExport.ts | 2 +- src/utils/exportUtils/PlainTextExport.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index d00aa7bf737..a00adec7beb 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -76,7 +76,7 @@ export default abstract class Exporter { } public santizeFileName(filename: string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, ""); + filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index 6adcda4b760..b2da67a546b 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -92,7 +92,7 @@ export default class JSONExporter extends Exporter { } public santizeFileName(filename: string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, ""); + filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim,""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index 1f85124fc95..a82330b1817 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -120,7 +120,7 @@ export default class PlainTextExporter extends Exporter { } public santizeFileName(filename: string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü \.,_-]/gim, ""); + filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } From 439c4cac364c4c6fe2b660dacb55afaaed97971d Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Wed, 9 Mar 2022 02:20:31 +0530 Subject: [PATCH 05/12] sanitization added for exported file name=>lint error fixed --- src/utils/exportUtils/JSONExport.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index b2da67a546b..01df4fe5b9c 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -92,7 +92,7 @@ export default class JSONExporter extends Exporter { } public santizeFileName(filename: string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim,""); + filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); } From 9958015f82291b80cd6a15118df37310c81cc554 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Wed, 9 Mar 2022 18:29:01 +0530 Subject: [PATCH 06/12] sanitization added for exported file name=>lint error fixed --- src/utils/exportUtils/Exporter.ts | 4 +++- src/utils/exportUtils/JSONExport.ts | 4 +++- src/utils/exportUtils/PlainTextExport.ts | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index a00adec7beb..d8439f37641 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -83,7 +83,9 @@ export default abstract class Exporter { protected async downloadZIP(): Promise { const brand = SdkConfig.get().brand; - const filenameWithoutExt = this.santizeFileName(`${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`); + const filenameWithoutExt = this.santizeFileName( + `${brand} - ${this.room.name} - Chat Export - ${formatFullDateNoDay(new Date())}`, + ); const filename = `${filenameWithoutExt}.zip`; const { default: JSZip } = await import('jszip'); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index 01df4fe5b9c..c7e82655408 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -114,7 +114,9 @@ export default class JSONExporter extends Exporter { this.addFile("export.json", new Blob([text])); await this.downloadZIP(); } else { - const fileName = this.santizeFileName(`matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`); + const fileName = this.santizeFileName( + `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.json`, + ); this.downloadPlainText(fileName, text); } diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index a82330b1817..9c7b1145bac 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -142,7 +142,9 @@ export default class PlainTextExporter extends Exporter { this.addFile("export.txt", new Blob([text])); await this.downloadZIP(); } else { - const fileName = this.santizeFileName(`matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`); + const fileName = this.santizeFileName( + `matrix-${this.room.name}-export-${formatFullDateNoDay(new Date())}.txt`, + ); this.downloadPlainText(fileName, text); } From f2ceb5d827f04221253e75c72d40a4f9b4749479 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Wed, 9 Mar 2022 19:22:53 +0530 Subject: [PATCH 07/12] sanitization added for exported file name=>redundancy removed --- src/utils/exportUtils/Exporter.ts | 2 +- src/utils/exportUtils/JSONExport.ts | 6 ------ src/utils/exportUtils/PlainTextExport.ts | 6 ------ 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index d8439f37641..0ee59480dfb 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -75,7 +75,7 @@ export default abstract class Exporter { this.files.push(file); } - public santizeFileName(filename: string): string { + protected santizeFileName(filename: string): string { filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); diff --git a/src/utils/exportUtils/JSONExport.ts b/src/utils/exportUtils/JSONExport.ts index c7e82655408..7ba72f26e2a 100644 --- a/src/utils/exportUtils/JSONExport.ts +++ b/src/utils/exportUtils/JSONExport.ts @@ -91,12 +91,6 @@ export default class JSONExporter extends Exporter { return this.createJSONString(); } - public santizeFileName(filename: string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); - filename = filename.replace(/[ ]/gim, "-"); - return filename.trim(); - } - public async export() { logger.info("Starting export process..."); logger.info("Fetching events..."); diff --git a/src/utils/exportUtils/PlainTextExport.ts b/src/utils/exportUtils/PlainTextExport.ts index 9c7b1145bac..4c841d9f8fc 100644 --- a/src/utils/exportUtils/PlainTextExport.ts +++ b/src/utils/exportUtils/PlainTextExport.ts @@ -119,12 +119,6 @@ export default class PlainTextExporter extends Exporter { return content; } - public santizeFileName(filename: string): string { - filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); - filename = filename.replace(/[ ]/gim, "-"); - return filename.trim(); - } - public async export() { this.updateProgress(_t("Starting export process...")); this.updateProgress(_t("Fetching events...")); From e75b3065c3434ae8b7170dc976f518aee1292932 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Sat, 12 Mar 2022 15:06:29 +0530 Subject: [PATCH 08/12] sanitization added for exported file name=>redundancy removed --- src/utils/exportUtils/Exporter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 0ee59480dfb..ff03e2addd2 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -76,6 +76,7 @@ export default abstract class Exporter { } protected santizeFileName(filename: string): string { + filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); From 572cf47b898ca88cbbfe6ec6ca26cda0ae4d233f Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Sat, 12 Mar 2022 15:21:56 +0530 Subject: [PATCH 09/12] reverted to previous commit --- src/utils/exportUtils/Exporter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index ff03e2addd2..0ee59480dfb 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -76,7 +76,6 @@ export default abstract class Exporter { } protected santizeFileName(filename: string): string { - filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); From b0dac2f18a5c150ec358a610cbcb053b3daa9476 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Tue, 15 Mar 2022 09:58:51 +0530 Subject: [PATCH 10/12] sanitization added for exported file name=>redundancy removed --- src/utils/exportUtils/Exporter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index 0ee59480dfb..ff03e2addd2 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -76,6 +76,7 @@ export default abstract class Exporter { } protected santizeFileName(filename: string): string { + filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); return filename.trim(); From f086670d9d415104ca2c1051a30d9aec65a53789 Mon Sep 17 00:00:00 2001 From: Sinharitik589 Date: Mon, 16 May 2022 13:35:58 +0530 Subject: [PATCH 11/12] conversation export named after room --- src/utils/exportUtils/Exporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index ff03e2addd2..fd98940238e 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -77,8 +77,8 @@ export default abstract class Exporter { protected santizeFileName(filename: string): string { filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); - filename = filename.replace(/[^a-z0-9áéíóúñü.,_-]/gim, ""); filename = filename.replace(/[ ]/gim, "-"); + filename = filename.replace(/[^a-z0-9.,_-]/gim, ""); return filename.trim(); } From 677e9e7132540d7a571439f7264c08c5dc435c47 Mon Sep 17 00:00:00 2001 From: Sinharitik589 <67551927+Sinharitik589@users.noreply.github.com> Date: Wed, 18 May 2022 23:22:59 +0530 Subject: [PATCH 12/12] conversation export named after room Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/utils/exportUtils/Exporter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/exportUtils/Exporter.ts b/src/utils/exportUtils/Exporter.ts index fd98940238e..25d685f9101 100644 --- a/src/utils/exportUtils/Exporter.ts +++ b/src/utils/exportUtils/Exporter.ts @@ -77,7 +77,7 @@ export default abstract class Exporter { protected santizeFileName(filename: string): string { filename = filename.normalize('NFD').replace(/[\u0300-\u036f]/g, ""); - filename = filename.replace(/[ ]/gim, "-"); + filename = filename.replace(/\s+/gim, "-"); filename = filename.replace(/[^a-z0-9.,_-]/gim, ""); return filename.trim(); }