Skip to content

Commit db7ff1f

Browse files
committed
fix: standardized export file names across all export format
1 parent b2d440b commit db7ff1f

5 files changed

Lines changed: 20 additions & 7 deletions

File tree

packages/studio-web/src/app/shared/download/download.service.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ Please host all assets on your server, include the font and package imports defi
250250
}
251251

252252
createRASBasename(title: string) {
253-
const timestamp = new Date()
254-
.toISOString()
253+
const timestamp = dateToLocalISO(new Date())
255254
.replace(/[^0-9]/g, "")
256255
.slice(0, -3);
257256
return (title ? slugify(title, 15) : "readalong") + `-${timestamp}`;
@@ -439,6 +438,8 @@ Use the text editor to paste the snippet below in your WordPress page:
439438
);
440439
this.registerDownloadEvent(selectedOutputFormat, from);
441440
} else {
441+
const basename = this.createRASBasename(slots.title);
442+
442443
let audio: HTMLAudioElement = new Audio(b64Audio);
443444
// - update .readalong file translation
444445
await this.updateTranslations(rasXML, readalong);
@@ -453,7 +454,7 @@ Use the text editor to paste the snippet below in your WordPress page:
453454
)
454455
.pipe(takeUntil(this.unsubscribe$))
455456
.subscribe({
456-
next: (x: Blob) => saveAs(x, `readalong.${selectedOutputFormat}`),
457+
next: (x: Blob) => saveAs(x, `${basename}.${selectedOutputFormat}`),
457458
error: (err: HttpErrorResponse) => this.reportRasError(err),
458459
});
459460

@@ -528,3 +529,15 @@ Use the text editor to paste the snippet below in your WordPress page:
528529
return output.join("");
529530
}
530531
}
532+
533+
// Converts the date to an ISO string set to the user's local timezone.
534+
//
535+
// Date.toISOString() returns a string with the time set to UTC. This code is
536+
// extracted from the following stack overflow question:
537+
// https://stackoverflow.com/questions/12413243/javascript-date-format-like-iso-but-local
538+
function dateToLocalISO(date: Date) {
539+
const offsetMs = date.getTimezoneOffset() * 60 * 1000;
540+
const localInMs = date.getTime() - offsetMs;
541+
const dateLocal = new Date(localInMs);
542+
return dateLocal.toISOString();
543+
}

packages/studio-web/tests/studio-web/download-elan.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ test("should Download ELAN ( file format)", async ({ page, browserName }) => {
1313
await expect(
1414
download2.suggestedFilename(),
1515
"should have the expected filename",
16-
).toMatch(/readalong\.eaf/);
16+
).toMatch(/sentence\-paragr\-[0-9]*\.eaf/);
1717
});

packages/studio-web/tests/studio-web/download-praat.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test("should Download Praat ( file format)", async ({ page, browserName }) => {
1919
await expect(
2020
download2.suggestedFilename(),
2121
"should have the expected filename",
22-
).toMatch(/readalong\.textgrid/);
22+
).toMatch(/sentence\-paragr\-[0-9]*\.textgrid/);
2323
/* check output*/
2424
const filePath = await download2.path();
2525
const fileData = fs.readFileSync(filePath, { encoding: "utf8", flag: "r" });

packages/studio-web/tests/studio-web/download-srt.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test("should Download SRT ( file format)", async ({ page, browserName }) => {
1919
await expect(
2020
download2.suggestedFilename(),
2121
"should have the expected filename",
22-
).toMatch(/readalong\.srt/);
22+
).toMatch(/sentence\-paragr\-[0-9]*\.srt/);
2323

2424
const filePath = await download2.path();
2525
const fileData = fs.readFileSync(filePath, { encoding: "utf8", flag: "r" });

packages/studio-web/tests/studio-web/download-webvtt.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test("should Download WebVTT ( file format)", async ({ page, browserName }) => {
2121
await expect(
2222
download2.suggestedFilename(),
2323
"should have the expected filename",
24-
).toMatch(/readalong\.vtt/);
24+
).toMatch(/sentence\-paragr\-[0-9]*\.vtt/);
2525
// check output
2626
const filePath = await download2.path();
2727
const fileData = fs.readFileSync(filePath, { encoding: "utf8", flag: "r" });

0 commit comments

Comments
 (0)