Changeset 35400 for main


Ignore:
Timestamp:
2021-09-15T11:42:33+12:00 (3 years ago)
Author:
cstephen
Message:

Add JSON download option for transcriptions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItem.vue

    r35399 r35400  
    119119        },
    120120        downloadAsText() {
    121             const extensionIndex = this.transcription.fileName.lastIndexOf(".");
    122             let fileName = this.transcription.fileName.slice(0, extensionIndex);
    123             fileName += "_transcription.txt";
     121            const fileName = buildDownloadableFileName(this.transcription.fileName, "txt");
    124122
    125123            const blob = new Blob([ this.transcription.transcription ], { type: "text/plain;charset=utf-8" });
     124            saveAs(blob, fileName);
     125        },
     126        downloadAsJson() {
     127            const fileName = buildDownloadableFileName(this.transcription.fileName, "json");
     128            const toDownload = (({ fileName, transcription, metadata }) => ({ fileName, transcription, metadata }))(this.transcription);
     129
     130            const blob = new Blob([ JSON.stringify(toDownload, null, 4) ], { type: "application/json;charset=utf-8" });
    126131            saveAs(blob, fileName);
    127132        }
    128133    }
    129134}
     135
     136/**
     137 * Builds a file name for a download.
     138 * @param {String} transcriptionFileName The name of the transcription that will be downloaded.
     139 * @param {String} extension The file extension of the download. Do not include a period.
     140 * @returns {String} The file name.
     141 */
     142function buildDownloadableFileName(transcriptionFileName, extension) {
     143    const extensionIndex = transcriptionFileName.lastIndexOf(".");
     144    let fileName = transcriptionFileName.slice(0, extensionIndex);
     145    fileName += "_transcription." + extension;
     146
     147    return fileName;
     148}
    130149</script>
Note: See TracChangeset for help on using the changeset viewer.