198 files
This commit is contained in:
+13
-11
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import { LitElement, html, css, nothing } from "lit";
|
||||
import { isSafeHttpUrl } from "../helpers/url";
|
||||
import { isSafeLink } from "../helpers/url";
|
||||
import { property, state } from "lit/decorators.js";
|
||||
import { t, ensureLocale, langOf } from "../styles";
|
||||
import { runWs } from "../helpers/ws-run";
|
||||
@@ -230,17 +230,18 @@ export class MaintenanceDocumentsSection extends LitElement {
|
||||
this._hint = "";
|
||||
let deduped = 0;
|
||||
let dupInObject = 0;
|
||||
const refused: string[] = [];
|
||||
try {
|
||||
// Bulk upload: one refused file (too large, rejected) is noted and
|
||||
// the rest still go up — unlike the photo dialogs, which stop.
|
||||
// Bulk upload: one refused file (too large, rejected, the connection
|
||||
// dropped) is noted by name and the rest still go up — unlike the
|
||||
// photo dialogs, which stop.
|
||||
for (const file of files) {
|
||||
let doc;
|
||||
try {
|
||||
doc = await uploadDocument(this.hass, entryId, file, [cat]);
|
||||
} catch (e) {
|
||||
const key = e instanceof Error ? e.message : "";
|
||||
if (key !== "doc_too_large" && key !== "doc_upload_failed") throw e;
|
||||
this._error = t(key, this._lang);
|
||||
const key = e instanceof Error && e.message === "doc_too_large" ? "doc_too_large" : "doc_upload_failed";
|
||||
refused.push(`${file.name}: ${t(key, this._lang)}`);
|
||||
continue;
|
||||
}
|
||||
if (doc.duplicate_in_object) dupInObject++;
|
||||
@@ -250,9 +251,10 @@ export class MaintenanceDocumentsSection extends LitElement {
|
||||
if (dupInObject) this._hint = t("doc_dup_in_object", this._lang);
|
||||
else if (deduped) this._hint = t("doc_deduped", this._lang);
|
||||
await this._load();
|
||||
} catch {
|
||||
this._error = t("doc_upload_failed", this._lang);
|
||||
} finally {
|
||||
// Said AFTER the reload: _load() clears the error line, so a refusal
|
||||
// set before it flashed for a moment and was gone (#209).
|
||||
if (refused.length && entryId === this.entryId) this._error = refused.join(" · ");
|
||||
this._busy = false;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +279,7 @@ export class MaintenanceDocumentsSection extends LitElement {
|
||||
if (doc.kind === "file") void this._preview(doc);
|
||||
// Only open http(s) links — never a javascript:/data: URL (the same scheme
|
||||
// guard the rest of the panel applies before opening user-supplied URLs).
|
||||
else if (isSafeHttpUrl(doc.url)) window.open(doc.url, "_blank", "noopener");
|
||||
else if (isSafeLink(doc.url)) window.open(doc.url, "_blank", "noopener");
|
||||
}
|
||||
|
||||
private _startEdit(doc: MaintenanceDocument): void {
|
||||
@@ -340,7 +342,7 @@ export class MaintenanceDocumentsSection extends LitElement {
|
||||
this._linkDescription = "";
|
||||
this._addingLink = false;
|
||||
},
|
||||
"doc_link_invalid",
|
||||
"doc_link_not_allowed",
|
||||
);
|
||||
}
|
||||
|
||||
@@ -521,7 +523,7 @@ export class MaintenanceDocumentsSection extends LitElement {
|
||||
</button>`
|
||||
: html`<a
|
||||
class="icon-btn"
|
||||
href=${isSafeHttpUrl(doc.url) ? doc.url : "#"}
|
||||
href=${isSafeLink(doc.url) ? doc.url : "#"}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title=${t("doc_open", L)}
|
||||
|
||||
Reference in New Issue
Block a user