mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-13 20:36:35 +00:00
Explicitly set file name for camera snapshot (#23124)
* Explicitly set file name for camera snapshot * Process code review
This commit is contained in:
parent
257cab1061
commit
6c9cfed49f
@ -8,6 +8,7 @@ import "../../../components/buttons/ha-progress-button";
|
||||
import { UNAVAILABLE } from "../../../data/entity";
|
||||
import { fileDownload } from "../../../util/file_download";
|
||||
import { showToast } from "../../../util/toast";
|
||||
import { slugify } from "../../../common/string/slugify";
|
||||
|
||||
class MoreInfoCamera extends LitElement {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
@ -69,9 +70,14 @@ class MoreInfoCamera extends LitElement {
|
||||
throw new Error("No response from API");
|
||||
}
|
||||
|
||||
const contentType = result.headers.get("content-type");
|
||||
const ext = contentType === "image/png" ? "png" : "jpg";
|
||||
const date = new Date().toLocaleString();
|
||||
const filename = `snapshot_${slugify(this.stateObj!.entity_id)}_${date}.${ext}`;
|
||||
|
||||
const blob = await result.blob();
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
fileDownload(url);
|
||||
fileDownload(url, filename);
|
||||
} catch (err) {
|
||||
this._waiting = false;
|
||||
button.actionError();
|
||||
|
Loading…
x
Reference in New Issue
Block a user