-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
99 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { download_by_link } from "./setting"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Create a blob that contains the JSON data. | ||
// The space parameter specifies the indentation of nested objects in the string representation. | ||
export function download_by_link(messages, name) { | ||
const blob = new Blob([JSON.stringify(messages, null, 2)], { | ||
// The type of the blob. | ||
type: "application/json", | ||
}); | ||
|
||
const url = URL.createObjectURL(blob); | ||
|
||
// Create a file name for the JSON file. | ||
const date = new Date(); | ||
const year = date.getFullYear(); | ||
const month = String(date.getMonth() + 1).padStart(2, "0"); // months are 0-based in JavaScript | ||
const day = String(date.getDate()).padStart(2, "0"); | ||
const hour = String(date.getHours()).padStart(2, "0"); | ||
const minute = String(date.getMinutes()).padStart(2, "0"); | ||
const second = String(date.getSeconds()).padStart(2, "0"); | ||
const fileName = `chatall-${name}-${year}${month}${day}-${hour}${minute}${second}`; | ||
|
||
const a = document.createElement("a"); | ||
a.href = url; | ||
a.download = `${fileName}.json`; | ||
document.body.appendChild(a); | ||
|
||
// Click the anchor element to download the file. | ||
a.click(); | ||
|
||
// Remove the anchor element from the document body. | ||
document.body.removeChild(a); | ||
|
||
// Revoke the URL for the blob. | ||
URL.revokeObjectURL(url); | ||
} |